Bug 129814 - NPE due to CompilationUnit.getContents() returning null
Summary: NPE due to CompilationUnit.getContents() returning null
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 RC2   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-28 12:58 EST by Jess Garms CLA
Modified: 2020-05-06 08:41 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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