In the JDK-8, we could compile our changed java.lang classes and reconstruct the rt.jar. Then we could overwrite java.lang classfiles by augmenting the bootclasspath with -Xbootclasspath:<yourpathto>/rt.jar. Doing this, we could for example make java.lang.Integer be non-final for testing purposes.
In JDK-11, this is different. Patching is done via --patch-modules and I can't get it to work. I have done the following:
- Remove the final modifier and recompiled the java.base module from the openjdk-11 source
- Added the
--patch-module java.base=<path-to-my-compiled-java.base-directory> - It still fails on
error: cannot inherit from final Integer. Possibly we can't overwrite the class declarations of JDK source files anymore? That would be strange. - I've also tried adding these classfiles to a jar and tried to pass all possible root directories to the
--patch-moduleargument - I've tried removing the module
package-info.classfrom the compiledjava.basedirectory and tried explicitly addingjava.base.java.lang.Integerwith--add-opens
The docs aren't really clear on this particular usage.
The entire javac command from maven (I have tried both javac and the maven-compiler-plugin):
javac -d ./target/classes -classpath <classpathfiles> -sourcepath <sourcefiles> -s ./target/generated-sources/annotations -g -nowarn -target 11 -source 11 -encoding UTF-8 --patch-module=java.base=../runtimejar/mods/src/java.base -Xplugin:Manifold
(Shortened path names etc. for readability)
What am I missing here? Why can't I modify java.base/java.lang.Integer like this?
The example from Project Jigsaw models your use-case. Note the use of --patch-module for both javac and java.
Check that your sourcepath aligns with your --patch-module directory i.e., is there a file src/java.base/java/lang/Integar.java and is it in your sourcepath?
Update
Here is a sample project that demonstrates how to shadow java.lang.Integer: https://dl.dropbox.com/s/6swet2k89vukxbm/patch.zip
Compile:
Run: