I am trying to do the same thing in Java 11 that could be done with -Xbootclasspath/p:path
in pre java 9.
As a simple example I modified one of the valueOf
methods of java.lang.Integer
and compiled the project with:
javac --module-source-path=src/java.base --patch-module java.base=src/java.base -d mods $(find src -name '*.java')
I then ran a simple sample using:
java --patch-module java.base=<pathToMyModifiedJavaBaseClasses> -p lib -m my.moduleA/my.moduleA.Main
That worked an I'm seeing the modifications displayed (a simple print out I did from valueOf
).
When I try, however, to do the same thing with java.lang.ClassLoader
I get the following error when executing the program (compile works):
Error occurred during initialization of boot layer
java.lang.LinkageError: loader 'bootstrap' attempted duplicate class definition for java.lang.invoke.SimpleMethodHandle.
I do not even need to make changes in java.lang.ClassLoader
. The sheer existence of that class in my patch folder seems to be provocing this error. (I only wanted to add a field though at the bottom of the class)
NOTE: I just figured that it works when the ClassLoader
class is compiled with Eclipse. One of the few differences I know is that the Eclipse compiler does not seem to follow JEP 280 yet. But there are invokedynamic
instructions in the bytecode resulting from javac
as well, so I doubt that this is the problem.