Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354042 - Problem with include paths that are relative paths starting with ../ or./ and NPE
Summary: Problem with include paths that are relative paths starting with ../ or./ an...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build (show other bugs)
Version: 7.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 7.0.3   Edit
Assignee: Andrew Gvozdev CLA
QA Contact: Andrew Gvozdev CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-05 14:24 EDT by Michael Lindo CLA
Modified: 2014-01-29 22:55 EST (History)
3 users (show)

See Also:


Attachments
Fixes NPE and relative path problem (1.36 KB, patch)
2011-08-05 14:25 EDT, Michael Lindo CLA
angvoz.dev: iplog-
Details | Diff
Fixes NPE and relative path problem (2nd upload) (1.26 KB, patch)
2011-08-09 16:16 EDT, Michael Lindo CLA
angvoz.dev: iplog-
Details | Diff
Fixes NPE and relative path problem (3rd upload, 2nd revision) (1.32 KB, patch)
2011-08-11 11:12 EDT, Michael Lindo CLA
cdtdoug: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Lindo CLA 2011-08-05 14:24:26 EDT
Build Identifier: 3.6.1.r361_v20100909

There are two problems. The first one is causing this NPE:

java.lang.NullPointerException
    at org.eclipse.cdt.make.internal.core.scannerconfig.gnu.ScannerInfoConsoleParserUtility.findFile(Unknown Source)
    at org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCScannerInfoConsoleParser.processCommand(Unknown Source)
    at org.eclipse.cdt.make.internal.core.scannerconfig.gnu.AbstractGCCBOPConsoleParser.processSingleLine(Unknown Source)
    at org.eclipse.cdt.make.internal.core.scannerconfig.gnu.AbstractGCCBOPConsoleParser.processLine(Unknown Source)
    at org.eclipse.cdt.internal.core.ConsoleOutputSniffer.processLine(Unknown Source)
    at org.eclipse.cdt.internal.core.ConsoleOutputSniffer.access$0(Unknown Source)
    at org.eclipse.cdt.internal.core.ConsoleOutputSniffer$ConsoleOutputStream.checkLine(Unknown Source)
    at org.eclipse.cdt.internal.core.ConsoleOutputSniffer$ConsoleOutputStream.close(Unknown Source)
    at org.eclipse.ptp.internal.rdt.core.remotemake.RemoteProcessClosure$ReaderThread.close(Unknown Source)
    at org.eclipse.ptp.internal.rdt.core.remotemake.RemoteProcessClosure.isAlive(Unknown Source)
    at org.eclipse.ptp.rdt.core.remotemake.RemoteCommandLauncher.waitAndRead(Unknown Source)
    at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.invokeMake(Unknown Source)
    at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.invokeBuilder(Unknown Source)
    at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(Unknown Source)
    at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(Unknown Source)
    at org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder.build(Unknown Source)
    at org.eclipse.core.internal.events.BuildManager$2.run(Unknown Source)
    at org.eclipse.core.runtime.SafeRunner.run(Unknown Source)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(Unknown Source)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(Unknown Source)
    at org.eclipse.core.internal.events.BuildManager$1.run(Unknown Source)
    at org.eclipse.core.runtime.SafeRunner.run(Unknown Source)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(Unknown Source)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(Unknown Source)
    at org.eclipse.core.internal.events.BuildManager.build(Unknown Source)
    at org.eclipse.core.internal.resources.Project$1.run(Unknown Source)
    at org.eclipse.core.internal.resources.Workspace.run(Unknown Source)
    at org.eclipse.core.internal.resources.Project.internalBuild(Unknown Source)
    at org.eclipse.core.internal.resources.Project.build(Unknown Source)
    at org.eclipse.ui.actions.BuildAction.invokeOperation(Unknown Source)
    at org.eclipse.ui.actions.WorkspaceAction.execute(Unknown Source)
    at org.eclipse.ui.actions.WorkspaceAction$2.runInWorkspace(Unknown Source)
    at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(Unknown Source)
    at org.eclipse.core.internal.jobs.Worker.run(Unknown Source)

This line in ScannerInfoConsoleParserUtility is causing it:
String foundLocation = file.getLocation().toString();

I switched getLocation getLocationURI and that seems to have solved the NPE since this will now work with remote paths.

The second problem is when you have relative paths such as ../includethisfolder It never passes the foundLocation.endsWith(..) statement.  Removing the "../" from the path seems to work, but is this going to break something else? 

Reproducible: Always
Comment 1 Michael Lindo CLA 2011-08-05 14:25:29 EDT
Created attachment 201006 [details]
Fixes NPE and relative path problem
Comment 2 Michael Lindo CLA 2011-08-08 11:17:49 EDT
Hi Andrew. Would you be able to review this patch? Thanks
Comment 3 Andrew Gvozdev CLA 2011-08-09 11:20:14 EDT
(In reply to comment #2)
> Hi Andrew. Would you be able to review this patch? Thanks
Can you attach a patch which can actually be applied in eclipse? There are unrelated changes in .gitignore but even if I exclude those I still cannot apply the patch.
Comment 4 Michael Lindo CLA 2011-08-09 14:04:58 EDT
(In reply to comment #3)
> (In reply to comment #2)
> > Hi Andrew. Would you be able to review this patch? Thanks
> Can you attach a patch which can actually be applied in eclipse? There are
> unrelated changes in .gitignore but even if I exclude those I still cannot
> apply the patch.

Hi Andrew, that patch should be for the 7.0 branch I believe. If that doesn't work I'll try to get a new one up here ASAP.
Comment 5 Andrew Gvozdev CLA 2011-08-09 14:31:52 EDT
Supposedly there is a problem with "build/" prefix in build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make. Where did it come from?
Comment 6 Michael Lindo CLA 2011-08-09 16:16:25 EDT
Created attachment 201184 [details]
Fixes NPE and relative path problem (2nd upload)
Comment 7 Michael Lindo CLA 2011-08-09 16:18:42 EDT
I uploaded a new patch. I'm not sure where that build prefix comes from. Just
set ignore leading path segments to 2 when you apply the patch.

(In reply to comment #5)
> Supposedly there is a problem with "build/" prefix in
> build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make. Where did it come
> from?
Comment 8 Andrew Gvozdev CLA 2011-08-10 15:11:23 EDT
(In reply to comment #7)
> I uploaded a new patch. I'm not sure where that build prefix comes from. Just
> set ignore leading path segments to 2 when you apply the patch.
That did not work on the first patch, the wizard gives only choice of 0 and 1 for leading segments. Probably related to having .gitignore in the patch. I can apply the new patch just fine, thanks.

(In reply to comment #0)
> I switched getLocation getLocationURI and that seems to have solved the NPE since this will now work with remote paths.
That should be OK.

> The second problem is when you have relative paths such as ../includethisfolder It never passes the foundLocation.endsWith(..) statement. Removing the "../" from the path seems to work, but is this going to break something else?
Well, in your patch you remove *all* leading segments, not only "..". That is not OK because you want paths like "Folder1/Folder2/file.c" match with the whole folders chain and not to match Folder6/file.c. Additionally it is possible that output would contain something like "xxx/../Folder1/Folder2/file.c" so you want to collapse the path. You can do it creating IPath with "new Path(fileName)". But you'll still need to remove leading segments like ".." or ".", Path does not do that.
Comment 9 Andrew Gvozdev CLA 2011-08-10 15:15:56 EDT
Can you also put your real name in Bugzilla? I can see it from the patch but it would be nice of you to reveal it in Bugzilla as well.
Comment 10 Michael Lindo CLA 2011-08-10 17:37:10 EDT
(In reply to comment #9)
> Can you also put your real name in Bugzilla? I can see it from the patch but it
> would be nice of you to reveal it in Bugzilla as well.

If I collapse the path
"somefolder/.././Folder1/Folder2/file.c"
it will become
"somefolder/Folder1/Folder2/file.c"

Won't this get stuck returning null, since fileName may no longer be a suffix of foundLocation?

"if (!foundLocation.endsWith(fileName)) {" 

Regarding name change, please let me know where I can update that and my email address as well.

Thanks
Michael
Comment 11 Andrew Gvozdev CLA 2011-08-10 19:03:17 EDT
(In reply to comment #10)
> (In reply to comment #9)
> If I collapse the path
> "somefolder/.././Folder1/Folder2/file.c"
> it will become
> "somefolder/Folder1/Folder2/file.c"
> Won't this get stuck returning null, since fileName may no longer be a suffix of
> foundLocation?
> "if (!foundLocation.endsWith(fileName)) {"
If you collapse the path using 'new Path("somefolder/.././Folder1/Folder2/file.c") it will become "Folder1/Folder2/file.c". Path will collapse using path rules and accounting for "..". Except it cannot handle of course if your path starts with ".." to begin with.

> Regarding name change, please let me know where I can update that and my email
> address as well.
In bugzilla. Go to https://bugs.eclipse.org/bugs/userprefs.cgi?tab=account , login and you can change your name and email address in "Name and Password" tab.
Comment 12 Michael Lindo CLA 2011-08-11 11:12:56 EDT
Created attachment 201322 [details]
Fixes NPE and relative path problem (3rd upload, 2nd revision)
Comment 13 Michael Lindo CLA 2011-08-11 11:16:52 EDT
Hi Andrew, please see the latest patch. It will deal with the special case when the path starts with "..". Let me know if it can be committed. Thanks.

(In reply to comment #11)
> (In reply to comment #10)
> > (In reply to comment #9)
> > If I collapse the path
> > "somefolder/.././Folder1/Folder2/file.c"
> > it will become
> > "somefolder/Folder1/Folder2/file.c"
> > Won't this get stuck returning null, since fileName may no longer be a suffix of
> > foundLocation?
> > "if (!foundLocation.endsWith(fileName)) {"
> If you collapse the path using 'new
> Path("somefolder/.././Folder1/Folder2/file.c") it will become
> "Folder1/Folder2/file.c". Path will collapse using path rules and accounting
> for "..". Except it cannot handle of course if your path starts with ".." to
> begin with.
> 
> > Regarding name change, please let me know where I can update that and my email
> > address as well.
> In bugzilla. Go to https://bugs.eclipse.org/bugs/userprefs.cgi?tab=account ,
> login and you can change your name and email address in "Name and Password"
> tab.
Comment 14 Andrew Gvozdev CLA 2011-08-12 15:15:16 EDT
(In reply to comment #13)
> Hi Andrew, please see the latest patch. It will deal with the special case when
> the path starts with "..". Let me know if it can be committed. Thanks.
Thanks for the patch. Pushed to cdt_7_0, cdt_8_0 and master. Please, doublecheck that it is working as expected on all branches.
Comment 15 CDT Genie CLA 2011-08-12 15:23:02 EDT
*** cdt git genie on behalf of Michael Lindo ***

    bug 354042: Problem with include paths that are relative paths starting
    with ../ or./ and NPE

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=6dd117ec5e0dc130d2f78dc5c285834ca33ae39c
Comment 16 CDT Genie CLA 2011-08-12 15:23:03 EDT
*** cdt git genie on behalf of Michael Lindo ***

    bug 354042: Problem with include paths that are relative paths starting
    with ../ or./ and NPE

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=ac8574515bf178709504b87d8b4fc500da0dcb47
Comment 17 CDT Genie CLA 2011-08-12 15:23:05 EDT
*** cdt git genie on behalf of Michael Lindo ***

    bug 354042: Problem with include paths that are relative paths starting
    with ../ or./ and NPE

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=c1da6bdd847755b917acb933bb3e5ce9874198f0