On Sun, 22 Sep 2024 20:48:08 GMT, Chen Liang <li...@openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/classfile/impl/DirectClassBuilder.java
>>  line 207:
>> 
>>> 205: 
>>> 206:         // Now we can make the head
>>> 207:         head.writeLong(((long) ClassFile.MAGIC_NUMBER) << 32 | 
>>> minorVersion << 16 | majorVersion);
>> 
>> `minorVersion` needs to be cast to a `long` first, as otherwise when the MSB 
>> is set after the shift, then it’ll overwrite the magic number with all 1s.
>> 
>> Suggestion:
>> 
>>         head.writeLong(((long) ClassFile.MAGIC_NUMBER) << 32 | ((long) 
>> minorVersion) << 16 | majorVersion);
>
> For clarity, I think using Integer.toUnsignedLong on the shift result is 
> better

If minorVersion > 0xFFFF, the result of using Integer.toUnsignedLong will be 
wrong. I guess this is the reason why the previous version build failed

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21118#discussion_r1770667423

Reply via email to