langtools/test/tools/javac/lambda/NestedCapture04.java
changeset 31296 9a8e44b62c77
equal deleted inserted replaced
31216:43d0179ee9de 31296:9a8e44b62c77
       
     1 /*
       
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 8076538
       
    27  * @summary Verify error at runtime due to incorrect classification of a lambda as being instance capturing
       
    28  * @run main NestedCapture04
       
    29  */
       
    30 public class NestedCapture04 {
       
    31 
       
    32     public static interface Ftype {
       
    33         int get(int v);
       
    34     }
       
    35 
       
    36     public static class A {
       
    37         static int counter = 0;
       
    38     }
       
    39     public static Ftype x0;
       
    40     public static void main(String[] args) throws Throwable {
       
    41         doit();
       
    42     }
       
    43     public static Object doit() throws Throwable {
       
    44         Ftype x0_ =
       
    45         (int y0) -> {
       
    46     A.counter++;
       
    47     Ftype x1 = (int y1) -> {
       
    48         A.counter++;
       
    49         class Cltype2 {
       
    50             Cltype2 meth(Cltype2 w) {
       
    51                 A.counter++;
       
    52                 class Cltype3 {
       
    53                     class Inclass3 {
       
    54                         public int iv;
       
    55                         Inclass3() { iv = 0; }
       
    56                         Inclass3 clmeth(Inclass3 a) {
       
    57                             A.counter++;
       
    58                             class Cltype4 {
       
    59                                 Cltype4 (Cltype4 z) {
       
    60                                     Ftype x5 = (int y5) -> {
       
    61                                         A.counter++;
       
    62                                         class Cltype6 {
       
    63                                             Cltype6 meth(Cltype6 w) {
       
    64                                                 A.counter++;
       
    65                                                 class Cltype7 {
       
    66                                                     class Inclass7 {
       
    67                                                         public int iv;
       
    68                                                         Inclass7() { iv = 0; }
       
    69                                                         Inclass7 clmeth(Inclass7 a) {
       
    70                                                             A.counter++;
       
    71                                                             class Cltype8 {
       
    72                                                                 Cltype8 (Cltype8 z) {
       
    73                                                                     Ftype x9 = (int y9) -> {
       
    74                                                                         A.counter++;
       
    75                                                                         return y9;
       
    76                                                                     };
       
    77                                                                     x9.get(2);
       
    78                                                                     if ( z == null) {
       
    79                                                                         A.counter++;
       
    80                                                                         return;
       
    81                                                                     }
       
    82                                                                     A.counter+=100;
       
    83                                                                 }
       
    84                                                             }
       
    85                                                             Cltype8 v = new Cltype8(null);
       
    86                                                             return a;
       
    87                                                         }
       
    88                                                     }
       
    89                                                 }
       
    90                                                 Cltype7.Inclass7 c = new Cltype7().new Inclass7();
       
    91                                                 c.clmeth((Cltype7.Inclass7)null);
       
    92                                                 return w;
       
    93                                             }
       
    94                                         }
       
    95                                         Cltype6 v = new Cltype6().meth(new Cltype6());
       
    96                                         return y5;
       
    97                                     };
       
    98                                     x5.get(2);
       
    99                                     if ( z == null) {
       
   100                                         A.counter++;
       
   101                                         return;
       
   102                                     }
       
   103                                     A.counter+=100;
       
   104                                 }
       
   105                             }
       
   106                             Cltype4 v = new Cltype4(null);
       
   107                             return a;
       
   108                         }
       
   109                     }
       
   110                 }
       
   111                 Cltype3.Inclass3 c = new Cltype3().new Inclass3();
       
   112                 c.clmeth((Cltype3.Inclass3)null);
       
   113                 return w;
       
   114             }
       
   115         }
       
   116         Cltype2 v = new Cltype2().meth(new Cltype2());
       
   117         return y1;
       
   118     };
       
   119     x1.get(2);
       
   120     return y0;
       
   121 };
       
   122         return x0 = x0_;
       
   123     }
       
   124 }