test/tools/javac/foreach/ListOfListTest.java

Print this page




   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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4915435
  27  * @summary NullPointerError in Resolve.findMethod() with foreach vs generics
  28  * @author gafter
  29  *
  30  * @compile -source 1.5 ListOfListTest.java
  31  * @run main ListOfListTest
  32  */
  33 
  34 import java.util.List;
  35 import java.util.ArrayList;
  36 
  37 public class ListOfListTest {
  38 
  39     public static void main(String[] argv) {
  40         List<List<Integer>> ll = new ArrayList<List<Integer>>();
  41         List<Integer> il = new ArrayList<Integer>();
  42         ll.add(il);
  43         il.add(1);
  44         int sum = 0;
  45         for (Integer i : ll.get(0)) {
  46             sum = identity(sum) + i;
  47         }
  48 
  49         if (sum != 1) throw new Error(""+sum);
  50 
  51         enumsToo();




   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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4915435
  27  * @summary NullPointerError in Resolve.findMethod() with foreach vs generics
  28  * @author gafter



  29  */
  30 
  31 import java.util.List;
  32 import java.util.ArrayList;
  33 
  34 public class ListOfListTest {
  35 
  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         }
  45 
  46         if (sum != 1) throw new Error(""+sum);
  47 
  48         enumsToo();