[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

javac bug?




While coding at work I found this interesting problem w/ instance
initializers. Consider the following class:

import java.io.*;

class test {

    {
	if(true)
	    throw new FileNotFoundException();
    }
    
    test() throws IOException {}
}


this compiles under jikes but not javac:

[kerala] [patrice] javac test.java
test.java:7: Exception java.io.FileNotFoundException can't be thrown in
initializer.
	    throw new FileNotFoundException();
	    ^
1 error
[kerala] [patrice] jikes test.java
[kerala] [patrice]




Looking at the spec it seems javac is at fault:
http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#246032

but it still seems strange that javac should be broken...


cheers,
patrice