hansva opened a new issue, #9292:
URL: https://github.com/apache/hop/issues/9292

   ### What needs to happen?
   
   Six small defects in the core row and value metadata classes break the 
`equals`/`hashCode` contract or fail on valid input. Each one can make a 
`HashMap`, a `HashSet` or a cache behave incorrectly, or makes a helper ignore 
what it was given.
   
   | Class | Defect | Effect |
   |---|---|---|
   | `RowMeta.equals` | Compares only as many fields as `this` has | Row 
metadata `[a]` equals `[a, b]`, but `[a, b]` does not equal `[a]`. Equal 
objects also get different hash codes. |
   | `RowMeta.hashCode(Object[] row)` | Hashes the whole array, including the 
empty slots at its end | Rows are usually allocated longer than their metadata 
(`RowDataUtil.OVER_ALLOCATE_SIZE`), so the same values hash differently 
depending on the array length. |
   | `ValueMetaBase.hashCode` | Includes origin, comments, collator and index, 
which `equals` does not compare | Two equal value metas can have different hash 
codes. |
   | `RowBuffer.hashCode` | Hashes the row arrays by identity, while `equals` 
compares them value by value | Two equal buffers have different hash codes. |
   | `RowMetaAndData.equals` | No null or type check | `equals(null)` throws a 
`NullPointerException`; `equals` with another type throws a 
`ClassCastException`. |
   | `RowMetaBuilder.addNumber` / `addBigNumber` | Ignore the precision 
argument and always use -1 | Fields built with a precision lose it. |
   | `RowDataUtil.createResizedCopy` | Reads `objects.length` before its null 
check | A null row throws a `NullPointerException` instead of returning a new 
empty row. |
   | `RowDataUtil.OVER_ALLOCATE_SIZE` | `public static`, not `final` | Any code 
can change the allocation size for the whole JVM. |
   
   **Proposed change**
   
   - `RowMeta.equals` first compares the number of fields.
   - `RowMeta.hashCode(row)` hashes only the first `size()` values. For a row 
of exactly `size()` values the result is unchanged, so hashes that Checksum and 
Combination lookup store remain valid.
   - `ValueMetaBase.hashCode` uses exactly the fields that `equals` compares.
   - `RowBuffer.hashCode` uses the row metadata and the number of rows.
   - `RowMetaAndData.equals` returns `true` for the same object and `false` for 
`null` or another type.
   - `RowMetaBuilder` passes the precision through.
   - `RowDataUtil.createResizedCopy(null, n)` returns a new row of size `n`, 
and `OVER_ALLOCATE_SIZE` becomes `final`.
   
   A new `RowHelpersContractTest` covers each case.
   
   **Behaviour change**
   
   None for valid use, beyond the fixes themselves. Exact-size rows keep their 
hash. Code that relied on a shorter `RowMeta` being equal to a longer one, or 
on an exception from `RowMetaAndData.equals`, now gets `false`.
   
   ### Issue Priority
   
   Priority: 2
   
   ### Issue Component
   
   Component: API


-- 
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