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

Bug 323193

Summary: Use of IFile.getLocation() by CDebugUIUtils on remote links throws NullPointerException
Product: [Tools] CDT Reporter: Steve Mising name <shwilliams54321>
Component: cdt-debugAssignee: cdt-debug-inbox <cdt-debug-inbox>
Status: NEW --- QA Contact: Jonah Graham <jonah>
Severity: major    
Priority: P3 CC: daminggege, malaperle, pawel.1.piech
Version: 7.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

Description Steve Mising name CLA 2010-08-19 16:25:09 EDT
Build Identifier: 201006141710

CDT debugger throws NullPointerExceptions when sources are in linked folder which is linked to a remote system. CDT should not be calling IFile.getLocation(). If I make the following changes to CDT code, linked resources are no longer a problem.

CDebugUIUtils.getEditorFilePath():

  Change:

    if ( input instanceof IFileEditorInput ) {
      return ((IFileEditorInput)input).getFile().getLocation().toOSString();
    }

  To:

    if ( input instanceof IFileEditorInput ) {
      IFile file = ((IFileEditorInput)input).getFile();
      IPath path =       
         file.getProject().getLocation().append(file.getProjectRelativePath());
      return path.toOSString();
    }

CBreakpointManager.isSameBreakPoint():

  Change:

    Object sourceElement = getSourceElement( file );
    if ( sourceElement instanceof IFile ) {
      sourceHandle = ((IFile)sourceElement).getLocation().toOSString();
    }

  To:

    Object sourceElement = getSourceElement( file );
    if ( sourceElement instanceof IFile ) {
      IFile ifile = ((IFile)sourceElement);
      IPath path = 
        ifile.getProject().getLocation().append(ifile.getProjectRelativePath());
      sourceHandle = path.toOSString();
    }


DisassemblyBlock.createSourceLines():

  Change:

    if ( element instanceof IFile ) {
      file = ((IFile)element).getLocation().toFile();
    }

  To:

    if ( element instanceof IFile ) {
      IFile ifile = ((IFile)element);
      IPath path = 
        ifile.getProject().getLocation().append(ifile.getProjectRelativePath());
      file = path.toFile();
    }


DisassemblyBackEndCdi.insertDisassembly():

  Change:

    else if (srcElement instanceof IFile) {
      compilationPath = ((IFile)srcElement).getLocation().toString();
    }

  To:

    else if (srcElement instanceof IFile) {
      IFile ifile = ((IFile)srcElement);
      IPath path = 
        ifile.getProject().getLocation().append(ifile.getProjectRelativePath());
      compilationPath = path.toString
    }


Reproducible: Always

Steps to Reproduce:
I've implemented a remote file system using EFS. I'm not sure how to set up a simple example. I've seen that there's been an effort to support EFS in CDT (e.g., error parser handling of URIs). The fix is very straightforward, however, since it simply involves replacing calls to IFile.getLocation() to a link-friendly way of returning absolute paths. The underlying problem is that getLocation() calls:

  FileSystemResourceManager.locationFor(IResource)

which in turn calls this method:

  FileStoreRoot.localLocation(IPath, IResource)

FileStoreRoot will always return null for a linked resource as noted in a comment in its source file:

  /**
   * If this root represents a resource in the local file system, this path
   * represents the root location.  This value is null if the root represents
   * a non-local file system
   */
  private IPath localRoot = null;
    .
    .
    .
  IPath localLocation(IPath workspacePath, IResource resource) {
    if (localRoot == null)
      return null;
Comment 1 Marc-André Laperle CLA 2010-08-29 14:03:21 EDT
Hi Steve. Maybe this would get more attention if you attached a patch?
http://wiki.eclipse.org/CDT/contributing
Comment 2 Steve Mising name CLA 2010-08-30 16:01:09 EDT
(In reply to comment #1)
> Hi Steve. Maybe this would get more attention if you attached a patch?
> http://wiki.eclipse.org/CDT/contributing

Thanks for the tip. I'll look into it.
Comment 3 daming CLA 2012-07-05 03:38:40 EDT
Hi Steve and Marc,
How about the patch? I think it is greatly helpful, and should be included into the mainstream.
I have verified in my local environment (ecilpse 3.7 + cdt 8.02), and I can add breakpoint onto EFS file correctly as what I have done in JDT.

Regards,
Zhiming