RFR: 8286386: Address possibly lossy conversions in java.net.http [v5]
Daniel Fuchs
dfuchs at openjdk.java.net
Thu May 12 10:12:07 UTC 2022
On Thu, 12 May 2022 09:00:37 GMT, Pavel Rappo <prappo at openjdk.org> wrote:
>> This is what I mean:
>>
>> jshell> long codeLengthOf = (long)Integer.MAX_VALUE + 1
>> codeLengthOf ==> 2147483648
>>
>> jshell> int bufferLen = 0
>> bufferLen ==> 0
>>
>> jshell> bufferLen + codeLengthOf <= 64
>> $3 ==> false
>>
>> jshell> bufferLen + (int)codeLengthOf <= 64
>> $4 ==> true
>
> Yes, inserting explicit casts seems less clean than changing `codeLengthOf` to this:
>
> private static int codeLengthOf(char c) {
> return (int) (codes[c] & 0x00000000ffffffffL);
> }
>
> There are 256 elements in constant `long[] codes`. One could easily check that each element when ANDed with `0x00000000ffffffffL` results in a value that fits into the first 31 bits of `int`.
OK - I will change codeLengthOf as suggested. It was not immediately obvious to me that the values would fit in the first 31 bits.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8656
More information about the net-dev
mailing list