Skip to content
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

Fix bug using AddOrUpdateAnnotationAttribute on annotation with empty brackets #4672

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

nielsdebruin
Copy link
Contributor

What's changed?

Fixed bug that caused incorrect code when AddOrUpdateAnnotationAttribute on annotation with empty bracket e.g., @Foo().

What's your motivation?

The recipe AddOrUpdateAnnotationAttribute can be used to modify the attribute values on annotation. When no attribute values have been specified, the recipe will work fine if the syntax @Foo is used. However, if @Foo() is used, which is also valid java. Then, the recipe breaks.

Example

public @interface Foo {
    String[] array() default {};
}

If we run AddOrUpdateAnnotationAttribute on A annotated with @Foo, configured to set the value of Foo.array to "newTest1,newTest2" we correctly get:

@Foo
public class A {}
@Foo(array = {"newTest1", "newTest2"})
public class A {
}

Yet applying it to @Foo(), incorrectly yields

@Foo()
public class A {}
@Foo(array = "newTest1,newTest2", )
public class A {
}

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@nielsdebruin nielsdebruin added the bug Something isn't working label Nov 14, 2024
@nielsdebruin nielsdebruin self-assigned this Nov 14, 2024
@nielsdebruin nielsdebruin changed the title Add new test and fix Fix bug using AddOrUpdateAnnotationAttribute on annotation with empty brackets Nov 14, 2024
@nielsdebruin nielsdebruin marked this pull request as ready for review November 14, 2024 12:04
@timtebeek timtebeek merged commit 86f4eef into main Nov 14, 2024
2 checks passed
@timtebeek timtebeek deleted the bug-add-or-update-annotations-with-empty-brackets branch November 14, 2024 13:03
MBoegers pushed a commit to MBoegers/rewrite that referenced this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants