Skip to content

Commit c997379

Browse files
authored
[openrewrite] add EqualsAvoidsNull (#2650 progress on #2634)
2 parents 0835e61 + a90410c commit c997379

File tree

26 files changed

+77
-66
lines changed

26 files changed

+77
-66
lines changed

.github/workflows/claude.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
script: |
2424
try {
2525
// Get username - prioritize sender (the person who triggered the event)
26-
const username = github.event.sender?.login ||
27-
github.event.comment?.user?.login;
26+
const username = github.event?.sender?.login ||
27+
github.event?.comment?.user?.login;
2828
2929
if (!username) {
3030
console.log('Could not determine username from event payload');

gradle/rewrite.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,26 @@ rewrite {
44
activeRecipe(
55
'org.openrewrite.gradle.GradleBestPractices',
66
'org.openrewrite.java.RemoveUnusedImports',
7+
'org.openrewrite.java.format.RemoveTrailingWhitespace',
78
'org.openrewrite.java.migrate.UpgradeToJava17',
89
'org.openrewrite.java.recipes.JavaRecipeBestPractices',
910
'org.openrewrite.java.recipes.RecipeTestingBestPractices',
1011
'org.openrewrite.java.security.JavaSecurityBestPractices',
12+
'org.openrewrite.staticanalysis.EqualsAvoidsNull',
1113
'org.openrewrite.staticanalysis.JavaApiBestPractices',
1214
'org.openrewrite.staticanalysis.LowercasePackage',
1315
'org.openrewrite.staticanalysis.MissingOverrideAnnotation',
1416
'org.openrewrite.staticanalysis.ModifierOrder',
1517
'org.openrewrite.staticanalysis.NoFinalizer',
18+
'org.openrewrite.staticanalysis.NoToStringOnStringType',
19+
'org.openrewrite.staticanalysis.NoValueOfOnStringType',
1620
'org.openrewrite.staticanalysis.RemoveUnusedLocalVariables',
1721
'org.openrewrite.staticanalysis.RemoveUnusedPrivateFields',
1822
'org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods',
23+
'org.openrewrite.staticanalysis.UnnecessaryCloseInTryWithResources',
24+
'org.openrewrite.staticanalysis.UnnecessaryExplicitTypeArguments',
25+
'org.openrewrite.staticanalysis.UnnecessaryParentheses',
26+
'org.openrewrite.staticanalysis.UnnecessaryReturnAsLastStatement',
1927
'tech.picnic.errorprone.refasterrules.BigDecimalRulesRecipes',
2028
'tech.picnic.errorprone.refasterrules.CharSequenceRulesRecipes',
2129
'tech.picnic.errorprone.refasterrules.ClassRulesRecipes',
@@ -28,6 +36,9 @@ rewrite {
2836
'tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes',
2937
'tech.picnic.errorprone.refasterrules.StreamRulesRecipes',
3038
'tech.picnic.errorprone.refasterrules.TimeRulesRecipes'
39+
//'org.openrewrite.staticanalysis.CodeCleanup', bug
40+
//'org.openrewrite.staticanalysis.CommonStaticAnalysis', bug
41+
//'org.openrewrite.staticanalysis.UnnecessaryThrows', bug
3142
)
3243
exclusions.addAll(
3344
'**_gradle_node_plugin_example_**',

lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/DefaultJavaElementComparator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 DiffPlug
2+
* Copyright 2024-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -368,8 +368,8 @@ private boolean isSortPreserved(BodyDeclaration bodyDeclaration) {
368368
}
369369

370370
private int preserveRelativeOrder(BodyDeclaration bodyDeclaration1, BodyDeclaration bodyDeclaration2) {
371-
int value1 = ((Integer) bodyDeclaration1.getProperty(CompilationUnitSorter.RELATIVE_ORDER));
372-
int value2 = ((Integer) bodyDeclaration2.getProperty(CompilationUnitSorter.RELATIVE_ORDER));
371+
int value1 = (Integer) bodyDeclaration1.getProperty(CompilationUnitSorter.RELATIVE_ORDER);
372+
int value2 = (Integer) bodyDeclaration2.getProperty(CompilationUnitSorter.RELATIVE_ORDER);
373373
return value1 - value2;
374374
}
375375

lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/JdtFlags.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 DiffPlug
2+
* Copyright 2024-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ && isInterfaceOrAnnotationMember(bodyDeclaration))
4848
}
4949

5050
private static boolean isPackageVisible(BodyDeclaration bodyDeclaration) {
51-
return (!isPrivate(bodyDeclaration) && !isProtected(bodyDeclaration) && !isPublic(bodyDeclaration));
51+
return !isPrivate(bodyDeclaration) && !isProtected(bodyDeclaration) && !isPublic(bodyDeclaration);
5252
}
5353

5454
private static boolean isPrivate(BodyDeclaration bodyDeclaration) {

lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static class CachedEndings implements Serializable {
154154

155155
CachedEndings(File projectDir, Runtime runtime, Iterable<File> toFormat) {
156156
String rootPath = FileSignature.pathNativeToUnix(projectDir.getAbsolutePath());
157-
rootDir = rootPath.equals("/") ? rootPath : rootPath + "/";
157+
rootDir = "/".equals(rootPath) ? rootPath : rootPath + "/";
158158
defaultEnding = runtime.defaultEnding;
159159
for (File file : toFormat) {
160160
String ending = runtime.getEndingFor(file);

lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce
6969
return (String) method.invoke(formatter, input);
7070
} catch (InvocationTargetException exceptionWrapper) {
7171
Throwable throwable = exceptionWrapper.getTargetException();
72-
Exception exception = (throwable instanceof Exception e) ? e : null;
73-
throw (null == exception) ? exceptionWrapper : exception;
72+
Exception exception = throwable instanceof Exception e ? e : null;
73+
throw null == exception ? exceptionWrapper : exception;
7474
}
7575
});
7676
}

lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce
9797
return (String) method.invoke(formatter, input);
9898
} catch (InvocationTargetException exceptionWrapper) {
9999
Throwable throwable = exceptionWrapper.getTargetException();
100-
Exception exception = (throwable instanceof Exception e) ? e : null;
101-
throw (null == exception) ? exceptionWrapper : exception;
100+
Exception exception = throwable instanceof Exception e ? e : null;
101+
throw null == exception ? exceptionWrapper : exception;
102102
}
103103
});
104104
}

lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ private static FormatterFunc applyWithoutFile(String className, EclipseBasedStep
6767
return (String) method.invoke(formatter, input);
6868
} catch (InvocationTargetException exceptionWrapper) {
6969
Throwable throwable = exceptionWrapper.getTargetException();
70-
Exception exception = (throwable instanceof Exception e) ? e : null;
71-
throw (null == exception) ? exceptionWrapper : exception;
70+
Exception exception = throwable instanceof Exception e ? e : null;
71+
throw null == exception ? exceptionWrapper : exception;
7272
}
7373
};
7474
}
@@ -85,8 +85,8 @@ public String applyWithFile(String unix, File file) throws Exception {
8585
return (String) method.invoke(formatter, unix, file.getAbsolutePath());
8686
} catch (InvocationTargetException exceptionWrapper) {
8787
Throwable throwable = exceptionWrapper.getTargetException();
88-
Exception exception = (throwable instanceof Exception e) ? e : null;
89-
throw (null == exception) ? exceptionWrapper : exception;
88+
Exception exception = throwable instanceof Exception e ? e : null;
89+
throw null == exception ? exceptionWrapper : exception;
9090
}
9191
}
9292
});

lib/src/main/java/com/diffplug/spotless/FormatterProperties.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static FormatterProperties fromXmlContent(final Iterable<String> content)
114114

115115
public static FormatterProperties merge(Properties... properties) {
116116
FormatterProperties merged = new FormatterProperties();
117-
List.of(properties).forEach((source) -> merged.properties.putAll(source));
117+
List.of(properties).forEach(source -> merged.properties.putAll(source));
118118
return merged;
119119
}
120120

@@ -300,7 +300,7 @@ protected Properties execute(InputStream file, Node rootNode) throws IOException
300300
* A missing value is interpreted as an empty string,
301301
* similar to the Properties behavior
302302
*/
303-
String valString = (null == value) ? "" : value.getNodeValue();
303+
String valString = null == value ? "" : value.getNodeValue();
304304
properties.setProperty(idString, valString);
305305
}
306306
return properties;
@@ -332,7 +332,7 @@ private List<Node> getChildren(final Node node, final String nodeName) {
332332

333333
private static String getProfileName(Node profile) {
334334
Node nameAttribute = profile.getAttributes().getNamedItem("name");
335-
return (null == nameAttribute) ? "" : nameAttribute.getNodeValue();
335+
return null == nameAttribute ? "" : nameAttribute.getNodeValue();
336336
}
337337

338338
private final String rootNodeName;

lib/src/main/java/com/diffplug/spotless/Jvm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ private void verifyVersionRangesDoNotIntersect(NavigableMap<Integer, V> jvm2fmtV
122122
/** @return Highest formatter version recommended for this JVM (null, if JVM not supported) */
123123
@Nullable public V getRecommendedFormatterVersion() {
124124
Integer configuredJvmVersionOrNull = jvm2fmtMaxVersion.floorKey(Jvm.version());
125-
return (null == configuredJvmVersionOrNull) ? null : jvm2fmtMaxVersion.get(configuredJvmVersionOrNull);
125+
return null == configuredJvmVersionOrNull ? null : jvm2fmtMaxVersion.get(configuredJvmVersionOrNull);
126126
}
127127

128128
@Nullable public V getMinimumRequiredFormatterVersion() {
129129
Integer configuredJvmVersionOrNull = jvm2fmtMinVersion.floorKey(Jvm.version());
130-
return (null == configuredJvmVersionOrNull) ? null : jvm2fmtMinVersion.get(configuredJvmVersionOrNull);
130+
return null == configuredJvmVersionOrNull ? null : jvm2fmtMinVersion.get(configuredJvmVersionOrNull);
131131
}
132132

133133
/**

0 commit comments

Comments
 (0)