Bug 80960

Summary: [dom] NPE in ASTConverter#convert(...)
Product: [Eclipse Project] JDT Reporter: Jerome Lanneluc <jerome_lanneluc>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Jerome Lanneluc CLA 2004-12-14 13:03:19 EST
I20041214-0800

The following CU causes a NPE in ASTConverter#convert
import java.util.*;
public class X {
  public enum Rank { DEUCE, THREE, FOUR, FIVE, SIX,
    SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE }

  //public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }
  public enum Suit{

  private X(int rank, int suit) {  
  }
  
  private static final List<X> protoDeck = new ArrayList<X>();
  
  public static ArrayList<X> newDeck() {
      return new ArrayList<X>(protoDeck); // Return copy of prototype deck
  }
}

The stack trace is:
java.lang.NullPointerException
        at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1314)
        at
org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:238)
        at
org.eclipse.jdt.core.dom.ASTConverter.convertToEnumDeclaration(ASTConverter.java:2607)
        at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2356)
        at
org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:180)
        at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2419)
        at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1159)
        at
org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:220)
        at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:729)
        at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:574)
        at
org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST(ASTProvider.java:563)
        at
org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:494)
        at
org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover.getHoverInfo(NLSStringHover.java:84)
        at
org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo(BestMatchHover.java:102)
        at
org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo(JavaEditorTextHoverProxy.java:69)
        at
org.eclipse.jface.text.TextViewerHoverManager$4.run(TextViewerHoverManager.java:160)
Comment 1 Olivier Thomann CLA 2004-12-14 13:27:50 EST
Fix is trivial.
Missing a null check.
Comment 2 Olivier Thomann CLA 2004-12-14 13:45:06 EST
Adding null check.
Fixed and released in HEAD.
Added test092 in ASTConverter15Test.
I will open a new PR for improving the error recovery in this case.
Comment 3 Olivier Thomann CLA 2004-12-14 13:50:06 EST
See bug 80970.
Comment 4 Olivier Thomann CLA 2004-12-14 23:33:18 EST
Verified in 200412141600