Bug 10898

Summary: DOM/AST: NullPointerException
Product: [Eclipse Project] JDT Reporter: Luc Bourlier <eclipse>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2    
Version: 2.0   
Target Milestone: 2.0 M4   
Hardware: PC   
OS: Windows NT   
Whiteboard:

Description Luc Bourlier CLA 2002-03-06 15:39:23 EST
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"
Comment 1 Olivier Thomann CLA 2002-03-07 11:16:40 EST
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.