--- old/test/hotspot/jtreg/runtime/LoaderConstraints/duplicateLE/Test.java 2018-04-12 12:05:13.108872000 +0200 +++ new/test/hotspot/jtreg/runtime/LoaderConstraints/duplicateLE/Test.java 2018-04-12 12:05:12.610830000 +0200 @@ -40,6 +40,12 @@ "loader instance of PreemptingClassLoader (parent: \"app\" " + "jdk.internal.loader.ClassLoaders$AppClassLoader) attempted duplicate class definition for test.Foo."; + // Check that all names have external formatting ('.' and not '/' in package names). + // Check for name and parent of class loader. + static String expectedErrorMessage2 = + "loader \"DuplicateLE_Test_Loader\" (instance of PreemptingClassLoader, parent: \"app\" " + + "jdk.internal.loader.ClassLoaders$AppClassLoader) attempted duplicate class definition for test.Foo."; + // Test that the error message is correct when a loader constraint error is // detected during vtable creation. // @@ -47,17 +53,17 @@ // overrides "J.m()LFoo;". But, Task's class Foo and super type J's class Foo // are different. So, a LinkageError exception should be thrown because the // loader constraint check will fail. - public static void test1() throws Exception { + public static void test(String loaderName, String expectedErrorMessage) throws Exception { String[] classNames = {"test.Foo"}; - ClassLoader l = new PreemptingClassLoader(null, classNames, false); + ClassLoader l = new PreemptingClassLoader(loaderName, classNames, false); l.loadClass("test.Foo"); try { l.loadClass("test.Foo").newInstance(); throw new RuntimeException("Expected LinkageError exception not thrown"); } catch (LinkageError e) { String errorMsg = e.getMessage(); - if (!errorMsg.equals(expectedErrorMessage1)) { - System.out.println("Expected: " + expectedErrorMessage1 + "\n" + + if (!errorMsg.equals(expectedErrorMessage)) { + System.out.println("Expected: " + expectedErrorMessage + "\n" + "but got: " + errorMsg); throw new RuntimeException("Wrong LinkageError exception thrown: " + errorMsg); } @@ -65,34 +71,9 @@ } } - // Check that all names have external formatting ('.' and not '/' in package names). - // Check for name and parent of class loader. - static String expectedErrorMessage2 = - "loader \"DuplicateLE_Test_Loader\" (instance of PreemptingClassLoader, parent: \"app\" " + - "jdk.internal.loader.ClassLoaders$AppClassLoader) attempted duplicate class definition for test.Foo."; - - // Same as test1, but ClassLoader has a name. - public static void test2() throws Exception { - String[] classNames = {"test.Foo"}; - ClassLoader l = new PreemptingClassLoader("DuplicateLE_Test_Loader", classNames, false); - l.loadClass("test.Foo"); - try { - l.loadClass("test.Foo"); - throw new RuntimeException("Expected LinkageError exception not thrown"); - } catch (LinkageError e) { - String errorMsg = e.getMessage(); - if (!errorMsg.equals(expectedErrorMessage2)) { - System.out.println("Expected: " + expectedErrorMessage2 + "\n" + - "but got: " + errorMsg); - throw new RuntimeException("Wrong LinkageError exception thrown: " + errorMsg); - } - System.out.println("Passed with message: " + errorMsg); - } - } - public static void main(String args[]) throws Exception { - test1(); - test2(); + test(null, expectedErrorMessage1); + test("DuplicateLE_Test_Loader", expectedErrorMessage2); } }