Community
Participate
Working Groups
The following code generates a NullPointerException. It seems to be because the method has no return type. public class Test { public static void main(String[] args) { String source = "public class Foo { bar() {}}"; CompilationUnit unit = AST.parseCompilationUnit(source.toCharArray()); } } java.lang.NullPointerException at org.eclipse.jdt.core.dom.ASTConverter.convertType(ASTConverter.java:457) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:545) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:163) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:70) at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:310) at Test.main(Test.java:17) Exception in thread "main"
The return type of the method declaration is null and I am trying to convert a null type. This led to a NPE. Now I ignore the conversion of the return type if it is null. This means that the return type of the method will be void if you asked for it. If you asked for binding, then you will get an error reported in the compilation unit's messages collection. The message is "Return type for the method is missing". I think this is perfectly acceptable. Fixed and released in HEAD.