pjfanning opened a new pull request, #1381:
URL: https://github.com/apache/poi/pull/1381

   This follows up #1379. These `hashCode` methods broke the 
`equals`/`hashCode` contract.
   
   ### HPSF
   - **`Property.hashCode`** was `Objects.hash(id, type, value)`, but 
`Property.equals` differs from that in two ways:
     - It treats `VT_LPSTR` and `VT_LPWSTR` as the same type.
     - It compares `byte[]` values by content, ignoring trailing padding bytes. 
`Objects.hash` hashes an array by identity.
   
     So equal properties could have different hash codes. `hashCode` now leaves 
out the type and hashes `byte[]` values over their unpadded content.
   - **`CustomProperty`** overrode `hashCode` as `Objects.hash(name, id)`. 
Since #1379 a `CustomProperty` can equal a plain `Property` (when given a plain 
`Property`, `equals` ignores the name), so it now inherits `Property.hashCode`. 
Two equal custom properties still have equal hash codes.
   
   ### HWPF
   - **`TextPiece.hashCode`** and **`OldTextPiece.hashCode`** returned a 
constant behind `assert false : "hashCode not designed"`, so with assertions 
enabled any hash-based collection failed. `TextPiece` now hashes the fields its 
`equals` compares (start, end, unicode flag, text), and `OldTextPiece` hashes 
its raw bytes.
   
   Hash codes are only used by hash-based collections, and POI doesn't put 
these objects in any, so behaviour within POI is unchanged.
   
   New tests in `TestCustomProperty` and `TestTextPiece` cover each case. The 
hpsf package and the hwpf model tests pass.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to