diff --git a/src/main/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiterals.java b/src/main/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiterals.java index 7a8fcdbc7..c1f34f1de 100644 --- a/src/main/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiterals.java +++ b/src/main/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiterals.java @@ -230,8 +230,9 @@ public J.VariableDeclarations.NamedVariable visitVariable(J.VariableDeclarations boolean privateStaticFinalVariable = isPrivateStaticFinalVariable(variable); // `private static final String`(s) are handled separately by `FindExistingPrivateStaticFinalFields`. if (v.getInitializer() instanceof J.Literal && - (parentScope.getValue() instanceof J.MethodDeclaration || parentScope.getValue() instanceof J.ClassDeclaration) && - !(privateStaticFinalVariable && ((J.Literal) v.getInitializer()).getValue() instanceof String)) { + (parentScope.getValue() instanceof J.MethodDeclaration || parentScope.getValue() instanceof J.ClassDeclaration) && + ((J.Literal) v.getInitializer()).getValue() instanceof String && + !privateStaticFinalVariable) { String value = (((J.Literal) v.getInitializer()).getValue()).toString(); result.existingFieldValueToFieldName.put(v.getSimpleName(), value); } diff --git a/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java b/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java index be34b7030..d93fa1af8 100644 --- a/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java @@ -727,4 +727,24 @@ interface A { ) ); } + + @Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/384") + @Test + void staticWithObjectArray() { + rewriteRun( + //language=java + java( + """ + class A { + public void method() { + Object[] args = null; + args = new Object[] {"value"}; + } + } + """ + ) + ); + } + + }