< prev index next >

test/jdk/java/lang/StackWalker/VerifyStackTrace.java

Print this page




 114         @Override public String expected()    { return expected;}
 115     }
 116     static class TestCase3 implements TestCase {
 117         private final StackWalker walker = StackWalker.getInstance(
 118                 EnumSet.of(RETAIN_CLASS_REFERENCE, SHOW_HIDDEN_FRAMES));
 119 
 120         private final String description = "StackWalker.getInstance(" +
 121             "StackWalker.Option.RETAIN_CLASS_REFERENCE, " +
 122             "StackWalker.Option.SHOW_HIDDEN_FRAMES)";
 123 
 124         // Note: line numbers and lambda hashes will be erased when
 125         //       comparing stack traces. However, the stack may change
 126         //       if some methods are being renamed in the code base.
 127         // If the JDK code base changes and the test fails because of that,
 128         // then after validating that the actual stack trace obtained
 129         // is indeed correct (no frames are skipped that shouldn't)
 130         // then you can cut & paste the <-- actual --> stack printed in the
 131         // test output in here (don't forget the final \n):
 132         private final String expected =
 133             "1: VerifyStackTrace.lambda$test$1(VerifyStackTrace.java:213)\n" +
 134             "2: VerifyStackTrace$$Lambda$1/0x00000007c0089430.run(Unknown Source)\n" +
 135             "3: VerifyStackTrace$Handle.execute(VerifyStackTrace.java:149)\n" +
 136             "4: java.base/java.lang.invoke.LambdaForm$DMH/0x00000007c008a830.invokeVirtual_LL_V(LambdaForm$DMH)\n" +
 137             "5: java.base/java.lang.invoke.LambdaForm$MH/0x00000007c008a830.invoke_MT(LambdaForm$MH)\n" +
 138             "6: VerifyStackTrace$Handle.run(VerifyStackTrace.java:162)\n" +
 139             "7: VerifyStackTrace.invoke(VerifyStackTrace.java:192)\n" +
 140             "8: java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" +
 141             "9: java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n" +
 142             "10: java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n" +
 143             "11: java.base/java.lang.reflect.Method.invoke(Method.java:520)\n" +
 144             "12: VerifyStackTrace$1.run(VerifyStackTrace.java:222)\n" +
 145             "13: java.base/java.security.AccessController.executePrivileged(AccessController.java:759)\n" +
 146             "14: java.base/java.security.AccessController.doPrivileged(AccessController.java:310)\n" +
 147             "15: VerifyStackTrace.test(VerifyStackTrace.java:231)\n" +
 148             "16: VerifyStackTrace.main(VerifyStackTrace.java:188)\n";
 149 
 150         @Override public StackWalker walker() { return walker;}
 151         @Override public String description() { return description;}
 152         @Override public String expected()    { return expected;}
 153     }
 154 
 155     static final class TestCase4 extends TestCase3 {
 156         private final StackWalker walker = StackWalker.getInstance(
 157                 EnumSet.allOf(StackWalker.Option.class));


 185             } catch(NoSuchMethodException | IllegalAccessException x) {
 186                 throw new RuntimeException(x);
 187             }
 188             try {
 189                 handle.invoke(this, impl);
 190             } catch(Error | RuntimeException x) {
 191                 throw x;
 192             } catch(Throwable t) {
 193                 throw new RuntimeException(t);
 194             }
 195         }
 196     }
 197 
 198     static String prepare(String produced, boolean eraseSensitiveInfo) {
 199         if (eraseSensitiveInfo) {
 200             // Erase sensitive information before comparing:
 201             // comparing line numbers is too fragile, so we just erase them
 202             // out before comparing. We also erase the hash-like names of
 203             // synthetic frames introduced by lambdas & method handles
 204             return produced.replaceAll(":[1-9][0-9]*\\)", ":00)")
 205                     .replaceAll("/0x[0-9a-f]+\\.run", "/xxxxxxxx.run")
 206                     .replaceAll("/0x[0-9a-f]+\\.invoke", "/xxxxxxxx.invoke")
 207                     // LFs may or may not be pre-generated, making frames differ
 208                     .replaceAll("DirectMethodHandle\\$Holder", "LambdaForm\\$DMH")
 209                     .replaceAll("Invokers\\$Holder", "LambdaForm\\$MH")
 210                     .replaceAll("MH\\.invoke", "MH/xxxxxxxx.invoke")
 211                     // invoke frames may or may not have basic method type
 212                     // information encoded for diagnostic purposes
 213                     .replaceAll("xx\\.invoke([A-Za-z]*)_[A-Z_]+", "xx.invoke$1")
 214                     .replaceAll("\\$[0-9]+", "\\$??");
 215         } else {
 216             return produced;
 217         }
 218     }
 219 
 220 
 221     public static void main(String[] args) {
 222         test(new TestCase1());
 223         test(new TestCase2());
 224         test(new TestCase3());
 225         test(new TestCase4());
 226     }




 114         @Override public String expected()    { return expected;}
 115     }
 116     static class TestCase3 implements TestCase {
 117         private final StackWalker walker = StackWalker.getInstance(
 118                 EnumSet.of(RETAIN_CLASS_REFERENCE, SHOW_HIDDEN_FRAMES));
 119 
 120         private final String description = "StackWalker.getInstance(" +
 121             "StackWalker.Option.RETAIN_CLASS_REFERENCE, " +
 122             "StackWalker.Option.SHOW_HIDDEN_FRAMES)";
 123 
 124         // Note: line numbers and lambda hashes will be erased when
 125         //       comparing stack traces. However, the stack may change
 126         //       if some methods are being renamed in the code base.
 127         // If the JDK code base changes and the test fails because of that,
 128         // then after validating that the actual stack trace obtained
 129         // is indeed correct (no frames are skipped that shouldn't)
 130         // then you can cut & paste the <-- actual --> stack printed in the
 131         // test output in here (don't forget the final \n):
 132         private final String expected =
 133             "1: VerifyStackTrace.lambda$test$1(VerifyStackTrace.java:213)\n" +
 134             "2: VerifyStackTrace$$Lambda$1\\10.run(Unknown Source)\n" +
 135             "3: VerifyStackTrace$Handle.execute(VerifyStackTrace.java:149)\n" +
 136             "4: java.base/java.lang.invoke.LambdaForm$DMH\\11.invokeVirtual_LL_V(LambdaForm$DMH)\n" +
 137             "5: java.base/java.lang.invoke.LambdaForm$MH\\12.invoke_MT(LambdaForm$MH)\n" +
 138             "6: VerifyStackTrace$Handle.run(VerifyStackTrace.java:162)\n" +
 139             "7: VerifyStackTrace.invoke(VerifyStackTrace.java:192)\n" +
 140             "8: java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" +
 141             "9: java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n" +
 142             "10: java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n" +
 143             "11: java.base/java.lang.reflect.Method.invoke(Method.java:520)\n" +
 144             "12: VerifyStackTrace$1.run(VerifyStackTrace.java:222)\n" +
 145             "13: java.base/java.security.AccessController.executePrivileged(AccessController.java:759)\n" +
 146             "14: java.base/java.security.AccessController.doPrivileged(AccessController.java:310)\n" +
 147             "15: VerifyStackTrace.test(VerifyStackTrace.java:231)\n" +
 148             "16: VerifyStackTrace.main(VerifyStackTrace.java:188)\n";
 149 
 150         @Override public StackWalker walker() { return walker;}
 151         @Override public String description() { return description;}
 152         @Override public String expected()    { return expected;}
 153     }
 154 
 155     static final class TestCase4 extends TestCase3 {
 156         private final StackWalker walker = StackWalker.getInstance(
 157                 EnumSet.allOf(StackWalker.Option.class));


 185             } catch(NoSuchMethodException | IllegalAccessException x) {
 186                 throw new RuntimeException(x);
 187             }
 188             try {
 189                 handle.invoke(this, impl);
 190             } catch(Error | RuntimeException x) {
 191                 throw x;
 192             } catch(Throwable t) {
 193                 throw new RuntimeException(t);
 194             }
 195         }
 196     }
 197 
 198     static String prepare(String produced, boolean eraseSensitiveInfo) {
 199         if (eraseSensitiveInfo) {
 200             // Erase sensitive information before comparing:
 201             // comparing line numbers is too fragile, so we just erase them
 202             // out before comparing. We also erase the hash-like names of
 203             // synthetic frames introduced by lambdas & method handles
 204             return produced.replaceAll(":[1-9][0-9]*\\)", ":00)")
 205                     .replaceAll("\\\\[0-9]+\\.run", "/xxxxxxxx.run")
 206                     .replaceAll("\\\\[0-9]+\\.invoke", "/xxxxxxxx.invoke")
 207                     // LFs may or may not be pre-generated, making frames differ
 208                     .replaceAll("DirectMethodHandle\\$Holder", "LambdaForm\\$DMH")
 209                     .replaceAll("Invokers\\$Holder", "LambdaForm\\$MH")
 210                     .replaceAll("MH\\.invoke", "MH/xxxxxxxx.invoke")
 211                     // invoke frames may or may not have basic method type
 212                     // information encoded for diagnostic purposes
 213                     .replaceAll("xx\\.invoke([A-Za-z]*)_[A-Z_]+", "xx.invoke$1")
 214                     .replaceAll("\\$[0-9]+", "\\$??");
 215         } else {
 216             return produced;
 217         }
 218     }
 219 
 220 
 221     public static void main(String[] args) {
 222         test(new TestCase1());
 223         test(new TestCase2());
 224         test(new TestCase3());
 225         test(new TestCase4());
 226     }


< prev index next >