Skip to content

Conversation

cdsap
Copy link
Member

@cdsap cdsap commented Sep 18, 2025

If MavenSession is null, calling Utils.projectProperty currently throws a NullPointerException:

java.lang.NullPointerException: Cannot invoke "org.apache.maven.execution.MavenSession.getUserProperties()" because "mavenSession" is null
    at com.gradle.Utils.projectProperty (Utils.java:33)
    at com.gradle.CustomBuildScanEnhancements.addCustomValueWhenProjectPropertyResolvesToTrue (CustomBuildScanEnhancements.java:476)
    at com.gradle.CustomBuildScanEnhancements.captureSkipTestsFlags (CustomBuildScanEnhancements.java:470)

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.

}

@Test
void testProjectProperty_nullSession_returnsEmpty() {
Copy link
Member Author

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?

Copy link
Member

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

https://github.com/gradle/dv/blob/4ac9f78635f899e390fea59e9162bd520ec795b2/common-custom-user-data-maven-extension-test-func/src/test/groovy/com/gradle/maven/custom/CommonCustomUserDataMavenExtensionFuncTest.groovy#L39

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.

@cdsap cdsap requested a review from a team September 18, 2025 17:17
}

@Test
void testProjectProperty_nullSession_returnsEmpty() {
Copy link
Member

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

https://github.com/gradle/dv/blob/4ac9f78635f899e390fea59e9162bd520ec795b2/common-custom-user-data-maven-extension-test-func/src/test/groovy/com/gradle/maven/custom/CommonCustomUserDataMavenExtensionFuncTest.groovy#L39

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants