From 70076914dc20495a4e74be092db1651006aad57f Mon Sep 17 00:00:00 2001 From: Akanksha Date: Wed, 30 Jul 2025 15:57:58 -0700 Subject: [PATCH 1/8] Prefer System getProperty() over getenv() --- .../PreferSystemGetPropertyOverGetenv.java | 43 +++++++++++++++++++ ...PreferSystemGetPropertyOverGetenvTest.java | 36 ++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java create mode 100644 src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java diff --git a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java new file mode 100644 index 0000000000..b57c60ddc5 --- /dev/null +++ b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java @@ -0,0 +1,43 @@ +package org.openrewrite.staticanalysis; + + +import org.openrewrite.ExecutionContext; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.java.JavaTemplate; +import org.openrewrite.java.tree.J; + +public class PreferSystemGetPropertyOverGetenv extends Recipe { + + @Override + public String getDisplayName() { + return "Prefer System.getProperty(\"user.home\") over System.getenv(\"HOME\")"; + } + + @Override + public String getDescription() { + return "Replaces System.getenv(\"HOME\") with System.getProperty(\"user.home\") for better portability."; + } + + @Override + public TreeVisitor getVisitor() { + return new JavaIsoVisitor() { + @Override + public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { + if (method.getSimpleName().equals("getenv") + && method.getArguments().size() == 1 + && method.getArguments().get(0).printTrimmed().equals("\"HOME\"")) { + + maybeAddImport("java.lang.System"); + + return JavaTemplate.builder("System.getProperty(\"user.home\")") + .imports("java.lang.System") + .build() + .apply(updateCursor(method), method.getCoordinates().replace()); + } + return super.visitMethodInvocation(method, ctx); + } + }; + } +} diff --git a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java new file mode 100644 index 0000000000..db2ff26e7a --- /dev/null +++ b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java @@ -0,0 +1,36 @@ +package org.openrewrite.staticanalysis; + +import org.junit.jupiter.api.Test; +import static org.openrewrite.java.Assertions.java; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +class PreferSystemGetPropertyOverGetenvTest implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec.recipe(new PreferSystemGetPropertyOverGetenv()); + } + + @Test + void replacesEnvWithProperty() { + rewriteRun( + java( + """ + class A { + void test() { + String home = System.getenv("HOME"); + } + } + """, + """ + class A { + void test() { + String home = System.getProperty("user.home"); + } + } + """ + ) + ); + } +} From 91c11bffc3cf396d9740919057a7ebd0864efd77 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 31 Jul 2025 01:51:00 +0200 Subject: [PATCH 2/8] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../PreferSystemGetPropertyOverGetenv.java | 21 ++++++++++++++++--- ...PreferSystemGetPropertyOverGetenvTest.java | 15 +++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java index b57c60ddc5..4967fe760e 100644 --- a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java +++ b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java @@ -1,3 +1,18 @@ +/* + * Copyright 2025 the original author or authors. + *

+ * Licensed under the Moderne Source Available License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.openrewrite.staticanalysis; @@ -25,9 +40,9 @@ public TreeVisitor getVisitor() { return new JavaIsoVisitor() { @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { - if (method.getSimpleName().equals("getenv") - && method.getArguments().size() == 1 - && method.getArguments().get(0).printTrimmed().equals("\"HOME\"")) { + if (method.getSimpleName().equals("getenv") && + method.getArguments().size() == 1 && + method.getArguments().get(0).printTrimmed().equals("\"HOME\"")) { maybeAddImport("java.lang.System"); diff --git a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java index db2ff26e7a..ec58d5f6f2 100644 --- a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2025 the original author or authors. + *

+ * Licensed under the Moderne Source Available License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.openrewrite.staticanalysis; import org.junit.jupiter.api.Test; From d6059b18b10c1b97e2dfe859916bb7d543e43d80 Mon Sep 17 00:00:00 2001 From: Akanksha Date: Wed, 30 Jul 2025 19:05:05 -0700 Subject: [PATCH 3/8] Make PR comment changes --- .../PreferSystemGetPropertyOverGetenv.java | 10 ++++++---- .../PreferSystemGetPropertyOverGetenvTest.java | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java index 4967fe760e..917a751be1 100644 --- a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java +++ b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java @@ -15,16 +15,18 @@ */ package org.openrewrite.staticanalysis; - import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaTemplate; +import org.openrewrite.java.MethodMatcher; import org.openrewrite.java.tree.J; public class PreferSystemGetPropertyOverGetenv extends Recipe { + private static final MethodMatcher GETENV = new MethodMatcher("java.lang.System getenv(java.lang.String)"); + @Override public String getDisplayName() { return "Prefer System.getProperty(\"user.home\") over System.getenv(\"HOME\")"; @@ -40,9 +42,9 @@ public TreeVisitor getVisitor() { return new JavaIsoVisitor() { @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { - if (method.getSimpleName().equals("getenv") && - method.getArguments().size() == 1 && - method.getArguments().get(0).printTrimmed().equals("\"HOME\"")) { + if (GETENV.matches(method) + && method.getArguments().size() == 1 + && method.getArguments().get(0).printTrimmed().equals("\"HOME\"")) { maybeAddImport("java.lang.System"); diff --git a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java index ec58d5f6f2..a9cf852434 100644 --- a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java @@ -16,6 +16,7 @@ package org.openrewrite.staticanalysis; import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import static org.openrewrite.java.Assertions.java; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -27,6 +28,7 @@ public void defaults(RecipeSpec spec) { spec.recipe(new PreferSystemGetPropertyOverGetenv()); } + @DocumentExample @Test void replacesEnvWithProperty() { rewriteRun( From 0559fe0582284c3e0cffa9301fdc76ba3b2da4fc Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 31 Jul 2025 21:39:04 +0200 Subject: [PATCH 4/8] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../staticanalysis/PreferSystemGetPropertyOverGetenv.java | 6 +++--- .../PreferSystemGetPropertyOverGetenvTest.java | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java index 917a751be1..56a6d44069 100644 --- a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java +++ b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java @@ -42,9 +42,9 @@ public TreeVisitor getVisitor() { return new JavaIsoVisitor() { @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { - if (GETENV.matches(method) - && method.getArguments().size() == 1 - && method.getArguments().get(0).printTrimmed().equals("\"HOME\"")) { + if (GETENV.matches(method) && + method.getArguments().size() == 1 && + method.getArguments().get(0).printTrimmed().equals("\"HOME\"")) { maybeAddImport("java.lang.System"); diff --git a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java index a9cf852434..0468744ea7 100644 --- a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; import static org.openrewrite.java.Assertions.java; + import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; From aac848cc072132c157b8a5121516d85e7091ff6c Mon Sep 17 00:00:00 2001 From: Akanksha Date: Thu, 21 Aug 2025 00:15:15 -0700 Subject: [PATCH 5/8] extend recipe to support multiple System.getenv() --- .../PreferSystemGetPropertyOverGetenv.java | 39 ++++++++++++--- ...PreferSystemGetPropertyOverGetenvTest.java | 49 ++++++++++++------- 2 files changed, 62 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java index 56a6d44069..7e70e673f0 100644 --- a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java +++ b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java @@ -15,6 +15,9 @@ */ package org.openrewrite.staticanalysis; +import java.util.HashMap; +import java.util.Map; + import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; @@ -27,6 +30,18 @@ public class PreferSystemGetPropertyOverGetenv extends Recipe { private static final MethodMatcher GETENV = new MethodMatcher("java.lang.System getenv(java.lang.String)"); + private static final Map ENV_TO_PROPERTY = new HashMap<>(); + + static { + ENV_TO_PROPERTY.put("USER", "user.name"); + ENV_TO_PROPERTY.put("USERNAME", "user.name"); + ENV_TO_PROPERTY.put("HOME", "user.home"); + ENV_TO_PROPERTY.put("USERPROFILE", "user.home"); + ENV_TO_PROPERTY.put("TMPDIR", "java.io.tmpdir"); + ENV_TO_PROPERTY.put("TEMP", "java.io.tmpdir"); + ENV_TO_PROPERTY.put("TMP", "java.io.tmpdir"); + } + @Override public String getDisplayName() { return "Prefer System.getProperty(\"user.home\") over System.getenv(\"HOME\")"; @@ -42,16 +57,24 @@ public TreeVisitor getVisitor() { return new JavaIsoVisitor() { @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { - if (GETENV.matches(method) && - method.getArguments().size() == 1 && - method.getArguments().get(0).printTrimmed().equals("\"HOME\"")) { + if (GETENV.matches(method) + && method.getArguments().size() == 1 + && method.getArguments().get(0) instanceof J.Literal) { + + J.Literal arg = (J.Literal) method.getArguments().get(0); - maybeAddImport("java.lang.System"); + if (arg.getValue() instanceof String) { + String envVar = (String) arg.getValue(); + String replacementProperty = ENV_TO_PROPERTY.get(envVar); - return JavaTemplate.builder("System.getProperty(\"user.home\")") - .imports("java.lang.System") - .build() - .apply(updateCursor(method), method.getCoordinates().replace()); + if (replacementProperty != null) { + maybeAddImport("java.lang.System"); + return JavaTemplate.builder("System.getProperty(\"" + replacementProperty + "\")") + .imports("java.lang.System") + .build() + .apply(updateCursor(method), method.getCoordinates().replace()); + } + } } return super.visitMethodInvocation(method, ctx); } diff --git a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java index 0468744ea7..5dd7a1c74d 100644 --- a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java @@ -31,24 +31,37 @@ public void defaults(RecipeSpec spec) { @DocumentExample @Test - void replacesEnvWithProperty() { - rewriteRun( - java( - """ - class A { - void test() { - String home = System.getenv("HOME"); - } +void replacesMultipleEnvVariables() { + rewriteRun( + java( + """ + class A { + void test() { + String user = System.getenv("USER"); + String username = System.getenv("USERNAME"); + String home = System.getenv("HOME"); + String profile = System.getenv("USERPROFILE"); + String temp = System.getenv("TEMP"); + String tmpdir = System.getenv("TMPDIR"); + String tmp = System.getenv("TMP"); } - """, - """ - class A { - void test() { - String home = System.getProperty("user.home"); - } + } + """, + """ + class A { + void test() { + String user = System.getProperty("user.name"); + String username = System.getProperty("user.name"); + String home = System.getProperty("user.home"); + String profile = System.getProperty("user.home"); + String temp = System.getProperty("java.io.tmpdir"); + String tmpdir = System.getProperty("java.io.tmpdir"); + String tmp = System.getProperty("java.io.tmpdir"); } - """ - ) - ); - } + } + """ + ) + ); +} + } From e185702616d2e7a043fc53fbdb99a144aaaebce2 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 21 Aug 2025 13:00:35 +0200 Subject: [PATCH 6/8] Polish --- .../PreferSystemGetPropertyOverGetenv.java | 38 ++++------ ...PreferSystemGetPropertyOverGetenvTest.java | 69 +++++++++---------- 2 files changed, 49 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java index 7e70e673f0..898b4037c9 100644 --- a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java +++ b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java @@ -15,21 +15,22 @@ */ package org.openrewrite.staticanalysis; -import java.util.HashMap; -import java.util.Map; - import org.openrewrite.ExecutionContext; +import org.openrewrite.Preconditions; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.MethodMatcher; +import org.openrewrite.java.search.UsesMethod; import org.openrewrite.java.tree.J; +import java.util.HashMap; +import java.util.Map; + public class PreferSystemGetPropertyOverGetenv extends Recipe { private static final MethodMatcher GETENV = new MethodMatcher("java.lang.System getenv(java.lang.String)"); - private static final Map ENV_TO_PROPERTY = new HashMap<>(); static { @@ -54,30 +55,21 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { - return new JavaIsoVisitor() { + return Preconditions.check(new UsesMethod<>(GETENV), new JavaIsoVisitor() { @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { - if (GETENV.matches(method) - && method.getArguments().size() == 1 - && method.getArguments().get(0) instanceof J.Literal) { - - J.Literal arg = (J.Literal) method.getArguments().get(0); - - if (arg.getValue() instanceof String) { - String envVar = (String) arg.getValue(); - String replacementProperty = ENV_TO_PROPERTY.get(envVar); - - if (replacementProperty != null) { - maybeAddImport("java.lang.System"); - return JavaTemplate.builder("System.getProperty(\"" + replacementProperty + "\")") - .imports("java.lang.System") - .build() - .apply(updateCursor(method), method.getCoordinates().replace()); - } + if (GETENV.matches(method) && method.getArguments().get(0) instanceof J.Literal) { + String value = (String) ((J.Literal) method.getArguments().get(0)).getValue(); + String replacementProperty = ENV_TO_PROPERTY.get(value); + if (replacementProperty != null) { + return JavaTemplate.apply( + "System.getProperty(\"" + replacementProperty + "\")", + getCursor(), + method.getCoordinates().replace()); } } return super.visitMethodInvocation(method, ctx); } - }; + }); } } diff --git a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java index 5dd7a1c74d..33fa2408d4 100644 --- a/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenvTest.java @@ -17,11 +17,11 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; -import static org.openrewrite.java.Assertions.java; - import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; +import static org.openrewrite.java.Assertions.java; + class PreferSystemGetPropertyOverGetenvTest implements RewriteTest { @Override @@ -31,37 +31,36 @@ public void defaults(RecipeSpec spec) { @DocumentExample @Test -void replacesMultipleEnvVariables() { - rewriteRun( - java( - """ - class A { - void test() { - String user = System.getenv("USER"); - String username = System.getenv("USERNAME"); - String home = System.getenv("HOME"); - String profile = System.getenv("USERPROFILE"); - String temp = System.getenv("TEMP"); - String tmpdir = System.getenv("TMPDIR"); - String tmp = System.getenv("TMP"); - } - } - """, - """ - class A { - void test() { - String user = System.getProperty("user.name"); - String username = System.getProperty("user.name"); - String home = System.getProperty("user.home"); - String profile = System.getProperty("user.home"); - String temp = System.getProperty("java.io.tmpdir"); - String tmpdir = System.getProperty("java.io.tmpdir"); - String tmp = System.getProperty("java.io.tmpdir"); - } - } - """ - ) - ); -} - + void replacesMultipleEnvVariables() { + rewriteRun( + java( + """ + class A { + void test() { + String user = System.getenv("USER"); + String username = System.getenv("USERNAME"); + String home = System.getenv("HOME"); + String profile = System.getenv("USERPROFILE"); + String temp = System.getenv("TEMP"); + String tmpdir = System.getenv("TMPDIR"); + String tmp = System.getenv("TMP"); + } + } + """, + """ + class A { + void test() { + String user = System.getProperty("user.name"); + String username = System.getProperty("user.name"); + String home = System.getProperty("user.home"); + String profile = System.getProperty("user.home"); + String temp = System.getProperty("java.io.tmpdir"); + String tmpdir = System.getProperty("java.io.tmpdir"); + String tmp = System.getProperty("java.io.tmpdir"); + } + } + """ + ) + ); + } } From 1b86edd8d03c5d4f5bcb3b07d15c3aaf8e38854f Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 21 Aug 2025 13:01:17 +0200 Subject: [PATCH 7/8] Add markdown in displayName and description --- .../staticanalysis/PreferSystemGetPropertyOverGetenv.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java index 898b4037c9..e719662e13 100644 --- a/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java +++ b/src/main/java/org/openrewrite/staticanalysis/PreferSystemGetPropertyOverGetenv.java @@ -45,12 +45,12 @@ public class PreferSystemGetPropertyOverGetenv extends Recipe { @Override public String getDisplayName() { - return "Prefer System.getProperty(\"user.home\") over System.getenv(\"HOME\")"; + return "Prefer `System.getProperty(\"user.home\")` over `System.getenv(\"HOME\")`"; } @Override public String getDescription() { - return "Replaces System.getenv(\"HOME\") with System.getProperty(\"user.home\") for better portability."; + return "Replaces `System.getenv(\"HOME\")` with `System.getProperty(\"user.home\")` for better portability."; } @Override From bf7186038b65c640aec8519344d1ff18b6996ea1 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 21 Aug 2025 13:10:18 +0200 Subject: [PATCH 8/8] Add to common-static-analysis.yml --- src/main/resources/META-INF/rewrite/common-static-analysis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/META-INF/rewrite/common-static-analysis.yml b/src/main/resources/META-INF/rewrite/common-static-analysis.yml index d34c27af7e..d0fae71196 100644 --- a/src/main/resources/META-INF/rewrite/common-static-analysis.yml +++ b/src/main/resources/META-INF/rewrite/common-static-analysis.yml @@ -65,6 +65,7 @@ recipeList: - org.openrewrite.staticanalysis.NoToStringOnStringType - org.openrewrite.staticanalysis.NoValueOfOnStringType - org.openrewrite.staticanalysis.ObjectFinalizeCallsSuper + - org.openrewrite.staticanalysis.PreferSystemGetPropertyOverGetenv - org.openrewrite.staticanalysis.PrimitiveWrapperClassConstructorToValueOf - org.openrewrite.staticanalysis.RedundantFileCreation - org.openrewrite.staticanalysis.RemoveExtraSemicolons