Copilot commented on code in PR #11431:
URL: https://github.com/apache/gravitino/pull/11431#discussion_r3360159035


##########
catalogs/catalog-common/src/main/java/org/apache/gravitino/utils/ClassLoaderResourceCleanerUtils.java:
##########
@@ -301,6 +345,16 @@ private static void closeResourceInAzure(ClassLoader 
classLoader) throws Excepti
     MethodUtils.invokeStaticMethod(relocatedLogFactory, "release", 
classLoader);
   }
 
+  /**
+   * Returns true if {@code clazz} was loaded directly by {@code classLoader} 
(not delegated to a
+   * parent). Use this before touching static fields that must belong to the 
catalog's own
+   * classloader to avoid accidentally mutating JVM-global shared state.
+   */
+  @VisibleForTesting
+  static boolean isOwnedByClassLoader(Class<?> clazz, ClassLoader classLoader) 
{
+    return clazz.getClassLoader() == classLoader;
+  }

Review Comment:
   `isOwnedByClassLoader` currently returns `true` when both 
`clazz.getClassLoader()` and `classLoader` are `null` (bootstrap loader). That 
makes the guard treat bootstrap-loaded classes as “owned”, which is risky if 
`closeClassLoaderResource(null)` (or any other accidental `null` loader) ever 
happens, because it could allow static-state mutation against 
JVM-global/bootstrap classes rather than skipping cleanup.



-- 
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