Skip to content

fix: correct record equals/toString/hashCode for reference and array components (#628) - #631

Open
Darshan-dev57 wants to merge 2 commits into
javapathfinder:call-site-generationfrom
Darshan-dev57:fix-628-record-reference-components
Open

fix: correct record equals/toString/hashCode for reference and array components (#628)#631
Darshan-dev57 wants to merge 2 commits into
javapathfinder:call-site-generationfrom
Darshan-dev57:fix-628-record-reference-components

Conversation

@Darshan-dev57

@Darshan-dev57 Darshan-dev57 commented Aug 11, 2026

Copy link
Copy Markdown

Fix #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 Java record semantics:

    • String: content hash
    • Boxed JDK types: wrapped value hash
    • Arrays: content-based hash, recursively handling multidimensional arrays
    • Nested records: recursive hash
    • Other references: identity-based hash

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.

…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 cyrille-artho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! Tests: Please check whether higher dimensions in arrays (as well as their content) are properly hashed.

Comment thread src/tests/java17/records/RecordReferenceComponentTest.java
@cyrille-artho

Copy link
Copy Markdown
Member

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 cyrille-artho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the tests as in the previous comment.

@Darshan-dev57

Copy link
Copy Markdown
Author

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.

@cyrille-artho

cyrille-artho commented Aug 14, 2026

Copy link
Copy Markdown
Member

Hi,
Thank you for the update. I have now 12 unit tests failing on Mac OS with Java 17.0.20.
With Java 17.0.9 on Mac OS (graalvm), I have 14 unit tests failing.
On Ubuntu 24.04.02 (Darshan's system), all unit tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants