On Wed, 24 Jun 2026 07:34:02 GMT, Du�an B�lek <[email protected]> wrote:

>> `ImageReader` fails to locate preview resources in a module’s top-level 
>> directory. A resource stored as
>> `META-INF/preview/file.txt` should be exposed in preview mode as `file.txt` 
>> matching how nested preview resources such as 
>> `META-INF/preview/directory/file.txt` are exposed as `directory/file.txt`.
>> 
>> The first problem is that the preview resource lookup path is constructed by 
>> concatenating `META-INF/preview` and the requested resource path without an 
>> intervening `/`. As a result, looking up `file.txt` in preview mode searches 
>> for
>> `META-INF/previewfile.txt` instead of `META-INF/preview/file.txt`. This 
>> affected both `findResourceNode` and `containsResource`.
>> 
>> The second problem is that top-level preview resources are not covered by 
>> the package-driven preview pre-scan when the image is opened, since they 
>> have no package path and the empty package is intentionally not represented 
>> under `/packages`. At lookup time, all preview resources are taken from 
>> caches; therefore, top-level preview resources are never returned. This 
>> affected `findNode`.
>> 
>> The proposal here is to add the missing slash when forming preview resource 
>> names in `ImageReader` and to check for top-level preview resources at 
>> lookup time. This allows top-level preview resources to be found and to 
>> override their non-preview counterparts when preview mode is enabled.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Du�an B�lek has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Modified to cover all node-cache orderings.

src/java.base/share/classes/jdk/internal/jimage/ImageReader.java line 687:

> 685:                                 Node childNode = 
> nodes.get(nonPreviewChildName);
> 686:                                 assert isPreviewOnly == (childNode != 
> null) :
> 687:                                         "Inconsistent child node: " + 
> nonPreviewChildName;

Are you sure this assert is correct? I assume the directory could be cached 
already so it should only assert  childNode != null when preview is enabled.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/31609#discussion_r3499548550

Reply via email to