MaxGekk opened a new pull request, #56832:
URL: https://github.com/apache/spark/pull/56832
### What changes were proposed in this pull request?
`AttributeReference.hashCode` computes `name.hashCode()` directly:
```scala
override def hashCode: Int = {
var h = 17
h = h * 37 + name.hashCode() // NPE if name == null
...
}
```
This throws a `NullPointerException` when the attribute has a null name.
This PR makes the name contribution null-safe using `Objects.hashCode(name)`
(`java.util.Objects` is already imported).
### Why are the changes needed?
`AttributeReference.equals` already treats the name nullably (`name ==
ar.name`), but `hashCode` does not. An `AttributeReference` can carry a null
name (e.g. a `StructField` permits a null name and it flows into
`AttributeReference` via `DataTypeUtils.toAttribute`). When such an attribute
is placed in a hash-based collection (`HashSet`/`HashMap`, or via
`distinct`/`toSet`), `hashCode` throws an NPE.
This was noticed during review of #56831 (SPARK-57725), which fixes a
related but distinct null-name NPE in `AttributeSeq`'s case-insensitive name
maps. The two issues are independent and are addressed separately.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Added a test in `NamedExpressionSuite` asserting that
`AttributeReference.hashCode` does not throw on a null-named attribute and that
the equals/hashCode contract holds:
```
build/sbt 'catalyst/testOnly *NamedExpressionSuite'
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor
--
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]