test/hotspot/jtreg/runtime/LoaderConstraints/differentLE/Test.java
changeset 50634 c349d409262a
parent 50036 e0dbf14885b8
child 51097 bef02342d179
equal deleted inserted replaced
50633:b8055b38b252 50634:c349d409262a
    73     // it tries to load interface A. As it does not find it (there is no A.impl2),
    73     // it tries to load interface A. As it does not find it (there is no A.impl2),
    74     // it asks the super classloader for A.
    74     // it asks the super classloader for A.
    75     // Then it loads the D2 variant of D from the current working directory and it's
    75     // Then it loads the D2 variant of D from the current working directory and it's
    76     // superclass C. This fails as D1 is already loaded with the same superclass.
    76     // superclass C. This fails as D1 is already loaded with the same superclass.
    77 
    77 
    78     static String expectedErrorMessage =
    78     // Break the expectedErrorMessage into 2 pieces since the loader name will include
    79         "loader constraint violation: loader \"<unnamed>\" (instance of PreemptingClassLoader, " +
    79     // its identity hash and can not be compared against.
    80         "child of \"app\" jdk.internal.loader.ClassLoaders$AppClassLoader) wants to load " +
    80     static String expectedErrorMessage_part1 = "loader constraint violation: loader PreemptingClassLoader @";
       
    81     static String expectedErrorMessage_part2 = " (instance of PreemptingClassLoader, " +
       
    82         "child of 'app' jdk.internal.loader.ClassLoaders$AppClassLoader) wants to load " +
    81         "class test.D_ambgs. A different class with the same name was previously loaded " +
    83         "class test.D_ambgs. A different class with the same name was previously loaded " +
    82         "by \"app\" (instance of jdk.internal.loader.ClassLoaders$AppClassLoader).";
    84         "by 'app' (instance of jdk.internal.loader.ClassLoaders$AppClassLoader).";
    83 
    85 
    84     public static void test_access() throws Exception {
    86     public static void test_access() throws Exception {
    85         try {
    87         try {
    86             // Make a Class 'D_ambgs' under the default loader.
    88             // Make a Class 'D_ambgs' under the default loader.
    87             // This uses the implementation from the .java file.
    89             // This uses the implementation from the .java file.
    99             D_ambgs[] x2 = c_1.make(iface);
   101             D_ambgs[] x2 = c_1.make(iface);
   100 
   102 
   101             throw new RuntimeException("Expected LinkageError was not thrown.");
   103             throw new RuntimeException("Expected LinkageError was not thrown.");
   102         } catch (LinkageError jle) {
   104         } catch (LinkageError jle) {
   103             String errorMsg = jle.getMessage();
   105             String errorMsg = jle.getMessage();
   104             if (!errorMsg.equals(expectedErrorMessage)) {
   106             if (!errorMsg.contains(expectedErrorMessage_part1) ||
   105                 System.out.println("Expected: " + expectedErrorMessage + "\n" +
   107                 !errorMsg.contains(expectedErrorMessage_part2)) {
       
   108                 System.out.println("Expected: " + expectedErrorMessage_part1 + "<id>" + expectedErrorMessage_part2 + "\n" +
   106                                    "but got:  " + errorMsg);
   109                                    "but got:  " + errorMsg);
   107                 throw new RuntimeException("Wrong error message of LinkageError.");
   110                 throw new RuntimeException("Wrong error message of LinkageError.");
   108             } else {
   111             } else {
   109                 System.out.println("Passed with message: " + errorMsg);
   112                 System.out.println("Passed with message: " + errorMsg);
   110             }
   113             }