/*
 * Copyright (c) 2015, 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
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * @test
 * @bug 8129740 8133111 8157142
 * @summary Incorrect class file created when passing lambda in inner class constructor
 * @run main AllowEnclosingVarCaptureTest
 */

public class AllowEnclosingVarCaptureTest {

    int var = 0;

    void foo() {
        var *= 2;
    }

    public static void main(String[] args) {
        new AllowEnclosingVarCaptureTest().new Inner(9764);
    }

    public class Inner {
        public Inner(Runnable r) {
            r.run();
            if (var != 66704)
                throw new AssertionError("Unexpected output: " + var);
        }

        public Inner(int x) {
            this(() -> {
                var = x + 1234;
                AllowEnclosingVarCaptureTest.this.var += 5678;
                foo();
                AllowEnclosingVarCaptureTest.this.foo();
            });
        }
    }
}
