On Wed, 18 Mar 2026 06:56:00 GMT, Shaojin Wen <[email protected]> wrote:

>> FloatEntryImpl.equals() and DoubleEntryImpl.equals() used == for comparison, 
>> which returns false for NaN == NaN per IEEE 754. This caused two different 
>> FloatEntry/DoubleEntry objects holding NaN to not be considered equal, 
>> violating the equals/hashCode contract (same hashCode but equals returns 
>> false).
>> 
>> Similarly, SplitConstantPool.findFloatEntry() and findDoubleEntry() used == 
>> to match values, so NaN entries could never be found in the pool, causing 
>> every floatEntry(Float.NaN) or doubleEntry(Double.NaN) call to create a 
>> duplicate entry and bloat the constant pool.
>> 
>> Fix by using Float.floatToRawIntBits() and Double.doubleToRawLongBits() for 
>> bitwise comparison, which correctly handles NaN and also properly 
>> distinguishes +0.0 from -0.0.
>
> Shaojin Wen has updated the pull request incrementally with two additional 
> commits since the last revision:
> 
>  - Refactor findEntry loop to use while with direct width increment
>    
>    Change the loop from for-with-post-increment to a while loop that
>    increments by e.width() directly, making the code clearer.
>    
>    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
>  - Add tests for Float/Double NaN with different bit patterns
>    
>    Since the code uses raw bit variants 
> (floatToRawIntBits/doubleToRawLongBits)
>    when converting floating-point values to integral bits for hashCode and
>    equals, the tests should cover the cases of NaNs with different bit 
> patterns.
>    
>    - testFloatNaNWithDifferentBitPatternsAreDistinct: Verify that NaNs with
>      different bit patterns create distinct constant pool entries
>    - testDoubleNaNWithDifferentBitPatternsAreDistinct: Same for Double
>    - testFloatNaNWithDifferentBitPatternsAreNotEqual: Verify that NaNs with
>      different bit patterns are not equal
>    - testDoubleNaNWithDifferentBitPatternsAreNotEqual: Same for Double
>    - testFloatNaNWithSameBitPatternIsDeduplicated: Verify that NaNs with the
>      same bit pattern are deduplicated
>    - testDoubleNaNWithSameBitPatternIsDeduplicated: Same for Double
>    
>    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

Thank you for the feedback. I've removed all AI co-author attributions from the 
commits and have updated the PR. The commits now only include attribution for 
actual human contributors (e.g., rgiulietti for the loop improvement 
suggestion).

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

PR Comment: https://git.openjdk.org/jdk/pull/30196#issuecomment-4080807264

Reply via email to