Skip to content

org.openrewrite.staticanalysis.AnnotateRequiredParameters rewrites Objects.requireNonNull wrong #792

@flyhard

Description

@flyhard

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v6.23.0
  • Maven/Gradle plugin v6.23.0
  • rewrite-static-analysis v2.22.0

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

					<plugin>
						<groupId>org.openrewrite.maven</groupId>
						<artifactId>rewrite-maven-plugin</artifactId>
						<version>6.23.0</version>
						<configuration>
							<activeRecipes>
								<recipe>org.openrewrite.staticanalysis.CodeCleanup</recipe>
								<recipe>org.openrewrite.java.migrate.UpgradeToJava21</recipe>
								<recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe>
								<recipe>org.openrewrite.java.testing.assertj.JUnitToAssertj</recipe>
								<recipe>org.openrewrite.java.testing.assertj.Assertj</recipe>
								<recipe>org.openrewrite.java.migrate.lombok.log.UseLombokLogAnnotations</recipe>
								<recipe>org.openrewrite.java.logging.slf4j.ParameterizedLogging</recipe>
								<recipe>org.openrewrite.java.migrate.util.JavaUtilAPIs</recipe>
								<recipe>org.openrewrite.java.jspecify.JSpecifyBestPractices</recipe>
							</activeRecipes>
							<failOnDryRunResults>true</failOnDryRunResults>
						</configuration>
						<dependencies>
							<dependency>
								<groupId>org.openrewrite.recipe</groupId>
								<artifactId>rewrite-static-analysis</artifactId>
								<version>2.22.0</version>
							</dependency>
							<dependency>
								<groupId>org.openrewrite.recipe</groupId>
								<artifactId>rewrite-testing-frameworks</artifactId>
								<version>3.22.0</version>
							</dependency>
							<dependency>
								<groupId>org.openrewrite.recipe</groupId>
								<artifactId>rewrite-migrate-java</artifactId>
								<version>3.22.0</version>
							</dependency>
							<dependency>
								<groupId>org.openrewrite.recipe</groupId>
								<artifactId>rewrite-logging-frameworks</artifactId>
								<version>3.18.1</version>
							</dependency>
						</dependencies>
					</plugin>

What is the smallest, simplest way to reproduce the problem?

class A {
  String field;
    public A(String bar) {
        this.field = Objects.requireNonNull(bar,"bar may not be null);
    }
}

What did you expect to see?

class A {
  String field;
    public A(String bar) {
        this.field = bar;
    }
}

What did you see instead?

class A {
  String field;
    public A(String bar) {
        this.field;
    }
}

What is the full stack trace of any errors you encountered?

no error reported

Are you interested in contributing a fix to OpenRewrite?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions