langtools/test/tools/javac/lambda/LambdaLocalTest.java
author rfield
Wed, 30 Apr 2014 23:02:14 -0700
changeset 24225 44f3a7b2ac71
permissions -rw-r--r--
8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables 8029725: Lambda reference to containing local class causes javac infinite recursion Reviewed-by: vromero, jlahoda, dlsmith
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24225
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
     1
/*
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
     4
 *
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
     7
 * published by the Free Software Foundation.
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
     8
 *
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    13
 * accompanied this code).
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    14
 *
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    18
 *
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    21
 * questions.
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    22
 */
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    23
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    24
/*
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    25
 * @test
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    26
 * @bug 8029725
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    27
 * @summary Lambda reference to containing local class causes javac infinite recursion
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    28
 * @author  Robert Field
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    29
 * @run main LambdaLocalTest
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    30
 */
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    31
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    32
public class LambdaLocalTest {
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    33
    interface F {void f();}
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    34
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    35
    static F f;
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    36
    static StringBuffer sb = new StringBuffer();
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    37
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    38
    static void assertEquals(Object val, Object expected) {
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    39
        if (!val.equals(expected)) {
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    40
            throw new AssertionError("expected '" + expected + "' got '" + val + "'");
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    41
        }
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    42
    }
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    43
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    44
    public static void main(String[] args) {
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    45
        class Local {
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    46
            public Local() {
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    47
                f = () -> new Local();
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    48
                sb.append("+");
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    49
            }
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    50
        }
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    51
        new Local();
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    52
        f.f();
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    53
        assertEquals(sb.toString(), "++");
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    54
    }
44f3a7b2ac71 8029852: Bad code generated (VerifyError) when lambda instantiates enclosing local class and has captured variables
rfield
parents:
diff changeset
    55
}