Fix NPE in record.equals(null) (#688)

This commit is contained in:
Ivan Hetman 2023-04-11 10:30:21 +03:00 committed by GitHub
parent 3e1edeb90c
commit fcb750675c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -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);

View File

@ -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"));