JSR014 prototype and AssertionError

W

Wolfgang Jeltsch

Hello,

take the following file Bug.java:
import java.util.*;

public final class Bug<Item> {
public Bug(Collection<Item> items) {
for (Item item : items) {}
}
}
When compiling this with the JSR014 prototype version 2.2, the compiler
crashes with the following exception:

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)

I have created a hack which circumvents this problem by replacing all
occurences of foreach with iterator-based code. In order to use it, your
code must conform to the Java Code Conventions and there must not be any
spaces between the angle brackets (< and >) of generic parameters. No
compiler options are supported. There may be further limitations.

The code is a UNIX shell script so you need Cygwin or whatever under
Windows.

Put the following code in a file named javac and modify the string
<path-to-prototype> properly. Then give the file execution rights and
adjust your PATH variable in a way that this script is found instead of the
normal javac when entering javac on the command line.
#!/bin/sh

mv $1 $1.actual
sed -e 's/for .\([^ ]*\) \([_a-zA-Z]*\) : \(.*\). {/Iterator<\1>
_iterator = (\3).iterator(); while (_iterator.hasNext()) { final \1 \2 =
_iterator.next();/' < $1.actual > $1
/<path-to-prototype>/adding_generics-2_2-ea/scripts/javac $1
mv $1.actual $1
The 4th to 6th line are actually one line that only got splitted by my news
program.

Merry Christmas.

Wolfgang
 
W

Wolfgang Jeltsch

I said:
#!/bin/sh

mv $1 $1.actual
sed -e 's/for .\([^ ]*\) \([_a-zA-Z]*\) : \(.*\). {/Iterator<\1>
_iterator = (\3).iterator(); while (_iterator.hasNext()) { final \1 \2 =
_iterator.next();/' < $1.actual > $1
/<path-to-prototype>/adding_generics-2_2-ea/scripts/javac $1
mv $1.actual $1
The 4th to 6th line are actually one line that only got splitted by my
news program.

I've just fixed a bug and improved the code a bit. In addition, I now call
the actual javac with -warnunchecked. Here's the new code:
#!/bin/sh

mv $1 $1.actual
sed -e 's/for .\([^ ]*\) \([_0-9a-zA-Z]*\) : \(.*\). {/for (final
Iterator<\1> iterator_\2 = (\3).iterator(); iterator_\2.hasNext(); ) {
final \1 \2 = iterator_\2.next();/' < $1.actual > $1
/<path-to-prototype>/adding_generics-2_2-ea/scripts/javac -warnunchecked
$1
mv $1.actual $1
Lines beginning at the left edge are actually continuations of the
respective previous lines.

Merry Christmas.

Wolfgang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top