--- old/test/jdk/valhalla/valuetypes/Reflection.java 2019-05-31 14:10:19.440006395 -0400 +++ new/test/jdk/valhalla/valuetypes/Reflection.java 2019-05-31 14:10:19.032004372 -0400 @@ -29,9 +29,13 @@ * @run main/othervm -XX:+EnableValhalla Reflection */ -import java.lang.reflect.*; +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InaccessibleObjectException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.Arrays; -import java.util.stream.Collectors; public class Reflection { public static void main(String... args) throws Exception { @@ -47,10 +51,12 @@ Reflection test = new Reflection(Point.class, "Point", o); test.newInstance(); test.constructor(); + test.pointConstructors(); test.accessFieldX(o.x); test.setAccessible(); test.trySetAccessible(); test.staticField(); + test.requireNoStaticInit(); } static void testLineClass() throws Exception { @@ -60,6 +66,7 @@ test.checkField("public final Point Line.p2", "p2", Point.class); test.checkMethod("public Point Line.p1()", "p1", Point.class); test.checkMethod("public Point Line.p2()", "p2", Point.class); + test.requireNoStaticInit(); } static void testNonFlattenValue() throws Exception { @@ -69,6 +76,7 @@ test.checkMethod("public Point NonFlattenValue.pointValue()", "pointValue", Point.class); test.checkMethod("public Point? NonFlattenValue.point()", "point", Point.class.asNullableType()); test.checkMethod("public boolean NonFlattenValue.has(Point,Point?)", "has", boolean.class, Point.class, Point.class.asNullableType()); + test.requireNoStaticInit(); } /* @@ -173,36 +181,51 @@ } catch (IllegalAccessException e) {} } + @SuppressWarnings("deprecation") void newInstance() throws Exception { - try { - Object o = c.newInstance(); - throw new RuntimeException("newInstance expected to be unsupported on inline class"); - } catch (IllegalAccessException e) {} + Object o = c.newInstance(); + assertEquals(o.getClass(), c); } void constructor() throws Exception { - try { - ctor.newInstance(); - throw new RuntimeException("IllegalAccessException not thrown"); - } catch (IllegalAccessException e) { } + Object o = ctor.newInstance(); + assertEquals(o.getClass(), c); + } + + void pointConstructors() throws Exception { + Constructor[] cons = c.getDeclaredConstructors(); + for (int i = 0; i < cons.length; i++) { + Class[] params = cons[i].getParameterTypes(); + Object o = null; + switch (params.length) { + case 0: + o = cons[i].newInstance(); + break; + case 2: + o = cons[i].newInstance(1, 2); + break; + default: + throw new RuntimeException(String.format("NYI: arguments: %s%n", + Arrays.toString(params))); + } + System.out.printf("%s.getDeclaredConstructors()[%d].newInstance(): %s%n", + c.getName(), i, o); + } } void setAccessible() throws Exception { - try { - ctor.setAccessible(true); - throw new RuntimeException("InaccessibleObjectException not thrown"); - } catch (InaccessibleObjectException e) { e.printStackTrace(); } + ctor.setAccessible(true); Field field = c.getField("x"); try { field.setAccessible(true); throw new RuntimeException("InaccessibleObjectException not thrown"); - } catch (InaccessibleObjectException e) { e.printStackTrace(); } + } catch (InaccessibleObjectException e) { + System.out.println("as expected: " + e.toString()); + } } void trySetAccessible() throws Exception { - if (ctor.trySetAccessible()) { - throw new RuntimeException("trySetAccessible should not succeed"); - } + ctor.trySetAccessible(); Field field = c.getField("x"); if (field.trySetAccessible()) { throw new RuntimeException("trySetAccessible should not succeed"); @@ -231,6 +254,16 @@ assertEquals(m.toString(), source); } + // Check that the class does not have a static method with the name + void requireNoStaticInit() throws Exception { + Method[] methods = c.getDeclaredMethods(); + for (Method m : methods) { + if (Modifier.isStatic(m.getModifiers())) { + assertFalse(m.getName().equals("")); + } + } + } + static void assertEquals(Object o1, Object o2) { if (o1 == o2 || o1.equals(o2)) return;