AmarGhugare opened a new pull request, #1867:
URL: https://github.com/apache/commons-lang/pull/1867

   `DiffBuilder.append(String, Object, Object)` throws `ClassCastException` 
when comparing incompatible arrays or an array with a scalar. This can also 
silently hide a real difference: `ReflectionDiffBuilder` catches that 
exception, so an `Object` field changing from `int[]` to `long[]` reports zero 
differences.
   
   For example:
   
   ```java
   Object left = new int[] { 1 };
   Object right = new long[] { 1 };
   DiffBuilder.<String>builder().setLeft("left").setRight("right")
       .setStyle(ToStringStyle.SHORT_PREFIX_STYLE).build()
       .append("value", left, right).build();
   ```
   
   This should record one difference retaining both values, but currently 
throws. Comparing an array with a scalar also depends on operand order: `int[]` 
versus `String` throws, while `String` versus `int[]` records a difference.
   
   Only dispatch to a typed array overload when the values are null-compatible, 
have the same primitive array type, or are both reference arrays. Other 
combinations use the existing `Object` comparison. This preserves null-array 
handling and equality comparisons between reference arrays with different 
component types.
   
   Regression coverage includes all eight primitive array types, 
primitive/reference array mismatches, array/scalar pairs in both orders, 
different array dimensions, nulls, compatible reference arrays, and 
reflection-based comparisons. Against the original code, the new tests produce 
12 cast errors and one assertion failure for a missing reflection difference.
   
   Validation:
   
   - `DiffBuilderTest` and `ReflectionDiffBuilderTest`: all 89 tests pass.
   - Full default Maven build on JDK 25 with Java 8 compilation target: 108,511 
tests, zero failures or errors, 18 skipped. This includes the inherited 
`DiffBuilderNoForceTest` cases.
   - Coverage, RAT, Checkstyle, Japicmp, SpotBugs, PMD, and Javadoc checks pass.
   - `git diff --check` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to