diff -r 000000000000 -r 959103a6100f test/tools/javac/lambda/BadAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/BadAccess.java Wed Apr 27 01:34:52 2016 +0800 @@ -0,0 +1,30 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8003280 + * @summary Add lambda tests + * check that non-static variables are not accessible from static lambdas + * @author Maurizio Cimadamore + * @compile/fail/ref=BadAccess.out -XDrawDiagnostics BadAccess.java + */ + +public class BadAccess { + + int i; + static int I; + + interface SAM { + int m(); + } + + static void test1() { + int l = 0; //effectively final + final int L = 0; + SAM s = ()-> i + I + l + L; + } + + void test2() { + int l = 0; //effectively final + final int L = 0; + SAM s = ()-> i + I + l + L; + } +}