participate


Generics - foreach loop in static block won't compile
<<   Back to Forum  |   Give us Feedback
This topic has 1 reply on 1 page.
uncle_alice
Posts:3,817
Registered: 9/26/00
foreach loop in static block won't compile   
Jun 3, 2003 10:26 AM

 
When I try to compile this:
public class TestEnum
{
  private static String[] numerals =
      {"einz", "zwei", "drei", "vier"};
 
  static
  {
    for (String n : numerals)
    {
      // doesn't matter what's in here
    }
  }
 
  public static void main(String[] args)
  {
  }
}
I get this exception:
An exception has occurred in the compiler (1.4.2-beta).
java.lang.NullPointerException
    at com.sun.tools.javac.comp.Lower.visitArrayForeachLoop(Lower.java:2269)
    at com.sun.tools.javac.comp.Lower.visitForeachLoop(Lower.java:2242)
    at com.sun.tools.javac.tree.Tree$ForeachLoop.accept(Tree.java:559)
    at com.sun.tools.javac.comp.Lower.translate(Lower.java:1580)
    at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:51)
    at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:131)
    at com.sun.tools.javac.tree.Tree$Block.accept(Tree.java:497)
    at com.sun.tools.javac.comp.Lower.translate(Lower.java:1580)
    at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:1645)
    at com.sun.tools.javac.tree.Tree$ClassDef.accept(Tree.java:409)
    at com.sun.tools.javac.comp.Lower.translate(Lower.java:1580)
    at com.sun.tools.javac.comp.Lower.translate(Lower.java:1594)
    at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:2438)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:408)
    at com.sun.tools.javac.main.Main.compile(Main.java:523)
    at com.sun.tools.javac.Main.compile(Main.java:41)
    at com.sun.tools.javac.Main.main(Main.java:32)
The same thing happens if I use foreach with a Collection instead an array. If I use an old-style for loop or Iterator in the static block, it compiles fine. I can also put the foreach loop in the main method, and it works. Is this a known bug?
 
gafter
Posts:669
Registered: 6/25/98
Re: foreach loop in static block won't compile   
Jun 5, 2003 8:29 PM (reply 1 of 1)  (In reply to original post )

 
You guys rock. Thanks for finding this problem. I'll get it fixed.
 
This topic has 1 reply on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 26
  • Guests : 129

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums