RFR: 8286386: Address possibly lossy conversions in java.net.http
Daniel Fuchs
dfuchs at openjdk.java.net
Wed May 11 17:52:51 UTC 2022
On Wed, 11 May 2022 17:37:44 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> Yes - that's my understanding.
>
> These methods either set or clear a single bit in `firstChar`.
> The constant is an `int` so its complement is a 32 bit int.
>
> It could also be written as `~ (char) 0b1000000_0000000`. Then the 16 bit unsigned char would be complemented.
> Either way, the cast is needed to be explicit about the size of the constant.
>
> Another way to avoid the cast would be to define the bit positions as:
>
> `private static final char FIN_BIT = 0b10000000_00000000;
> ... etc.
> `
> Then the code in the methods would not need the cast.
>
>
> if (value) {
> firstChar |= FIN_BIT;
> } else {
> firstChar &= ~FIN_BIT;
> }
Ah! Good point. Maybe I should use a constant and get rid of the cast.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8656
More information about the net-dev
mailing list