adventure icon indicating copy to clipboard operation
adventure copied to clipboard

Adding an empty list as children to component doesn't result in `Component.empty()`

Open diogotcorreia opened this issue 3 years ago • 3 comments

Creating a component with

Component.text("").children(Collections.emptyList())

does not result in Component.empty().

image

Component.text("").children(Collections.emptyList()) == Component.empty()
// returns false, but should be true

Using Adventure 4.11.0.

This doesn't seem very logical at first, but I have a component that I don't know anything about and that I set its children to a List that I also don't know anything about, so sometimes it might result in an empty component.

diogotcorreia avatar Aug 02 '22 23:08 diogotcorreia

Setting the content to empty on a non-empty component also has the same behaviour: image

diogotcorreia avatar Aug 02 '22 23:08 diogotcorreia

Don’t use reference equality, use the .equals method

Machine-Maker avatar Aug 03 '22 00:08 Machine-Maker

@Machine-Maker The thing is, I am not using either .equals or == directly. Adventure's internals are using ==, such as here: https://github.com/KyoriPowered/adventure/blob/d32ab6b28f7ff43b0d1c89ca2a886c2a34b2d696/api/src/main/java/net/kyori/adventure/text/TextComponentImpl.java#L50 https://github.com/KyoriPowered/adventure/blob/d32ab6b28f7ff43b0d1c89ca2a886c2a34b2d696/api/src/main/java/net/kyori/adventure/text/Component.java#L128

This then causes .compact() to not behave as expected.

Also, found another one: image

diogotcorreia avatar Aug 03 '22 00:08 diogotcorreia