PaperMC / PaperMC/Paper

Equivalence between KeyImpl and TypedKeyImpl is not symmetric

Open
#13,678 1 comment 0 reactions 0 assignees View on GitHub

@Machine-Maker is already working on this.

Since Aug 7, 2026.

  • #14152 by @Machine-Maker — open
status: accepted version: 1.21.11
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 x and y, x.equals(y) should return true if and only if y.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:

  1. In TypedKeyImpl, override equals and check if the other object is also a TypedKey. If so, additionally compare registry key. Otherwise, only compare namespace and value.
  2. In TypedKeyImpl, override hashCode and replace its implementation with that of KeyImpl (from adventure), such that the registry key has no influence on the hash code and equal keys have equal hash codes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.