test/tools/javac/foreach/ListOfListTest.java

Thu, 21 Feb 2013 15:26:46 +0000

author
mcimadamore
date
Thu, 21 Feb 2013 15:26:46 +0000
changeset 1599
9f0ec00514b6
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8007461: Regression: bad overload resolution when inner class and outer class have method with same name
Summary: Fix regression in varargs method resolution introduced by bad refactoring
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 2003, 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  */
    24 /*
    25  * @test
    26  * @bug 4915435
    27  * @summary NullPointerError in Resolve.findMethod() with foreach vs generics
    28  * @author gafter
    29  */
    31 import java.util.List;
    32 import java.util.ArrayList;
    34 public class ListOfListTest {
    36     public static void main(String[] argv) {
    37         List<List<Integer>> ll = new ArrayList<List<Integer>>();
    38         List<Integer> il = new ArrayList<Integer>();
    39         ll.add(il);
    40         il.add(1);
    41         int sum = 0;
    42         for (Integer i : ll.get(0)) {
    43             sum = identity(sum) + i;
    44         }
    46         if (sum != 1) throw new Error(""+sum);
    48         enumsToo();
    49     }
    51     static int identity(Integer i) {
    52         switch (i) {
    53         case 0: return 0;
    54         default: return i;
    55         }
    56     }
    58     enum E { a, b, c, d, e };
    60     static class Box<T> {
    61         Box(T t) { this.t = t; }
    62         T t;
    63         T get() { return t; }
    64     }
    66     static void enumsToo() {
    67         Box<E> box = new Box<E>(E.c);
    68         switch (box.get()) {
    69         case a: throw new Error();
    70         case c: break;
    71         default: throw new Error();
    72         }
    73         Box<Integer> boxi = new Box<Integer>(12);
    74         switch (boxi.get()) {
    75         case 0: throw new Error();
    76         case 12: break;
    77         default: throw new Error();
    78         }
    79     }
    80 }

mercurial