From fcb750675c33c7622e8a2da9e0843f80342a8db2 Mon Sep 17 00:00:00 2001 From: Ivan Hetman Date: Tue, 11 Apr 2023 10:30:21 +0300 Subject: [PATCH] Fix NPE in record.equals(null) (#688) --- .../teavm/classlib/impl/record/ObjectMethodsSubstitutor.java | 2 +- tests/src/test/java/org/teavm/vm/RecordTest.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/classlib/src/main/java/org/teavm/classlib/impl/record/ObjectMethodsSubstitutor.java b/classlib/src/main/java/org/teavm/classlib/impl/record/ObjectMethodsSubstitutor.java index ac2036785..8b3b7b571 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/record/ObjectMethodsSubstitutor.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/record/ObjectMethodsSubstitutor.java @@ -54,7 +54,7 @@ public class ObjectMethodsSubstitutor implements BootstrapMethodSubstitutor { pe.constant(1).propagateTo(result); pe.jump(joint); }); - ConditionProducer classCondition = () -> thisVar.isNull() + ConditionProducer classCondition = () -> thatVar.isNull() .or(() -> thatVar.invokeVirtual("getClass", Class.class).isNotSame(pe.constant(type))); pe.when(classCondition).thenDo(() -> { pe.constant(0).propagateTo(result); diff --git a/tests/src/test/java/org/teavm/vm/RecordTest.java b/tests/src/test/java/org/teavm/vm/RecordTest.java index 27993501c..b310a59b7 100644 --- a/tests/src/test/java/org/teavm/vm/RecordTest.java +++ b/tests/src/test/java/org/teavm/vm/RecordTest.java @@ -16,6 +16,7 @@ package org.teavm.vm; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -26,6 +27,7 @@ import org.teavm.junit.TeaVMTestRunner; public class RecordTest { @Test public void equalsMethod() { + assertFalse(new A(2, "q").equals(null)); assertEquals(new A(2, "q"), new A(2, "q")); assertNotEquals(new A(2, "q"), new A(3, "q")); assertNotEquals(new A(2, "q"), new A(2, "w"));