github-advanced-security[bot] commented on code in PR #3109:
URL: https://github.com/apache/groovy/pull/3109#discussion_r4426396329


##########
src/main/java/groovy/lang/GroovyClassLoader.java:
##########
@@ -579,7 +589,114 @@
      * @see #clearCache()
      */
     protected void removeClassCacheEntry(final String name) {
-        classCache.remove(name);
+        if (classCache.remove(name) != null) {
+            noteRemovedSimpleName(name);
+        }
+    }
+
+    /**
+     * Beans introspection and inner-class resolution ask for companion names
+     * that are not on any classpath. {@code Class.forName} of a beans 
companion
+     * retries the platform loader when this loader reports
+     * {@link ClassNotFoundException}, so that probe is reported as a different
+     * exception the introspector already ignores. Other known misses stay a
+     * normal {@link ClassNotFoundException}, without consulting the parent.
+     */
+    private void throwIfParentWouldOnlyRecordAMiss(final String name, final 
boolean lookupScriptFiles) throws ClassNotFoundException {
+        if (name == null) {
+            return;
+        }
+        boolean beanCompanion = isBeanCompanionProbe(name);
+        boolean innerName = name.indexOf('$') >= 0;
+        if (!beanCompanion && !innerName) {
+            return;
+        }
+        if (definedByParentGroovyLoader(name) || hasClassResource(name)) {
+            return;
+        }
+        if (lookupScriptFiles) {
+            try {
+                if (resourceLoader.loadGroovySource(name) != null) {
+                    return;
+                }
+            } catch (MalformedURLException ignored) {
+                // Let the normal load path report the bad source URL.
+                return;
+            }
+        }
+        if (beanCompanion) {
+            throw new IntrospectionProbeMiss(name);
+        }
+        throw new ClassNotFoundException(name);
+    }
+
+    private boolean hasClassResource(final String name) {
+        return getResource(name.replace('.', '/') + ".class") != null;

Review Comment:
   ## CodeQL / Uncontrolled data used in path expression
   
   This path depends on a [user-provided value](1).
   
   [Show more 
details](https://github.com/apache/groovy/security/code-scanning/284)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to