Bug 41769 - getUnderlyingResource() for an element not in the build path
Summary: getUnderlyingResource() for an element not in the build path
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.0 M3   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-08-21 01:57 EDT by Luc Bourlier CLA
Modified: 2003-08-22 04:48 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luc Bourlier CLA 2003-08-21 01:57:23 EDT
I crossed a strange behavior when doing the work for breakpoint in external/not
in buildpath sources.

To set a line breakpoint, we need information about the type where the
breakpoint will be set. In one case, we use the working copy of the compilation
unit used in the editor to get the IType element which contains the line (see
ManageBreakpointRulerAction#addMarker() line 243 and following).
We also need to know which resource contains the type, so we usually use the
method BreakpointUtil#getBreakpointResource() to get the resource from a java
element.
But if the type is defined in a java file which is not in the build path, a
JavaModelException is thrown (see bug 41761 for a stack trace).

BreakpointUtil#getBreakpointResource() first get the real element if the given
is from a working copy, then call getUnderlyingResource() on this element.
It looks like getUnderlyingResource() returns null for an element contains in a
working copy, but I don't understand why it throws an exception when called on
the 'real' element, the resource exists.
Is it a bug or the normal behavior ?

A way to reproduce the problem is to replace line 256 in
ManageBreakpointRulerAction#addMarker()

resource= ((IFileEditorInput)editorInput).getFile();

by

resource= BreakpointUtils.getBreakpointResource(type);

then to try to add a breakpoint in a java file which is in the workbench but not
in a build path, by double-clicking in the ruler.
Comment 1 Jerome Lanneluc CLA 2003-08-21 09:04:43 EDT
This is the normal behavior as the compilation unit doesn't exist in the Java 
model sense (since it is not on the classpath).

You can use getResource() instead as this is a handle only operation (it 
doesn't check for existence).

Please let me know if it is ok to close this bug.
Comment 2 Luc Bourlier CLA 2003-08-21 17:52:55 EDT
getResource() works fine.
Thanks