Skip to content

Commit

Permalink
convert remaining getSystemClassLoader().loadClass() to Class.forName()
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinccheung committed Nov 1, 2024
1 parent f3d7212 commit d4aeb92
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
public class OldClassAndRedefineClassApp {

public static void main(String args[]) throws Throwable {
ClassLoader appClassLoader = ClassLoader.getSystemClassLoader();

System.out.println("Main: loading OldSuper");
// Load an old class (version 49), but not linking it.
Class.forName("OldSuper", false, ClassLoader.getSystemClassLoader());
Class.forName("OldSuper", false, appClassLoader);

// Redefine a class unrelated to the above old class.
Instrumentation instrumentation = InstrumentationRegisterClassFileTransformer.getInstrumentation();
System.out.println("INFO: instrumentation = " + instrumentation);
Class<?> c = ClassLoader.getSystemClassLoader().loadClass("Hello");
Class<?> c = Class.forName("Hello", false, appClassLoader);
byte[] bytes = c.getClassLoader().getResourceAsStream(c.getName().replace('.', '/') + ".class").readAllBytes();
instrumentation.redefineClasses(new ClassDefinition(c, bytes));

Expand Down

0 comments on commit d4aeb92

Please sign in to comment.