1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Protect against NPE.

This commit is contained in:
Sergey Prigogin 2015-04-16 13:55:38 -07:00
parent 5da5634038
commit 3c61ffa5ef

View file

@ -59,7 +59,7 @@ public class InclusionContext {
fTuLocation = fTu.getLocation();
ICProject cProject = fTu.getCProject();
fProject = cProject.getProject();
fCurrentDirectory = fTu.getResource().getParent().getLocation();
fCurrentDirectory = fTuLocation == null ? null : fTuLocation.removeLastSegments(1);
IScannerInfo scannerInfo = fTu.getScannerInfo(true);
fIncludeSearchPath = CPreprocessor.configureIncludeSearchPath(fCurrentDirectory.toFile(), scannerInfo);
fIncludeResolutionCache = new HashMap<>();
@ -86,7 +86,7 @@ public class InclusionContext {
public IPath resolveInclude(IncludeInfo include) {
IPath path = fIncludeResolutionCache.get(include);
if (path == null) {
String directory = fCurrentDirectory.toOSString();
String directory = fCurrentDirectory == null ? null : fCurrentDirectory.toOSString();
String filePath = CPreprocessor.getAbsoluteInclusionPath(include.getName(), directory);
if (filePath != null) {
path = new Path(filePath);
@ -138,7 +138,7 @@ public class InclusionContext {
}
}
if (shortestInclude == null) {
if (fIncludeSearchPath.isInhibitUseOfCurrentFileDirectory() ||
if (fIncludeSearchPath.isInhibitUseOfCurrentFileDirectory() || fCurrentDirectory == null ||
!fCurrentDirectory.isPrefixOf(fullPath)) {
return null;
}
@ -172,7 +172,7 @@ public class InclusionContext {
}
}
if (shortestInclude == null) {
if (fIncludeSearchPath.isInhibitUseOfCurrentFileDirectory() ||
if (fIncludeSearchPath.isInhibitUseOfCurrentFileDirectory() || fCurrentDirectory == null ||
!fCurrentDirectory.isPrefixOf(fullPath)) {
return null;
}