Skip to content

Fix ClassCastException in Record.compareTo() - #814

Open
harshitsingh070 wants to merge 1 commit into
apache:mainfrom
harshitsingh070:fix-record-compare-to
Open

harshitsingh070 wants to merge 1 commit into
apache:mainfrom
harshitsingh070:fix-record-compare-to

Conversation

@harshitsingh070

Copy link
Copy Markdown
Contributor

Description

Fixes #813

Record.compareTo() attempted to cast the underlying Object[] values to Comparable[].

Since the runtime type of the array remains Object[], this resulted in a ClassCastException when comparing records, even when the individual fields implemented Comparable.

Changes

  • Replaced the invalid Object[] to Comparable[] array cast with element-wise comparison.
  • Preserved the existing field type validation.
  • Added regression tests for Record.compareTo() covering equality, ordering, tie-breaking, single-field records, and dissimilar field types.

Testing

Ran:

.\mvnw test -pl wayang-commons/wayang-basic "-Dtest=org.apache.wayang.basic.data.RecordTest"

Result:

Tests run: 6, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

Also ran the specific regression test:

.\mvnw test -pl wayang-commons/wayang-basic "-Dtest=org.apache.wayang.basic.data.RecordTest#compareToShouldNotThrowClassCastExceptionDueToArrayCast"

Result:

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

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.

Record.compareTo() throws ClassCastException when comparing records

1 participant