Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 314303

Summary: [source lookup] Risk of NPE in Source lookup service
Product: [Tools] CDT Reporter: Marc Khouzam <marc.khouzam>
Component: cdt-debug-dsf-gdbAssignee: Marc Khouzam <marc.khouzam>
Status: RESOLVED FIXED QA Contact: Marc Khouzam <marc.khouzam>
Severity: normal    
Priority: P3 CC: john.cortell, pawel.1.piech
Version: 7.0Flags: marc.khouzam: review+
Target Milestone: 7.0   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Guard against NPE marc.khouzam: iplog-

Description Marc Khouzam CLA 2010-05-25 12:11:37 EDT
Created attachment 169850 [details]
Guard against NPE

I got a report from a user of an NPE.  I don't know the details of his setup so I'm not sure how to reproduce it, but I figure we should guard against it.

java.lang.NullPointerException
        at org.eclipse.cdt.dsf.mi.service.CSourceLookup.getSourceLookupPath(CSourceLookup.java:91)
        at org.eclipse.cdt.dsf.mi.service.CSourceLookup.getSourceLookupPath(CSourceLookup.java:102)
        at org.eclipse.cdt.dsf.mi.service.CSourceLookup.getSourceLookupPath(CSourceLookup.java:102)
        at org.eclipse.cdt.dsf.mi.service.CSourceLookup.setSourceLookupPath(CSourceLookup.java:71)
        at org.eclipse.cdt.dsf.gdb.launching.FinalLaunchSequence$13.execute(FinalLaunchSequence.java:324)
        at org.eclipse.cdt.dsf.concurrent.Sequence.executeStep(Sequence.java:443)
        at org.eclipse.cdt.dsf.concurrent.Sequence.access$2(Sequence.java:366)
        at org.eclipse.cdt.dsf.concurrent.Sequence$2.handleSuccess(Sequence.java:413)
        at org.eclipse.cdt.dsf.concurrent.RequestMonitor.handleCompleted(RequestMonitor.java:346)
        at org.eclipse.cdt.dsf.concurrent.RequestMonitor$2.run(RequestMonitor.java:291)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Comment 1 Marc Khouzam CLA 2010-05-25 12:12:24 EDT
Pawel, can you review?  I'll wait for your review to commit because we are so late in the release cycle.
Comment 2 Marc Khouzam CLA 2010-05-25 12:13:05 EDT
All this could go away if we fixed Bug 225805.  I'll target that one for 8.0
Comment 3 John Cortell CLA 2010-05-25 12:15:59 EDT
The guard should be accompanied by an assert until we know that there isn't a deeper issue at hand.
Comment 4 Pawel Piech CLA 2010-05-25 12:23:13 EDT
+1, use of IResource.getLocation() has changed when the resource system was refactored to support URIs.
Comment 5 Marc Khouzam CLA 2010-05-25 13:17:42 EDT
(In reply to comment #4)
> +1, use of IResource.getLocation() has changed when the resource system was
> refactored to support URIs.

Committed to HEAD.
Thanks

(In reply to comment #3)
> The guard should be accompanied by an assert until we know that there isn't a
> deeper issue at hand.

John, now that there is somewhat of an explanation for this happening, do you still want the assert?
Comment 6 Marc Khouzam CLA 2010-05-25 13:18:03 EDT
Fixed
Comment 7 John Cortell CLA 2010-05-25 14:16:31 EDT
(In reply to comment #5)
> John, now that there is somewhat of an explanation for this happening, do you
> still want the assert?

I'm not really getting the explanation, but if you feel there is one, then there's no need for an assert.
Comment 8 Marc Khouzam CLA 2010-05-25 15:08:13 EDT
(In reply to comment #4)
> +1, use of IResource.getLocation() has changed when the resource system was
> refactored to support URIs.

Looking at the history of IResource.getLocation(), the javadoc refers to getLocationURI() all the way back to the 3.5 release.

So, I'm also confused about if this NPE is expected or not?  Pawel, do you have more details?
Comment 9 Pawel Piech CLA 2010-05-25 15:30:30 EDT
(In reply to comment #8)
> So, I'm also confused about if this NPE is expected or not?  Pawel, do you have
> more details?

IResource.getLocation() can return null if the resource doesn't actually exist or if it's a remote resource.  If the resource doesn't exist, I think we can blissfully ignore the NPE, in case of non-local resources I'm not sure what the valid action should be... it's not a use case we've discussed :-)
Comment 10 CDT Genie CLA 2010-07-28 15:29:37 EDT
*** cdt cvs genie on behalf of mkhouzam ***
Bug 314303: Protect against NPE.

[*] CSourceLookup.java 1.3 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/CSourceLookup.java?root=Tools_Project&r1=1.2&r2=1.3