1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Cleanup GCCToolChain

Fixed some possible null pointer uses, detected by a statical code
analysis tool.
This commit is contained in:
Erwin Waterlander 2023-05-12 15:57:29 +01:00 committed by Jonah Graham
parent 9e10c79017
commit 9dcaf509fa

View file

@ -280,11 +280,11 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
} }
List<String> commandLine = new ArrayList<>(); List<String> commandLine = new ArrayList<>();
if (command.isAbsolute()) { Path commandPath = getCommandPath(command);
commandLine.add(command.toString()); if (commandPath == null) {
} else { throw new NullPointerException("Cannot obtain full command path for command " + command); //$NON-NLS-1$
commandLine.add(getCommandPath(command).toString());
} }
commandLine.add(commandPath.toString());
if (baseScannerInfo != null) { if (baseScannerInfo != null) {
if (baseScannerInfo.getIncludePaths() != null) { if (baseScannerInfo.getIncludePaths() != null) {
@ -415,11 +415,11 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
// Pick the first one // Pick the first one
Path command = Paths.get(commands[0]); Path command = Paths.get(commands[0]);
List<String> commandLine = new ArrayList<>(); List<String> commandLine = new ArrayList<>();
if (command.isAbsolute()) { Path commandPath = getCommandPath(command);
commandLine.add(command.toString()); if (commandPath == null) {
} else { throw new NullPointerException("Cannot obtain full command path for command " + command); //$NON-NLS-1$
commandLine.add(getCommandPath(command).toString());
} }
commandLine.add(commandPath.toString());
if (baseScannerInfo != null) { if (baseScannerInfo != null) {
if (baseScannerInfo.getIncludePaths() != null) { if (baseScannerInfo.getIncludePaths() != null) {
@ -535,7 +535,9 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
} catch (InterruptedException e) { } catch (InterruptedException e) {
Activator.log(e); Activator.log(e);
} }
Files.delete(tmpFile); if (tmpFile != null) {
Files.delete(tmpFile);
}
return new ExtendedScannerInfo(symbols, includePath.toArray(new String[includePath.size()])); return new ExtendedScannerInfo(symbols, includePath.toArray(new String[includePath.size()]));
} }
@ -649,7 +651,7 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
private Set<String> getResourcesFileExtensions() { private Set<String> getResourcesFileExtensions() {
IContentTypeManager manager = Platform.getContentTypeManager(); IContentTypeManager manager = Platform.getContentTypeManager();
Set<String> fileExts = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); Set<String> fileExts = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
IContentType contentTypeCpp = manager.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE); IContentType contentTypeCpp = manager.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));