Bug 129814

Summary: NPE due to CompilationUnit.getContents() returning null
Product: [Eclipse Project] JDT Reporter: Jess Garms <jgarms>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: frederic_fusier, jerome_lanneluc
Version: 3.1.2   
Target Milestone: 3.2 RC2   
Hardware: PC   
OS: Windows XP   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=562436
Whiteboard:

Description Jess Garms CLA 2006-02-28 12:58:35 EST
We ran into the following NPE from SourceTypeConverter calling CharOperation.subarray:

java.lang.NullPointerException
    at org.eclipse.jdt.core.compiler.CharOperation.subarray(CharOperation.java:2675)
    at org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convertAnnotations(SourceTypeConverter.java:562)
    at org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convert(SourceTypeConverter.java:432)
    at org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convert(SourceTypeConverter.java:150)
    at org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.buildCompilationUnit(SourceTypeConverter.java:89)
    at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.resolve(HierarchyResolver.java:511)
    at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.resolve(HierarchyResolver.java:486)
    at org.eclipse.jdt.internal.core.hierarchy.HierarchyBuilder.buildSupertypes(HierarchyBuilder.java:119)
    at org.eclipse.jdt.internal.core.hierarchy.IndexBasedHierarchyBuilder.build(IndexBasedHierarchyBuilder.java:134)
    at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.compute(TypeHierarchy.java:320)
    at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.refresh(TypeHierarchy.java:1255)
    at com.bea.wlw.netui.core.pageflow.model.PageFlowProject$2.run(PageFlowProject.java:281)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:76)

It seems to have been caused by the getSource() call returning null, which I believe can happen if the underlying file is deleted at just the wrong time. 

I'm afraid I don't have a repro for this -- it's only happened a couple times.

I attempted a fix by checking the results of getSource(), but Frederic reported the following via email: "SourceTypeConverter.getSource() should never return null. There's surely a real problem here and we must find the origin of it..."
Comment 1 Philipe Mulet CLA 2006-04-27 05:10:06 EDT
+1 for 3.2RC2
Comment 2 Jerome Lanneluc CLA 2006-04-27 05:13:51 EDT
Indeed the only path that can lead to null being returned is if the compilation unit's buffer is closed while getContents() runs.
Comment 3 Jerome Lanneluc CLA 2006-04-27 06:27:56 EDT
Added null check in CompilationUnit#getContents() in the case of #IBuffer#getCharacters() returning null. In this case, returns an empty char array.

Cannot add a test case since this is a timing issue.
Comment 4 Olivier Thomann CLA 2006-04-28 12:06:29 EDT
Verified with I20060427-1600 for 3.2RC2