-
Notifications
You must be signed in to change notification settings - Fork 19
Avoid NPE as the Maven session can be null #315
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
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
@Test | ||
void testProjectProperty_nullSession_returnsEmpty() { |
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 initially tried to provide parameterized tests to cover the different use cases, but I reverted that approach because the public MavenSession constructors are deprecated. Do you have an alternative?
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.
You might be able to add a test here
And use this setup (which will run the build with a null
Maven session) and see that it does not fail and publishes a Build Scan.
} | ||
|
||
@Test | ||
void testProjectProperty_nullSession_returnsEmpty() { |
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.
You might be able to add a test here
And use this setup (which will run the build with a null
Maven session) and see that it does not fail and publishes a Build Scan.
If MavenSession is null, calling
Utils.projectProperty
currently throws a NullPointerException:This PR adds a simple null check to Utils.projectProperty. When the MavenSession argument is null, the method now returns Optional.empty() instead of throwing.