Equivalence between KeyImpl and TypedKeyImpl is not symmetric
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 3.5k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 11
Description
Expected behavior
Object#equals's contract requires:
It is symmetric: for any non-null reference values
xandy,x.equals(y)should return true if and only ify.equals(x)returns true.
Observed/Actual behavior
Equivalence between TypedKeyImpl and KeyImpl is not symmetric
Steps/models to reproduce
Key key = Key.key("minecraft:stone");
TypedKey<ItemType> typedKey = TypedKey.create(RegistryKey.ITEM, key);
System.out.println(key.equals(typedKey)); // true
System.out.println(typedKey.equals(key)); // false
Plugin and Datapack List
None
Paper version
This server is running Paper version 1.21.11-126-main@3f5728e (2026-02-28T11:49:07Z) (Implementing API version 1.21.11-R0.1-SNAPSHOT)
Other
In my opinion TypedKey shouldn't extend Key. But since it is too late to change this now, I think the problem could be solved by:
- In
TypedKeyImpl, overrideequalsand check if the other object is also aTypedKey. If so, additionally compare registry key. Otherwise, only compare namespace and value. - In
TypedKeyImpl, overridehashCodeand replace its implementation with that ofKeyImpl(from adventure), such that the registry key has no influence on the hash code and equal keys have equal hash codes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the KeyImpl and TypedKeyImpl equality and hashCode implementations, then reproduce the asymmetric results from the issue's Java example. Done means the equality contract and hash-code relationship described in the issue are satisfied; pull request #14152 is already open for this issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100