How to fix OpenJDK 9 with Jigsaw?

Before Jigsaw, it was pretty easy to replace one or more OpenJDK classes (run some kind of test or contribute). I could copy the source file from the OpenJDK source, for example, java/util/ArrayList.java to src/java/util/ , add any changes I want, and then compile in normal mode (output to the mypatch directory):

 $ javac.exe src\java\util\ArrayList.java -d mypatch 

After that, I could start the JVM with -Xbootclasspath/p to replace the original ArrayList with a fixed one:

 $ java -Xbootclasspath/p:mypatch MyTestClass 

However, this does not work anymore, because the Jigsaw integration in Java 9-ea + 111. The compilation command reports a lot of errors, starting as follows:

 src\java\util\ArrayList.java:26: error: package exists in another module: java.base package java.util; ^ src\java\util\ArrayList.java:108: error: cannot find symbol public class ArrayList<E> extends AbstractList<E> ^ symbol: class AbstractList src\java\util\ArrayList.java:109: error: cannot find symbol implements List<E>, RandomAccess, Cloneable, java.io.Serializable ^ 

And even if I compile with the old JDK, the JVM cannot start:

 -Xbootclasspath/p is no longer a supported option. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 

How to make patches for JDK with Jigsaw?

+7
java jvm java-9 javac jigsaw
source share
2 answers

From the javac error message, you may know that the class you are compiling belongs to the java.base module. Now, to compile the JDK class, you must specify the module that it contains with the new argument -Xmodule :

 $ javac --patch-module java.base=src -d mypatch \ src/java.base/java/util/ArrayList.java 

Now, to replace existing classes with new ones, use the --patch-module <module-name> JVM argument:

 $ java --patch-module java-base=mypatch MyTestClass 

Here we must specify a directory that contains subdirectories named as corresponding modules. Now everything works as before. You can specify this several times if you paid several modules:

 $ java --patch-module java-base=mypatch --patch-module java-xml=myxmlpatch MyTestClass 
+8
source share

Here is a new solution that works with the released jdk 9 version.

 javac --patch-module java.base=src -d mypatches/java.base \ src/java.base/java/util/ArrayList.java java --patch-module java.base=mypatches/java.base ... 

Source: Jigsaw Project: Modular System Quick Start Guide

+2
source share

All Articles