fix: correct record equals/toString/hashCode for reference and array components (#628) - #631
Conversation
…components (javapathfinder#628) Three bugs fixed in executeRecord() on call-site-generation branch: 1. equals() for array components: was doing deep element comparison, now uses reference identity (JEP 395: Objects.equals() on arrays delegates to Object.equals() = reference identity). 2. toString() for String/boxed/reference components: was printing JPF heap addresses (e.g. java.lang.String@209). Now: - String: ei.asString() for actual content - Boxed JDK types: wrapped value via 'value' field - Arrays: [I@hexHash format (Object.toString() semantics) - Other references: ClassName@hexHash 3. equals() for boxed types (Integer, Long, etc.): was using reference identity, now compares by wrapped value using a safe whitelist of known JDK boxed types. User classes with a 'value' field but identity-based equals() are NOT affected. 4. hashCode() made consistent with equals(): - String: content hash - Boxed JDK types: wrapped value hash - Arrays: objectRef (identity, consistent with array equals) - Nested records: recursive hash - Other refs: objectRef (identity) Added RecordReferenceComponentTest with 15 regression tests covering arrays, strings, boxed types, identity classes, null components, nested records, and hashCode consistency. Verified: all 15 new tests pass, full suite BUILD SUCCESSFUL.
cyrille-artho
left a comment
There was a problem hiding this comment.
Good work! Tests: Please check whether higher dimensions in arrays (as well as their content) are properly hashed.
|
With the new tests, there are two possible outcomes: (1) they do not all pass, in which case please look at the hash values and how to fix them; (2) they pass, in which case please update the PR. |
cyrille-artho
left a comment
There was a problem hiding this comment.
Please update the tests as in the previous comment.
|
Updated as requested. Added tests for different-length arrays and multidimensional arrays, including equivalent multidimensional arrays. The array hash implementation now recursively hashes array contents. All 17 RecordReferenceComponentTest tests pass, and the full build succeeds. |
|
Hi, |
Fix #628
Three bugs fixed in executeRecord() on call-site-generation branch:
equals() for array components: was doing deep element comparison, now uses reference identity (JEP 395: Objects.equals() on arrays delegates to Object.equals() = reference identity).
toString() for String/boxed/reference components: was printing JPF heap addresses (e.g. java.lang.String@209). Now:
equals() for boxed types (Integer, Long, etc.): was using reference identity, now compares by wrapped value using a safe whitelist of known JDK boxed types. User classes with a 'value' field but identity-based equals() are NOT affected.
hashCode() made consistent with Java record semantics:
Added RecordReferenceComponentTest regression coverage for arrays, strings, boxed types, identity classes, null components, nested records, different-length arrays, and multidimensional arrays.
Verified: all 17 regression tests pass and the full build succeeds.