Skip to content

UpdateBeforeAfterAnnotations does not check for existing target annotations #501

Description

@timo-abele

What version of OpenRewrite are you using?

I was using the latest version as of 2024-02-14, I bet this hasn't been fixed in the meantime because it is an edge case.

How are you running OpenRewrite?

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

What is the problem?

A test base class uses both JUnit 4 and Jupiter, as a consequence its setup method is annotated with both @Before and @BeforeEach. The recipe will now replace the old @Before with the already present @BeforeEach annotation causing

Duplicate annotation. The declaration of 'org.junit.jupiter.api.BeforeEach' does not have a valid java.lang.annotation.Repeatable annotation

...
class TestBase {
    @Before
    @BeforeEach
    void setup() {
      //...
    }
}

While rare this issue could pop up in all kinds of unexpected places, so it might be worth introducing something like MaybeChangeType that considers the already present annotations.

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

see above

Are you interested in contributing a fix to OpenRewrite?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions