Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 349730 - Non-local files cause InvalidArgumentException
Summary: Non-local files cause InvalidArgumentException
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 8.0   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: 8.0.1   Edit
Assignee: Markus Schorn CLA
QA Contact: Doug Schaefer CLA
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks: 349204
  Show dependency tree
 
Reported: 2011-06-17 16:13 EDT by Greg Watson CLA
Modified: 2014-01-29 22:54 EST (History)
1 user (show)

See Also:


Attachments
Fix for InvalidArgumentException (1.41 KB, patch)
2011-06-17 16:14 EDT, Greg Watson CLA
cdtdoug: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Watson CLA 2011-06-17 16:13:42 EDT
If a TU is from a non-local filesystem, then it can cause an InvalidArgumentException when a FileContent object is created. This is because InternalParserUtil#createWorkspaceFileContent() assumes that IFile#getContents() is always a FileInputStream. However in most cases (e.g. RSE and Remote Tools) IFile#getContents() returns an InputStream that is not a FileInputStream.

The attached patch checks the return value of IFile#getContents(). If it is not a FileInputStream, a local copy of the resource is cached and a FileInputStream opened on the cached copy.
Comment 1 Greg Watson CLA 2011-06-17 16:14:31 EDT
Created attachment 198213 [details]
Fix for InvalidArgumentException
Comment 2 Markus Schorn CLA 2011-06-29 08:50:41 EDT
In earlier versions we intentionally did not create file-content objects for non-local file systems. The effect of this decision was, that we did not index remote file-systems, which is probably desirable.
You seem to have a use-case where you do want to create a file-content object for a remote file. Can you describe the scenario (and provide a stack trace of the exception)?
Comment 3 Markus Schorn CLA 2011-07-20 04:06:38 EDT
Greg, can you provide the stack-trace?
Comment 4 Greg Watson CLA 2011-08-09 10:29:54 EDT
Here's the stack trace. The exception occurs because FileCharArray tests if the input stream is a FileInputStream and returns null if not. This null is then passed to the InternalFileContent constructor at line 224 of InternalParserUtil#createFileContent(). The patch just creates a FileInputStream from the IFileStore if this is the case.

java.lang.IllegalArgumentException
	at org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent.<init>(InternalFileContent.java:75)
	at org.eclipse.cdt.internal.core.parser.InternalParserUtil.createFileContent(InternalParserUtil.java:224)
	at org.eclipse.cdt.internal.core.parser.InternalParserUtil.createWorkspaceFileContent(InternalParserUtil.java:158)
	at org.eclipse.cdt.core.parser.FileContent.create(FileContent.java:83)
	at org.eclipse.cdt.core.parser.FileContent.create(FileContent.java:67)
	at org.eclipse.cdt.internal.core.model.TranslationUnit.getAST(TranslationUnit.java:779)
	at org.eclipse.cdt.internal.core.model.TranslationUnit.getAST(TranslationUnit.java:768)
	at org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase.getAST(RunAnalyseHandlerBase.java:519)
	at org.eclipse.ptp.pldt.mpi.core.actions.RunAnalyseMPIcommandHandler.doArtifactAnalysis(RunAnalyseMPIcommandHandler.java:66)
	at org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase.analyse(RunAnalyseHandlerBase.java:149)
	at org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase.runResource(RunAnalyseHandlerBase.java:408)
	at org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase.runResources(RunAnalyseHandlerBase.java:625)
	at org.eclipse.ptp.pldt.common.actions.RunAnalyseHandlerBase$1.execute(RunAnalyseHandlerBase.java:310)
	at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Comment 5 Beth Tibbitts CLA 2011-08-11 15:38:23 EDT
My motivation is to re-institue function that worked before the original UNC path change,
and  this worked for remote projects in the past and then stop working
when https://bugs.eclipse.org/bugs/show_bug.cgi?id=343437
(Add support for UNC include directories) was implemented.

Yes it's not very scalable (pull entire file down to get AST) but until I decide on and implement a more scalable solution I would like this to work as it used to on a remote file.
Comment 6 Markus Schorn CLA 2011-08-17 07:59:55 EDT
Thanks, I have committed your patch.
Comment 7 CDT Genie CLA 2011-08-17 08:23:04 EDT
*** cdt git genie on behalf of Greg Watson ***

    Bug 349730: Content for non-local files

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=ffca7f9d6bc38f101c22a80acafea04f18c5119b
Comment 8 CDT Genie CLA 2011-08-17 08:23:05 EDT
*** cdt git genie on behalf of Greg Watson ***

    Bug 349730: Content for non-local files

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