Skip to content
Permalink
Browse files
8268418: [lworld] VM assert illegal mirror klass when calling Class::…
…getInterfaces on a flat array

Reviewed-by: fparain
  • Loading branch information
Mandy Chung committed Jun 9, 2021
1 parent 3552074 commit 31e99673a1fcb6c6a60205db4cc2366efb49f217
Showing 2 changed files with 33 additions and 1 deletion.
@@ -1170,7 +1170,7 @@ JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
InstanceKlass* ik = InstanceKlass::cast(klass);
size = ik->local_interfaces()->length();
} else {
assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
assert(klass->is_objArray_klass() || klass->is_typeArray_klass() || klass->is_flatArray_klass(), "Illegal mirror klass");
size = 3;
}

@@ -32,10 +32,12 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Objects;

import static org.testng.Assert.*;

@@ -174,6 +176,7 @@ static Object[][] methods() {
new Object[] { "toRef", Point.ref.class, new Class<?>[] { Object.class }},
};
}

@Test(dataProvider = "methods")
public void testMethod(String name, Class<?> returnType, Class<?>[] paramTypes) throws ReflectiveOperationException {
Method m = Point.class.getDeclaredMethod(name, paramTypes);
@@ -190,4 +193,33 @@ public void testConstructor() throws ReflectiveOperationException {
assertTrue(ctor.getDeclaringClass() == Point.class.asPrimaryType());
}

class C implements IdentityObject { }
primitive class T implements PrimitiveObject { }

@DataProvider(name="intfs")
Object[][] intfs() {
Point point = new Point(10, 20);
Point[] array = new Point[] { point };
return new Object[][]{
new Object[]{ new BasicTest(), new Class<?>[] { IdentityObject.class }},
new Object[]{ point, new Class<?>[] { PrimitiveObject.class }},
new Object[]{ new T(), new Class<?>[] { PrimitiveObject.class }},
new Object[]{ new C(), new Class<?>[] { IdentityObject.class }},
new Object[]{ Objects.newIdentity(), new Class<?>[] { IdentityObject.class }},
new Object[]{ array, new Class<?>[] { Cloneable.class, Serializable.class, IdentityObject.class }},
};
}

@Test(dataProvider = "intfs")
public void testGetInterfaces(Object o, Class<?>[] expectedInterfaces) {
Class<?> type = o.getClass();
assertEquals(type.getInterfaces(), expectedInterfaces);
if (type.isPrimitiveClass()) {
assertTrue(PrimitiveObject.class.isAssignableFrom(type));
assertTrue(o instanceof PrimitiveObject);
} else {
assertTrue(IdentityObject.class.isAssignableFrom(type));
assertTrue(o instanceof IdentityObject);
}
}
}

0 comments on commit 31e9967

Please sign in to comment.