#2740: Fix BaseComponent#equals() stack overflow

This commit is contained in:
CertainLach 2020-01-05 10:44:16 +11:00 committed by md_5
parent d2ceccd646
commit 465215686b
2 changed files with 25 additions and 1 deletions

View File

@ -13,7 +13,7 @@ import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;
@Setter
@ToString(exclude = "parent")
@EqualsAndHashCode
@EqualsAndHashCode(exclude = "parent")
@NoArgsConstructor
public abstract class BaseComponent
{

View File

@ -409,6 +409,30 @@ public class ComponentsTest
Assert.assertEquals( text, roundtripLegacyText );
}
@Test
public void testEquals()
{
TextComponent first = new TextComponent( "Hello, " );
first.addExtra( new TextComponent( "World!" ) );
TextComponent second = new TextComponent( "Hello, " );
second.addExtra( new TextComponent( "World!" ) );
Assert.assertEquals( first, second );
}
@Test
public void testNotEquals()
{
TextComponent first = new TextComponent( "Hello, " );
first.addExtra( new TextComponent( "World." ) );
TextComponent second = new TextComponent( "Hello, " );
second.addExtra( new TextComponent( "World!" ) );
Assert.assertNotEquals( first, second );
}
private String fromAndToLegacyText(String legacyText)
{
return BaseComponent.toLegacyText( TextComponent.fromLegacyText( legacyText ) );