apache / apache/wayang

Record.compareTo() throws ClassCastException when comparing records

Open Beginner friendly
#813 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
274
Forks
140
Avg merge
5d 16h
Merged PRs (30d)
4

Description

## Description

`Record.compareTo()` throws a `ClassCastException` when comparing records containing `Comparable` values.

The issue occurs because `Record.values` is an `Object[]`, but `compareTo()` attempts to cast the entire array to `Comparable[]`.

## Location

`wayang-commons/wayang-basic/src/main/java/org/apache/wayang/basic/data/Record.java`

Around lines 184-185.

## Steps to Reproduce

```java
Record first = new Record(1, 2);
Record second = new Record(1, 2);

first.compareTo(second);
```

This results in a `ClassCastException`.

## Expected Behavior

`Record.compareTo()` should compare the record values without throwing a `ClassCastException`.

For the example above, comparing two equal records should return `0`.

## Proposed Solution

Compare the record values element-by-element instead of casting the entire `Object[]` to `Comparable[]`.

I have implemented a fix locally and added regression tests covering equal records, ordering, tie-breaking, single-field records, and dissimilar field types.

Contributor guide

Open the contributing guide

Research direction

Start in wayang-commons/wayang-basic/src/main/java/org/apache/wayang/basic/data/Record.java around lines 184-185 and inspect how compareTo() handles values. Reproduce the equal-record case first, then verify element-by-element comparison for ordering, tie-breaking, single-field records, and dissimilar field types; done means these comparisons no longer throw ClassCastException and equal records return 0.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.