[GR-33359] Fix image name argument parsing when combined with -m option #3622
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adresses two problems related to
native-image
argument handling. Namely, it:NullPointerException
in cases when a class could not be found on the provided module path--module
argument, the image name is not mistakenly interpreted as a class nameDetails
Main class resolving
Currently, our main class resolving is done via:
graal/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java
Line 340 in 8d70605
There is a catch block present for
ClassNotFoundException
, however, looking at the call chain, it is possible that control will reachjava.lang.Class.forName(Module, String)
, and by looking at the documentation for this method the return value could benull
- which is currently not covered. Therefore, the following line will produce aNullPointerException
:graal/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java
Line 351 in 8d70605
Image name handling in the presence of
--module
optionInvoking
native-image
with the following argumentswill produce a binary with the name
foo
. However, combining this with the--module
(-m
for short) option, for examplewill cause a
NullPointerException
in the same line as mentioned above. This is tied to class resolving which could returnnull
, however it is a misinterpreted main class argument when-m
option is present - the image name will be interpreted as an overrule for the class name.Implementation details
This PR solves this problem by reusing the same overrule exclusion code used when
-jar
option is present:graal/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java
Line 1168 in 8d70605
As for main class resolving, a check is added to ensure that the
mainClass
field is notnull
before proceeding onto entry method lookup.