openrewrite / rewrite-spring

OpenRewrite recipes for Spring projects.
Apache License 2.0
237 stars 64 forks source link

org.springframework.util.Assert in Spring Framework 6 #521

Closed pativa closed 1 month ago

pativa commented 1 month ago

What problem are you trying to solve?

Migrating many projects to Spring Boot 3 / Spring Framework 6. There does not seem to be any recipes available for Spring Framework 6.

Specifically, we encountered that org.springframework.util.Assert have removed some functions that were previously deprecated. See the example below for an example change.

The easiest way to migrate this would be with org.openrewrite.java.AddLiteralMethodArgument.

Describe the situation before applying the recipe

import org.springframework.util.Assert;

class A {
    void foo(String bar) {
        Assert.notNull(bar);
    }
}

Describe the situation after applying the recipe

class A {
    void foo(String bar) {
        Assert.notNull(bar, "must not be null");
    }
}

Ideally I guess the message would be something like "bar must not be null", but that would be a harder change to apply automatically.

Are you interested in contributing this recipe to OpenRewrite?

I have the necessary yaml changes ready and could provide that, but as there is no Spring Framework 6 migration ready, I have nowhere to put them.

So this is more more wondering if there is any interest in that I contribute these changes to the project.

timtebeek commented 1 month ago

Hi @pativa ! Good seeing you back here; would love to include your recipe as a first step for a spring-framework-60.yml; we can hook that into the rest of the migrations as usual; Feel free to throw up a rough draft PR and I'll help get it in shape and merged.

Up to now we hadn't been very specific in what changes are needed for Spring Framework 6 and Spring Boot 3, but I like your suggestion of being explicit in what folks can apply, even if the Spring Boot recipes also work for Spring Framework applications.

pativa commented 1 month ago

Thank you for the quick response.

I did an attempt at this change in https://github.com/openrewrite/rewrite-spring/pull/522

timtebeek commented 1 month ago

Indeed fixed in

Thanks a lot!