javaspring-bootgradleopenrewrite

Execution failed for task ':rewriteRun'. Cannot invoke "java.util.Set.stream()" because the return value of "java.util.Map.remove(Object)" is null


I am on IntelliJ IDEA 2025.1.2 with plugin OpenRewrite bundled 251.26094.121Java 18, and Gradle 7.6.5. I am trying to update Spring Boot from version 3.3.12 to version 3.4 but OpenRewrite returns the following error:

15:07:12: Executing 'rewriteRun'…


> Task :compileJava
Note: C:\Users\UserName\IdeaProjects\test-project\src\main\java\com\test\contactdata\controller\util\CrmFormatterUtils.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :processResources
> Task :classes
> Task :compileTestJava

> Task :rewriteRun
Validating active recipes
Scanning sources in project :
Using active styles []
There were problems parsing some source files, run with --info to see full stack traces
There were problems parsing Test_DevOps\helm\test-project\templates\deployment.yaml
There were problems parsing Test_DevOps\helm\test-project\templates\hpa.yaml
There were problems parsing Test_DevOps\helm\test-project\templates\ingress.yaml
There were problems parsing Test_DevOps\helm\test-project\templates\secretproviderclass.yaml
There were problems parsing Test_DevOps\helm\test-project\templates\service.yaml
There were problems parsing Test_DevOps\helm\test-project\templates\serviceaccount.yaml
All sources parsed, running active recipes: org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_4
The recipe produced an error. Please report this to the recipe author.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':rewriteRun'.
> java.lang.RuntimeException: Error while visiting build.gradle: java.lang.NullPointerException: Cannot invoke "java.util.Set.stream()" because the return value of "java.util.Map.remove(Object)" is null
    org.openrewrite.gradle.search.DependencyInsight$MarkIndividualDependency.lambda$visitMethodInvocation$4(DependencyInsight.java:237)
    java.base/java.util.Optional.map(Optional.java:260)
    org.openrewrite.gradle.search.DependencyInsight$MarkIndividualDependency.visitMethodInvocation(DependencyInsight.java:230)
    org.openrewrite.gradle.search.DependencyInsight$MarkIndividualDependency.visitMethodInvocation(DependencyInsight.java:192)
    org.openrewrite.java.tree.J$MethodInvocation.acceptJava(J.java:4281)
    org.openrewrite.java.tree.J.accept(J.java:63)
    org.openrewrite.TreeVisitor.visit(TreeVisitor.java:245)
    org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:311)
    org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1380)
    org.openrewrite.java.JavaVisitor.lambda$visitBlock$4(JavaVisitor.java:400)
    org.openrewrite.internal.ListUtils.map(ListUtils.java:244)
    org.openrewrite.internal.ListUtils.map(ListUtils.java:267)
    org.openrewrite.java.JavaVisitor.visitBlock(JavaVisitor.java:399)
    org.openrewrite.java.JavaIsoVisitor.visitBlock(JavaIsoVisitor.java:88)
    org.openrewrite.java.JavaIsoVisitor.visitBlock(JavaIsoVisitor.java:30)
    org.openrewrite.java.tree.J$Block.acceptJava(J.java:851)
    ...

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 43s

> Task :rewriteRun FAILED
4 actionable tasks: 4 executed
15:09:56: Execution finished 'rewriteRun'.

Unfortunately the error message does not help. What might the issue here?I also tried by removing the helm files, and with different Gradle version but it didn't help either.

My build.gradle file is as following:

plugins {
    id 'org.springframework.boot' version '3.3.12'
    id 'io.spring.dependency-management' version '1.1.7'
    id 'java'
    id 'org.sonarqube' version '3.5.0.2730'
}

group = 'com.test'
version = '0.0.1-SNAPSHOT'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(18)
    }
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    implementation 'org.springframework.boot:spring-boot-starter-freemarker'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
    implementation 'io.hypersistence:hypersistence-utils-hibernate-63:3.8.3'
    implementation "jakarta.validation:jakarta.validation-api:3.0.2"
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.apache.commons:commons-lang3:3.15.0'
    implementation 'org.apache.httpcomponents.client5:httpclient5'
    implementation 'org.flywaydb:flyway-core'
    implementation 'org.flywaydb:flyway-sqlserver'
    implementation 'org.keycloak:keycloak-admin-client:16.1.0'
    implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.14.1'
    implementation 'com.googlecode.libphonenumber:libphonenumber:8.13.40'
    implementation "commons-codec:commons-codec:1.17.2"
    implementation 'com.google.guava:guava:33.3.1-jre'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc:10.2.1.jre17'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

I also have a second Spring Boot 3.3.10 application and again I want to update it to version 3.4. Java 18, Gradle 7.5. OpenRewrite again returns the following error:

15:48:54: Executing 'rewriteRun'…

Starting Gradle Daemon...
Gradle Daemon started in 5 s 716 ms
Download https://plugins.gradle.org/m2/org/openrewrite/plugin/maven-metadata.xml, took 59 ms

> Task :compileJava
C:\Users\UserName\IdeaProjects\test-project\test-project\src\main\java\com\test\client\configuration\security\ResourceServerConfig.java:43: warning: [removal] csrf() in HttpSecurity has been deprecated and marked for removal
                .csrf().disable()
                ^
C:\Users\UserName\IdeaProjects\test-project\test-project\src\main\java\com\test\client\configuration\security\ResourceServerConfig.java:45: warning: [removal] oauth2ResourceServer() in HttpSecurity has been deprecated and marked for removal
                .oauth2ResourceServer()
                ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\UserName\IdeaProjects\test-project\test-project\src\main\java\com\test\client\service\backend\client\MixedMultiplartFormHttpMessageConverter.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 warnings

> Task :processResources
> Task :classes
> Task :compileTestJava

> Task :rewriteRun
Validating active recipes
Scanning sources in project :
Using active styles []
All sources parsed, running active recipes: org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_4
The recipe produced an error. Please report this to the recipe author.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':rewriteRun'.
> java.lang.RuntimeException: Error while visiting test-project\build.gradle: java.lang.NullPointerException: Cannot invoke "java.util.Set.stream()" because the return value of "java.util.Map.remove(Object)" is null
    org.openrewrite.gradle.search.DependencyInsight$MarkIndividualDependency.lambda$visitMethodInvocation$4(DependencyInsight.java:237)
    java.base/java.util.Optional.map(Optional.java:260)
    org.openrewrite.gradle.search.DependencyInsight$MarkIndividualDependency.visitMethodInvocation(DependencyInsight.java:230)
    org.openrewrite.gradle.search.DependencyInsight$MarkIndividualDependency.visitMethodInvocation(DependencyInsight.java:192)
    org.openrewrite.java.tree.J$MethodInvocation.acceptJava(J.java:4281)
    org.openrewrite.java.tree.J.accept(J.java:63)
    org.openrewrite.TreeVisitor.visit(TreeVisitor.java:245)
    org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:311)
    org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1380)
    org.openrewrite.java.JavaVisitor.lambda$visitBlock$4(JavaVisitor.java:400)
    org.openrewrite.internal.ListUtils.map(ListUtils.java:244)
    org.openrewrite.internal.ListUtils.map(ListUtils.java:267)
    org.openrewrite.java.JavaVisitor.visitBlock(JavaVisitor.java:399)
    org.openrewrite.java.JavaIsoVisitor.visitBlock(JavaIsoVisitor.java:88)
    org.openrewrite.java.JavaIsoVisitor.visitBlock(JavaIsoVisitor.java:30)
    org.openrewrite.java.tree.J$Block.acceptJava(J.java:851)
    ...

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3m 58s

> Task :rewriteRun FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5/userguide/command_line_interface.html#sec:command_line_warnings
4 actionable tasks: 4 executed
15:52:57: Execution finished 'rewriteRun'.

Actually later I fixed the warnings but again it didn't help. What I am doing wrong here?

Content of my gradle.build file is as following:

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.3.10'
    id 'io.spring.dependency-management' version '1.1.0'
    id "jacoco"
    id 'org.sonarqube' version '3.5.0.2730'
}

group = 'com.test'
version = '0.0.1-SNAPSHOT'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(18)
    }
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.data:spring-data-commons:3.1.12'
    implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.1'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.apache.poi:poi-ooxml:5.3.0'
    implementation 'com.ibm.icu:icu4j:75.1'
    implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.1'
    implementation 'com.itextpdf:itextpdf:5.5.13.4'

    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'

    implementation 'org.keycloak:keycloak-admin-client:16.1.0'

    implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
    runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
    runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

jacocoTestReport {
    reports {
        xml.enabled true
    }
}

tasks.named('test', Test) {
    useJUnitPlatform()
}

Solution

  • This seems to be a bug in Openrewrite that is triggered by having the same dependency twice. It was just reported: https://github.com/openrewrite/rewrite/issues/5578

    The probable dependencies that are triggering the issue are:

    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    

    A similar example with lombok can be found on the bug report.

    You could try to remove one of the dependencies or wait for the bug to be eventually resolved.