On Wed, 22 Apr 2026 09:21:20 GMT, David Beaumont <[email protected]> wrote:
>>> There is a lot of complexity in this, which is partly why it has taken me a
>>> long time to go through all these changes. This is why I'm wondering about
>>> making this simpler so that there are only 2 views.
>>
>> I for one, would welcome only two views. For my taste there are some strange
>> inconsistencies (I'm using valhalla EA JDK for this):
>>
>> $ ./bin/jshell
>> | Welcome to JShell -- Version 27-jep401ea3
>> | For an introduction type: /help intro
>>
>> jshell> var mref = ModuleFinder.ofSystem().find("java.base").orElseThrow();
>> mref ==> [module java.base, location=jrt:/java.base]
>>
>> jshell> var bytePreviewResource = "META-INF/preview/java/lang/Byte.class";
>> bytePreviewResource ==> "META-INF/preview/java/lang/Byte.class"
>>
>> jshell> var bytePreview = mref.open().list().filter(n ->
>> n.equals(bytePreviewResource)).toList();
>> bytePreview ==> []
>>
>> jshell> var inStream = mref.open().find(bytePreviewResource).orElseThrow();
>> inStream ==> jrt:/java.base/META-INF/preview/java/lang/Byte.class
>>
>>
>> i.e. the `bytePreview` variable would not be empty when an InputStream for
>> the same resource can be found (using `ModuleReader.find()`).
>>
>> Also the `open()` call returns the resource's inputstream:
>>
>>
>> bin/jshell
>> | Welcome to JShell -- Version 27-jep401ea3
>> | For an introduction type: /help intro
>>
>> jshell> var bytePreviewResource = "META-INF/preview/java/lang/Byte.class";
>> bytePreviewResource ==> "META-INF/preview/java/lang/Byte.class"
>>
>> jshell> var inStream =
>> java.lang.Object.class.getResourceAsStream(bytePreviewResource);
>> inStream ==> null
>>
>> jshell> var inStream = java.lang.Object.class.getResourceAsStream("/" +
>> bytePreviewResource);
>> inStream ==> java.io.ByteArrayInputStream@67205a84
>>
>> jshell> var mref = ModuleFinder.ofSystem().find("java.base").orElseThrow();
>> mref ==> [module java.base, location=jrt:/java.base]
>>
>> jshell> var inStream = mref.open().open(bytePreviewResource).orElseThrow();
>> inStream ==> java.io.ByteArrayInputStream@5e853265
>>
>> jshell>
>
> I'm not seeing the same behaviour with jshell. And what I'm seeing is exactly
> what I expect to see.
>
>
> [jdk/beta/open -> jimage_preview_mode]%
> ../build/linux-x64/images/jdk/bin/jshell
> | Welcome to JShell -- Version 27-internal
> | For an introduction type: /help intro
>
> jshell> var mref = ModuleFinder.ofSystem().find("java.base").orElseThrow();
> mref ==> [module java.base, location=jrt:/java.base]
>
> jshell> var bytePreviewResource = "META-INF/preview/java/lang/Byte.class";
> bytePreviewResource ==> "META-INF/preview/java/lang/Byte.class"
>
> jshell> var bytePreview = mref.open().list().filter(n ->
> n.equals(bytePreviewResource)).toList();
> bytePreview ==> []
>
> jshell> var inStream = mref.open().find(bytePreviewResource).orElseThrow();
> | Exception java.util.NoSuchElementException: No value present
> | at Optional.orElseThrow (Optional.java:381)
> | at do_it$Aux (#4:1)
> | at (#4:1)
>
> jshell> var inStream =
> java.lang.Object.class.getResourceAsStream(bytePreviewResource);
> inStream ==> null
>
> jshell> var inStream = java.lang.Object.class.getResourceAsStream("/" +
> bytePreviewResource);
> inStream ==> null
>
> jshell> var mref = ModuleFinder.ofSystem().find("java.base").orElseThrow();
> mref ==> [module java.base, location=jrt:/java.base]
>
> jshell> var inStream = mref.open().open(bytePreviewResource).orElseThrow();
> | Exception java.util.NoSuchElementException: No value present
> | at Optional.orElseThrow (Optional.java:381)
> | at do_it$Aux (#8:1)
> | at (#8:1)
>
>
> (that's with this PR patched into head as it would be submitted now).
>
> Obviously this is not the final state of things, and there's support for
> "exploded" images to be added, along with the plumbing of the compiler flags,
> so while this is a transient state, it's exactly what I expect to see.
Nevermind, of course there are no preview resources built into the jimage yet
for mainline.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29414#discussion_r3123015761