Copilot commented on code in PR #8491:
URL: https://github.com/apache/hadoop/pull/8491#discussion_r3221646534


##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AFileSystemIsolatedClassloader.java:
##########
@@ -60,19 +59,25 @@ public AwsCredentials resolveCredentials() {
   }
 
   private static class CustomClassLoader extends ClassLoader {
-  }
+    private final ClassLoader parent;
 
-  private final ClassLoader customClassLoader = spy(new CustomClassLoader());
-  {
-    try {
-      doReturn(CustomCredentialsProvider.class)
-          .when(customClassLoader)
-          .loadClass(customClassName);
-    } catch (ClassNotFoundException ex) {
-      throw new RuntimeException(ex);
+    CustomClassLoader(ClassLoader parent) {
+      super(parent);
+      this.parent = parent;
+    }
+
+    @Override
+    public Class<?> loadClass(String name) throws ClassNotFoundException {
+      if (customClassName.equals(name)) {
+        return CustomCredentialsProvider.class;
+      }
+      return parent.loadClass(name);
     }

Review Comment:
   Overriding `ClassLoader#loadClass(String)` and delegating directly to 
`parent.loadClass(name)` bypasses the standard `ClassLoader` loading flow 
(notably the built-in locking/caching path in `ClassLoader#loadClass(...)`). 
Since you already call `super(parent)`, you can drop the redundant `parent` 
field and delegate the non-special case to `super.loadClass(name)` (or 
`super.loadClass(name, false)` if you choose to override the protected method) 
to preserve standard classloading semantics.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to