Sunday, June 29, 2008

NullPointerException at Javac compiler


Got an NPE when compiling from the compiler. Its very annoying since its the compiler bug and very hard to get to the class that freaked it out (no appropriate message). The error is:

java.lang.NullPointerException
at com.sun.tools.javac.code.Types$IsSameTypeFcn.visitClassType
at com.sun.tools.javac.code.Type$ClassType.accept
at com.sun.tools.javac.code.Types$IsSameTypeFcn.isSameType
at com.sun.tools.javac.code.Types$IsSameTypeFcn.visitClassType
at com.sun.tools.javac.code.Type$ClassType.accept
.....

The line that promped the javac error is:
List<LinkedList<DateScoreSortable<BaseNewsArticleView>>> lists = getMyLists(...);

I know it look strange, but that's what I needed. Actually I had this code in a test class, but I do use this funky structure in the business logic. Anyway it seems to trigger an edge case in the Sun compiler. The Eclipse JDT incremental Java compiler did not have any problems with the code, it compiled and run it without problems.
I really don't have time now to submit the bug and full sample, maybe later.
By the way it happened on my Mac java version "1.5.0_13". To solved the problem I used the same data sutucture but without the generics, i.e.:
List lists = getMyLists(...);

It worked!

0 comments:

Creative Commons License This work by Eishay Smith is licensed under a Creative Commons Attribution 3.0 Unported License.