Skip to content

org.openrewrite.staticanalysis.NoDoubleBraceInitialization drops constructor collection parameter #356

Description

@blipper
class A {
    void foo() {
        Map<String, String> a = Map.of("foo", "bar");
        Map<String, String> b = new HashMap<>(a) {{
            put("irrelevantKey", "irrelevantValue");
        }};
    }
}

What did you expect to see?

class A {
    void foo() {
        Map<String, String> a = Map.of("foo", "bar");
        Map<String, String> b = new HashMap<>(a);
        b.put("irrelevantKey", "irrelevantValue");
    }
}

What did you see instead?

class A {
    void foo() {
        Map<String, String> a = Map.of("foo", "bar");
        Map<String, String> b = new HashMap<>();   // <= No `a` here anymore
        b.put("irrelevantKey", "irrelevantValue");
    }
}

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

stacktrace output here

Are you interested in contributing a fix to OpenRewrite?

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

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