Skip to content

ReplaceWeekYearWithYear incorrectly replaces valid week-year usages #800

@tginsberg

Description

@tginsberg

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v8.69.0
  • Maven/Gradle plugin v7.23.0
  • Static Analysis: v2.24.0

How are you running OpenRewrite?

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

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

public class Example {
    void example() {
        var dtf = DateTimeFormatter.ofPattern("YYYY-ww");
    }
}

What did you expect to see?

Because the format uses week-of-year, I expect YYYY (week year) to be left alone.

public class Example {
    void example() {
        var dtf = DateTimeFormatter.ofPattern("YYYY-ww");
    }
}

What did you see instead?

When used with week-of-year (ww), week-year (YYYY) is valid. However, ReplaceWeekYearWithYear replaces it in cases where it shouldn't, creating formats the author probably does not intend. In the example below, yyyy-ww uses calendar year and week-of-year instead of the desired week-year and week-of-year.

public class Example {
    void example() {
        var dtf = DateTimeFormatter.ofPattern("yyyy-ww");
    }
}

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

No errors, stack traces, or other unexpected output, just incorrect behavior.

Are you interested in contributing a fix to OpenRewrite?

Yes!

Metadata

Metadata

Assignees

No one assigned

    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