Weird behaviour of `ItemStackComparators`

I need to compare two item stacks if they are equal, except I don’t care about their quantity.
I’ve tried IGNORE_SIZE, but it works weirdly: even when I pass exactly the same object in both places, it still returns me -1:
ItemStackComparators.IGNORE_SIZE.get().compare(item1, item1) = -1
Is this supposed to work like this, am I missing something?

Also, the DEFAULT one is also weird, I would guess it should actually take the quantity into account, but actually it returns 0 on stacks of the same item but with different quantity…

The full “logs” look like this:

item1 = 1 BlockItem[name=null]
item1.toContainer() = MemoryDataContainer{safety=ALL_DATA_CLONED, map={ContentVersion=1, ItemType=minecraft:dirt, Count=1, UnsafeDamage=0}}
item2 = 9 BlockItem[name=null]
item2.toContainer() = MemoryDataContainer{safety=ALL_DATA_CLONED, map={ContentVersion=1, ItemType=minecraft:dirt, Count=9, UnsafeDamage=0}}
ItemStackComparators.IGNORE_SIZE.get().compare(item1, item2) = -1
ItemStackComparators.IGNORE_SIZE.get().compare(item1, item1) = -1
ItemStackComparators.IGNORE_SIZE.get().compare(item2, item2) = -1
ItemStackComparators.DEFAULT.get().compare(item1, item2) = 0
ItemStackComparators.DEFAULT.get().compare(item1, item1) = 0
ItemStackComparators.DEFAULT.get().compare(item2, item2) = 0

So, I went down the rabbit hole a bit (not deep enough to fix the most important issue though, as I don’t have enough time for that, but maybe just enough for someone from Sponge dev team to pick it up):

The issue with different stack sizes being compared as equal (despite using bySize comparator) is a one line fix in SpongeItemStackComparatorFactory in bySize line 73:
replace return new SpongeItemStackComparatorFactory(this.comparator == null ? comparator : this.comparator.thenComparing(this.comparator));
with return new SpongeItemStackComparatorFactory(this.comparator == null ? comparator : this.comparator.thenComparing(comparator));

The other issue (of items not being compared as the same) is more complicated. Any comparator that uses either byData or byDurability (which are also weird btw, as they are exactly the same) is affected, because the values used for comparison probably have wrong hashCode/equals implementation (they compare as different despite being the same):

valueFromValues (hashcode == 336891284) = ImmutableSpongeValue{key=SpongeKey{key=sponge:display_name, elementType=interface net.kyori.adventure.text.Component}, element=TranslatableComponentImpl{key="chat.square_brackets", args=[TextComponentImpl{content="", style=StyleImpl{color=null, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[TranslatableComponentImpl{key="block.minecraft.dirt", args=[], style=StyleImpl{color=null, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}]}], style=StyleImpl{color=NamedTextColor{name="white", value="#ffffff"}, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=HoverEvent{action=show_item, value=ShowItem{item=ResourceLocation{namespace="minecraft", value="dirt"}, count=1, nbt=null}}, insertion=null, font=null}, children=[]}}
value           (hashcode == 277145678) = ImmutableSpongeValue{key=SpongeKey{key=sponge:display_name, elementType=interface net.kyori.adventure.text.Component}, element=TranslatableComponentImpl{key="chat.square_brackets", args=[TextComponentImpl{content="", style=StyleImpl{color=null, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[TranslatableComponentImpl{key="block.minecraft.dirt", args=[], style=StyleImpl{color=null, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}]}], style=StyleImpl{color=NamedTextColor{name="white", value="#ffffff"}, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=HoverEvent{action=show_item, value=ShowItem{item=ResourceLocation{namespace="minecraft", value="dirt"}, count=1, nbt=null}}, insertion=null, font=null}, children=[]}}
value.equals(valueFromValues) = false
value.equals(value) = true
valueFromValues.equals(valueFromValues) = true