Attempts to unpack and pack the java.compiler.jmod produces the next exception:
===========================================
Error: More than one ModuleTarget attribute
java.lang.module.InvalidModuleDescriptorException: More than one ModuleTarget attribute
at java.base/jdk.internal.module.ModuleInfo.invalidModuleDescriptor(ModuleInfo.java:1216)
at java.base/jdk.internal.module.ModuleInfo.doRead(ModuleInfo.java:243)
at java.base/jdk.internal.module.ModuleInfo.read(ModuleInfo.java:129)
at jdk.jlink/jdk.tools.jmod.JmodTask.describe(JmodTask.java:318)
at jdk.jlink/jdk.tools.jmod.JmodTask.run(JmodTask.java:207)
at jdk.jlink/jdk.tools.jmod.Main.main(Main.java:35)
===========================================
The bug can be reproduced if jmod tool from JDK21 is used for jmods files from jdk20 or jdk21. The tool from JDK20 works fine with jmods files from jdk20.
Steps to reproduce:
JAVA_HOME=/jdk21/build/windows-x86_64-server-release/images/jdk/
JMOD_BINARY=${JAVA_HOME}/bin/jmod.exe
JMOD_DIR=${JAVA_HOME}/jmods
TEST_JMOD=java.compiler.jmod
mkdir extract
mkdir pack
${JMOD_BINARY} extract ${JMOD_DIR}/${TEST_JMOD} --dir extract/${TEST_JMOD}
cd extract/${TEST_JMOD}
${JMOD_BINARY} create --target-platform -amd64 --module-version 21 --class-path classes --legal-notices legal ../../pack/java.compiler.jmod
cd ../../
${JMOD_BINARY} describe pack/java.compiler.jmod
The last command produced this error.
Tested on windows and linux.
The same exception can occur if the java.base jmod file should be repacked using hash+module-path of repacked java.compiler.jmod.