Subject: bug#64389: java: stripping timestamps breaks jmods.

From: Ricardo Wurmus <[email-masked]>
Date: Sat, 01 Jul 2023 00:28:48 +0200

The 'strip-archive-timestamps phase in our openjdk packages breaks the
jmod feature because it invalidates the content hashes.

Here I try to extend the JDK with modules from openjfx:

--8<---------------cut here---------------start------------->8---
jlink --add-modules java.desktop,javafx.swing,javafx.controls,jdk.unsupported.desktop --output myjdk --module-path openjfx-17.0.7_linux-x64_bin-jmods/javafx-jmods-17.0.7/
Error: Hash of java.xml (da39a79e291a7cc5b8e240390a4386a7d2323017871d6c2d635301826d0159f9) differs to expected hash (e3ee7150f05504485371ab9bac2d724a553f975eca5d529dca786599cc5f98a3) recorded in java.base
java.lang.module.FindException: Hash of java.xml (da39a79e291a7cc5b8e240390a4386a7d2323017871d6c2d635301826d0159f9) differs to expected hash (e3ee7150f05504485371ab9bac2d724a553f975eca5d529dca786599cc5f98a3) recorded in java.base
	at java.base/java.lang.module.Resolver.findFail(Resolver.java:892)
	at java.base/java.lang.module.Resolver.checkHashes(Resolver.java:480)
	at java.base/java.lang.module.Resolver.finish(Resolver.java:378)
	at java.base/java.lang.module.Configuration.<init>(Configuration.java:139)
	at java.base/java.lang.module.Configuration.resolve(Configuration.java:422)
	at java.base/java.lang.module.Configuration.resolve(Configuration.java:254)
	at jdk.jlink/jdk.tools.jlink.internal.Jlink$JlinkConfiguration.resolve(Jlink.java:217)
	at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.createImageProvider(JlinkTask.java:536)
	at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.createImage(JlinkTask.java:424)
	at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.run(JlinkTask.java:276)
	at jdk.jlink/jdk.tools.jlink.internal.Main.run(Main.java:56)
	at jdk.jlink/jdk.tools.jlink.internal.Main.main(Main.java:34)
--8<---------------cut here---------------end--------------->8---

When I remove the 'strip-archive-timestamps phase and try using jlink
from this variant of the openjdk package things work fine:

--8<---------------cut here---------------start------------->8---
java.base file:///gnu/store/c3hxi9pd9mpj3f6qk4qiysdqvchq8apm-openjdk-19.0.2-jdk/jmods/java.base.jmod
java.datatransfer file:///gnu/store/c3hxi9pd9mpj3f6qk4qiysdqvchq8apm-openjdk-19.0.2-jdk/jmods/java.datatransfer.jmod
java.desktop file:///gnu/store/c3hxi9pd9mpj3f6qk4qiysdqvchq8apm-openjdk-19.0.2-jdk/jmods/java.desktop.jmod
java.prefs file:///gnu/store/c3hxi9pd9mpj3f6qk4qiysdqvchq8apm-openjdk-19.0.2-jdk/jmods/java.prefs.jmod
java.xml file:///gnu/store/c3hxi9pd9mpj3f6qk4qiysdqvchq8apm-openjdk-19.0.2-jdk/jmods/java.xml.jmod
javafx.base file:///home/rekado/Downloads/java/openjfx-17.0.7_linux-x64_bin-jmods/javafx-jmods-17.0.7/javafx.base.jmod
javafx.controls file:///home/rekado/Downloads/java/openjfx-17.0.7_linux-x64_bin-jmods/javafx-jmods-17.0.7/javafx.controls.jmod
javafx.graphics file:///home/rekado/Downloads/java/openjfx-17.0.7_linux-x64_bin-jmods/javafx-jmods-17.0.7/javafx.graphics.jmod
javafx.swing file:///home/rekado/Downloads/java/openjfx-17.0.7_linux-x64_bin-jmods/javafx-jmods-17.0.7/javafx.swing.jmod
jdk.unsupported file:///gnu/store/c3hxi9pd9mpj3f6qk4qiysdqvchq8apm-openjdk-19.0.2-jdk/jmods/jdk.unsupported.jmod
jdk.unsupported.desktop file:///gnu/store/c3hxi9pd9mpj3f6qk4qiysdqvchq8apm-openjdk-19.0.2-jdk/jmods/jdk.unsupported.desktop.jmod

Providers:
  java.desktop provides java.net.ContentHandlerFactory used by java.base
  java.base provides java.nio.file.spi.FileSystemProvider used by java.base
  java.base provides java.util.random.RandomGenerator used by java.base
  java.desktop provides javax.print.PrintServiceLookup used by java.desktop
  java.desktop provides javax.print.StreamPrintServiceFactory used by java.desktop
  java.desktop provides javax.sound.midi.spi.MidiDeviceProvider used by java.desktop
  java.desktop provides javax.sound.midi.spi.MidiFileReader used by java.desktop
  java.desktop provides javax.sound.midi.spi.MidiFileWriter used by java.desktop
  java.desktop provides javax.sound.midi.spi.SoundbankReader used by java.desktop
  java.desktop provides javax.sound.sampled.spi.AudioFileReader used by java.desktop
  java.desktop provides javax.sound.sampled.spi.AudioFileWriter used by java.desktop
  java.desktop provides javax.sound.sampled.spi.FormatConversionProvider used by java.desktop
  java.desktop provides javax.sound.sampled.spi.MixerProvider used by java.desktop
  java.desktop provides sun.datatransfer.DesktopDatatransferService used by java.datatransfer
  jdk.unsupported.desktop provides sun.swing.InteropProvider used by java.desktop
--8<---------------cut here---------------end--------------->8---

We will need to find a way to remove timestamps without leaving invalid
hashes behind.  Can we recompute the file hashes or avoid embedding
timestamps in the first place?

-- 
Ricardo