jdk/test/java/lang/StackWalker/GetCallerClassTest.java
changeset 38784 c0a88deb692a
parent 37526 dc4669f222ab
child 44262 bfbb47bd118d
--- a/jdk/test/java/lang/StackWalker/GetCallerClassTest.java	Fri Jun 03 16:31:13 2016 -0700
+++ b/jdk/test/java/lang/StackWalker/GetCallerClassTest.java	Fri Jun 03 17:01:23 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8140450
+ * @bug 8140450 8152893
  * @summary Basic test for StackWalker.getCallerClass()
  * @run main/othervm GetCallerClassTest
  * @run main/othervm GetCallerClassTest sm
@@ -41,6 +41,7 @@
 import java.security.Policy;
 import java.security.ProtectionDomain;
 import java.util.Arrays;
+import java.util.EnumSet;
 import java.util.List;
 
 public class GetCallerClassTest {
@@ -65,16 +66,20 @@
         }
         new GetCallerClassTest(StackWalker.getInstance(), true).test();
         new GetCallerClassTest(StackWalker.getInstance(RETAIN_CLASS_REFERENCE), false).test();
+        new GetCallerClassTest(StackWalker.getInstance(EnumSet.of(RETAIN_CLASS_REFERENCE,
+                                                                  SHOW_HIDDEN_FRAMES)), false).test();
     }
 
     public void test() {
         new TopLevelCaller().run();
+        new LambdaTest().run();
         new Nested().createNestedCaller().run();
         new InnerClassCaller().run();
         new ReflectionTest().run();
 
         List<Thread> threads = Arrays.asList(
                 new Thread(new TopLevelCaller()),
+                new Thread(new LambdaTest()),
                 new Thread(new Nested().createNestedCaller()),
                 new Thread(new InnerClassCaller()),
                 new Thread(new ReflectionTest())
@@ -149,7 +154,7 @@
 
     public static void assertEquals(Class<?> c, Class<?> expected) {
         if (expected != c) {
-            throw new RuntimeException(c + " != " + expected);
+            throw new RuntimeException("Got " + c + ", but expected " + expected);
         }
     }
 
@@ -172,6 +177,28 @@
         }
     }
 
+    class LambdaTest implements Runnable {
+        public void run() {
+            Runnable lambdaRunnable = () -> {
+                try {
+                    Class<?> c = walker.getCallerClass();
+
+                    assertEquals(c, LambdaTest.class);
+                    if (expectUOE) { // Should have thrown
+                        throw new RuntimeException("Didn't get expected exception");
+                    }
+                } catch (Throwable e) {
+                    if (expectUOE && causeIsUOE(e)) {
+                        return; /* expected */
+                    }
+                    System.err.println("Unexpected exception:");
+                    throw new RuntimeException(e);
+                }
+            };
+            lambdaRunnable.run();
+        }
+    }
+
     class Nested {
         NestedClassCaller createNestedCaller() { return new NestedClassCaller(); }
         class NestedClassCaller implements Runnable {