On Thu, 16 Mar 2023 07:51:25 GMT, Adam Sotona <asot...@openjdk.org> wrote:

>> src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java
>>  line 160:
>> 
>>> 158:                     
>>> resource.type().equals(ResourcePoolEntry.Type.CLASS_OR_RESOURCE)) {
>>> 159:                     byte[] bytes = resource.contentBytes();
>>> 160:                     if (newClassReader(path, 
>>> bytes).interfaces().stream()
>> 
>> `IncludeLocalesPluginTest.java` test is failing.   Adding 
>> `-J-Djlink.debug=true` will get the stack trace:
>>  
>> 
>> Failed to parse class file: 
>> /jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th
>> java.lang.IllegalStateException: Bad magic number
>>      at 
>> java.base/jdk.internal.classfile.impl.ClassReaderImpl.<init>(ClassReaderImpl.java:94)
>>      at 
>> java.base/jdk.internal.classfile.impl.ClassImpl.<init>(ClassImpl.java:68)
>>      at java.base/jdk.internal.classfile.Classfile.parse(Classfile.java:165)
>>      at 
>> jdk.jlink/jdk.tools.jlink.internal.plugins.AbstractPlugin.newClassReader(AbstractPlugin.java:105)
>>      at 
>> jdk.jlink/jdk.tools.jlink.internal.plugins.IncludeLocalesPlugin.lambda$transform$5(IncludeLocalesPlugin.java:161)
>>      at 
>> jdk.jlink/jdk.tools.jlink.plugin.ResourcePool.lambda$transformAndCopy$0(ResourcePool.java:112)
>>      at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
>>      at 
>> java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1924)
>>      at 
>> java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
>>      at 
>> jdk.jlink/jdk.tools.jlink.plugin.ResourcePool.transformAndCopy(ResourcePool.java:111)
>>      at 
>> jdk.jlink/jdk.tools.jlink.internal.plugins.IncludeLocalesPlugin.transform(IncludeLocalesPlugin.java:154)
>>      at 
>> jdk.jlink/jdk.tools.jlink.internal.ImagePluginStack.visitResources(ImagePluginStack.java:262)
>>      at 
>> jdk.jlink/jdk.tools.jlink.internal.ImageFileCreator.generateJImage(ImageFileCreator.java:184)
>>      at 
>> jdk.jlink/jdk.tools.jlink.internal.ImageFileCreator.writeImage(ImageFileCreator.java:163)
>>      at 
>> jdk.jlink/jdk.tools.jlink.internal.ImageFileCreator.create(ImageFileCreator.java:100)
>>      at 
>> jdk.jlink/jdk.tools.jlink.internal.JlinkTask$ImageHelper.retrieve(JlinkTask.java:889)
>>      at 
>> jdk.jlink/jdk.tools.jlink.internal.ImagePluginStack.operate(ImagePluginStack.java:194)
>>      at 
>> jdk.jlink/jdk.tools.jlink.internal.JlinkTask.createImage(JlinkTask.java:452)
>>      at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.run(JlinkTask.java:292)
>>      at jdk.jlink/jdk.tools.jlink.internal.Main.run(Main.java:56)
>>      at jdk.jlink/jdk.tools.jlink.internal.Main.main(Main.java:34)
>> Dumping class file 
>> 26549-include-locales//jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th
>> ```  
>> 
>> Apparently `/jdk.localedata/sun/text/resources/ext/LineBreakIteratorData_th` 
>> is not a valid class file.  Using ASM `ClassReader` to parse this resource 
>> file succeeds because it does not do much of the class file validation.    
>> Instead the ClassFile API throws `IllegalStateException` as it has a bad 
>> magic number.
>> 
>> @naotoj what is the file format of this `LineBreakIteratorData_th` file?
>
> This plugin does not fit to the Classfile API use cases portfolio at all. 
> Here it is only needed to get interfaces list out of the constant pool and 
> then the Utf8 CP entries are in-place modified. That is out of the Classfile 
> API or ASM capabilities. Bad magic number is not the only difference, both 
> libraries fail whenever touching even headers of any other standard classfile 
> elements, only constant pool and interfaces seem to be "safe". 
> I can prepare very simple standalone helper class dealing with this case to 
> remove ASM dependency. 
> However knowing more about the file format is always useful :)

The file `LineBreakIteratorData_th` is not a class file, thus the exception is 
appropriate. This plugin test is trying to verify the integrity of the 
generated jimage, not only the required class files for the specified locale, 
but also the required resources as such. The file itself is a binary file that 
the BreakIterator uses internally.

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

PR: https://git.openjdk.org/jdk/pull/12944

Reply via email to