JDK-4937353 : assertion fails: xClassName; generics+foreach
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.2_01
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-10-14
  • Updated: 2003-10-14
  • Resolved: 2003-10-14
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 10/14/2003


FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
I am having a simple generic class wrapping a generic vector, see below.
The compiler crashes with an 'assertion failed' when writing code. If I replace the foreach loop with a semantically equivalent while loop and an iterator, it works fine.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
export J2SE14=c:/Programme/java/j2sdk1.4.2_01
export JSR14DISTR=c:/Programme/java/adding_generics-2_2-ea
$JSR14DISTR/scripts/javac Test.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
compiled class file
ACTUAL -
compiler assertion fails

ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (1.4.2_01). Please file a bug at the Java Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.

java.lang.AssertionError: xClassName

	at com.sun.tools.javac.jvm.ClassWriter.xClassName(ClassWriter.java:384)

	at com.sun.tools.javac.jvm.ClassWriter.writePool(ClassWriter.java:473)

	at com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1002)

	at com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:883)

	at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:316)

	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:455)

	at com.sun.tools.javac.main.Main.compile(Main.java:520)

	at com.sun.tools.javac.Main.compile(Main.java:41)

	at com.sun.tools.javac.Main.main(Main.java:32)



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.Vector;

public class Test<Base> {
  private Vector<Base> columnsByIndex = new Vector<Base>();

  public void print() {
    // this loop will crash with a compiler error
    for(Base base : columnsByIndex) {
      //...
    }

    /**
    // this loop - which does the same thing - works
    java.util.Iterator<Base> bases = columnsByIndex.iterator();
    while (bases.hasNext()) {
      Base base = bases.next();
      // ...
    }
    */

  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
use the while loop
(Incident Review ID: 215657) 
======================================================================

Comments
PUBLIC COMMENTS ...
10-06-2004