diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java index c236f2b49..44be49b5e 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java @@ -651,7 +651,7 @@ public class TClass extends TObject implements TAnnotatedElement, TType { int j = 0; for (int i = 0; i < supertypes.getLength(); ++i) { if (supertypes.get(i) != platformClass.getMetadata().getSuperclass()) { - filteredSupertypes[j++] = (TClass) getClass(supertypes.get(j)); + filteredSupertypes[j++] = (TClass) getClass(supertypes.get(i)); } } diff --git a/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java b/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java index 7f12b081d..c36e99213 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java +++ b/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java @@ -474,8 +474,9 @@ class DependencyGraphBuilder { DependencyNode instanceNode = getNode(instance); DependencyNode receiverNode = getNode(receiver); - receiverNode.propagate(dependencyAnalyzer.classType); - instanceNode.getClassValueNode().addConsumer(type -> { + receiverNode.propagate(dependencyAnalyzer.getType("[java/lang/Class;")); + receiverNode.getArrayItem().propagate(dependencyAnalyzer.classType); + instanceNode.getArrayItem().getClassValueNode().addConsumer(type -> { String className = type.getName(); if (className.startsWith("[")) { return; diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/ClassTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/ClassTest.java index a3fb30d07..91d5ed39d 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/ClassTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/ClassTest.java @@ -23,6 +23,8 @@ import static org.junit.Assert.assertTrue; import java.lang.annotation.Annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Collections; +import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.teavm.junit.TeaVMTestRunner; @@ -39,7 +41,12 @@ public class ClassTest { @Test public void classSimpleNameEvaluated() { - + assertEquals("Object", Object.class.getSimpleName()); + assertEquals("Object[]", Object[].class.getSimpleName()); + assertEquals("int", int.class.getSimpleName()); + assertEquals("int[]", int[].class.getSimpleName()); + assertEquals("InnerClass", InnerClass.class.getSimpleName()); + assertEquals("", new Object() { }.getClass().getSimpleName()); } @Test @@ -188,6 +195,26 @@ public class ClassTest { assertEquals(Integer.class, annot.n()); } + @Test + public void getInterfaces() { + assertEquals(0, SuperclassWithoutInterfaces.class.getInterfaces().length); + assertEquals(Set.of(TestInterface1.class, TestInterface2.class), + Set.of(ClassWithInterfaces.class.getInterfaces())); + } + + private static class SuperclassWithoutInterfaces { + } + + private static class ClassWithInterfaces extends SuperclassWithoutInterfaces + implements TestInterface1, TestInterface2 { + } + + private interface TestInterface1 { + } + + private interface TestInterface2 { + } + @TestAnnot private static class A { }