-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup GCCToolChain #393
Cleanup GCCToolChain #393
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extend the commit message with when the problem happens and how it can be verified. The current commit message is way to generic to be useful.
Based on the info given so far in this PR, I can't say if this is a good change or bad one.
build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java
Outdated
Show resolved
Hide resolved
build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java
Outdated
Show resolved
Hide resolved
build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java
Outdated
Show resolved
Hide resolved
build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java
Outdated
Show resolved
Hide resolved
87154af
to
0590884
Compare
These were possible null pointer uses, detected by static code analysis. I updated the commit message. |
Test failed due to some package that could not be fetched. Is there a way to re-run tests without a new push? |
I restarted the build in GitHub actions - you may need to be a committer to do that. |
if (fileExts.isEmpty()) { | ||
Activator.log(new Status(Status.ERROR, Activator.getId(), | ||
"Error: cannot determine resources file extensions.\n")); | ||
fileExts.addAll(Arrays.asList(new String[] { "C", "c", "c++", "cc", "cpp", "cxx" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit torn here. I don't know if we should hard code the file extensions like this or if we should return the empty set or perhaps throw some kind of exception instead.
@jonahgraham: What's your opinion here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The set is filled at the creation of GCCToolChain. An empty set disables the C/C++ indexing, because no resources will be found in the command lines. An exception will stop the creation of GCCToolChain which will disrupt the whole Core Build Makefile flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonahgraham: What's your opinion here?
I don't understand the use case that leads to fileExts being empty at this point in the code. Is this a theoretical problem or is there a use case? If it is theoretical I would probably do it as @ewaterlander has it now as it seems a fairly safe fallback way to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the use case that leads to fileExts being empty at this point in the code. Is this a theoretical problem or is there a use case? If it is theoretical I would probably do it as @ewaterlander has it now as it seems a fairly safe fallback way to fail.
I'm building a plugin based on Core Build Makefile projects. I'm running static code analysis on my own files and a few CDT files that I needed to modify. I'm currently stuck on CDT 10.5. I created the fallback to get rid of a null pointer issue, because code has to be clean. So you can say it is theoretical. When I move to CDT 11.2 which includes all my other changes I don't need the modified GCCToolChain anymore. But due to constraints I can't move to CDT 11.x for the time being. I offered this change as a code cleanup. I do not depend on it. So you can also choose to remove the fallback. Or I can do it if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have looked closer at this change now and I think it is unnecessary.
Platform.getContentTypeManager
in practice always returns non-null and that assumption exists in hundreds of places in Eclipse, both CDT and Eclipse Platform codemanager.getContentType
in these cases will always return non-null as the content types will always be there as the content types are provided by the CDT core plug-in which is a dependent plug-in. This assumption is also carried through in multiple places in the CDT source
Of course an argument could be made that we should be more defensive in the programming here. However this new code leads to a bunch of not reachable code. The new if statements added will always have a not-visited path and the fileExts.addAll
will never be called.
Therefore I think this part of the patch should not be done.
if (fileExts.isEmpty()) { | ||
Activator.log(new Status(Status.ERROR, Activator.getId(), | ||
"Error: cannot determine resources file extensions.\n")); | ||
fileExts.addAll(Arrays.asList(new String[] { "C", "c", "c++", "cc", "cpp", "cxx" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have looked closer at this change now and I think it is unnecessary.
Platform.getContentTypeManager
in practice always returns non-null and that assumption exists in hundreds of places in Eclipse, both CDT and Eclipse Platform codemanager.getContentType
in these cases will always return non-null as the content types will always be there as the content types are provided by the CDT core plug-in which is a dependent plug-in. This assumption is also carried through in multiple places in the CDT source
Of course an argument could be made that we should be more defensive in the programming here. However this new code leads to a bunch of not reachable code. The new if statements added will always have a not-visited path and the fileExts.addAll
will never be called.
Therefore I think this part of the patch should not be done.
Path commandPath = getCommandPath(command); | ||
if (commandPath != null) { | ||
commandLine.add(commandPath.toString()); | ||
} else { | ||
commandLine.add(getCommandPath(command).toString()); | ||
Activator.log(new Status(Status.ERROR, Activator.getId(), | ||
"Error: cannot extract compiler command from command line.\n")); | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting case. By having getScannerInfo
return null here it simply delays the NPE that used to (theoretically) be thrown here to be thrown later when the scanner info is accessed in CBuildConfiguration.processLine
. Adding the log here is helpful, but without a stacktrace/extra details it doesn't leave additional info on helping to identify the problem.
This code has an assumption is that the compiler will be found and that getCommandPath won't actually return null. Not sure how to get it into that state.
I would rather see this throw an exception here and I provide a suggestion as to what that could look like.
Path commandPath = getCommandPath(command);
if (commandPath == null) {
throw new NullPointerException("Cannot obtain full command path for command " + command);
}
commandLine.add(commandPath.toString());
with a similar change below.
build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java
Show resolved
Hide resolved
Fixed some possible null pointer uses, detected by a statical code analysis tool.
0590884
to
1601982
Compare
As @Torbjorn-Svensson has an outstanding "change requested" marked on here I will wait a bit before merging to give him a chance to weigh in. FWIW this is what I see in the UI, because we have allow override for branch protection I can submit this, but I have to tick the big red checkmark first: |
@jonahgraham Do you think we should include this in the 11.2 release or wait for 11.3? |
11.3 — I'm preparing branches/etc now ahead of final build on Monday |
Fixed some null pointer issues.