Community
Participate
Working Groups
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.
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.
getResource() works fine. Thanks