diff --git a/build.gradle b/build.gradle index 7eb835918508..edad6a366e93 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ defaultTasks 'build' allprojects { group = "org.springframework.boot" + apply from: rootProject.file("gradle/error-prone.gradle") } subprojects { diff --git a/cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/AnsiString.java b/cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/AnsiString.java index a59a9755dd9f..81900c8ee042 100644 --- a/cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/AnsiString.java +++ b/cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/AnsiString.java @@ -55,7 +55,7 @@ AnsiString append(String text, Code... codes) { for (Code code : codes) { ansi = applyCode(ansi, code); } - this.value.append(ansi.a(text).reset().toString()); + this.value.append(ansi.a(text).reset()); return this; } diff --git a/core/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/Elements.java b/core/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/Elements.java index c307ac723fd6..d6ca40625a89 100644 --- a/core/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/Elements.java +++ b/core/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/Elements.java @@ -36,7 +36,7 @@ static String getQualifiedName(Element element) { TypeElement enclosingElement = getEnclosingTypeElement(element.asType()); if (enclosingElement != null) { return getQualifiedName(enclosingElement) + "$" - + ((DeclaredType) element.asType()).asElement().getSimpleName().toString(); + + ((DeclaredType) element.asType()).asElement().getSimpleName(); } if (element instanceof TypeElement typeElement) { return typeElement.getQualifiedName().toString(); diff --git a/core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/FilteredConfigurationPropertiesSource.java b/core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/FilteredConfigurationPropertiesSource.java index bfc33fb13ea2..b4dbd419d24a 100644 --- a/core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/FilteredConfigurationPropertiesSource.java +++ b/core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/FilteredConfigurationPropertiesSource.java @@ -73,7 +73,7 @@ protected Predicate getFilter() { @Override public String toString() { - return this.source.toString() + " (filtered)"; + return this.source + " (filtered)"; } } diff --git a/gradle/error-prone.gradle b/gradle/error-prone.gradle new file mode 100644 index 000000000000..d76ea3cf2a72 --- /dev/null +++ b/gradle/error-prone.gradle @@ -0,0 +1,21 @@ +import static java.lang.System.getenv + +apply plugin: "net.ltgt.errorprone" + +dependencies { + errorprone("com.google.errorprone:error_prone_core:2.42.0") + errorprone("tech.picnic.error-prone-support:error-prone-contrib:0.25.0") +} + +tasks.withType(JavaCompile).configureEach { + options.errorprone { + disableAllChecks = true + error("RedundantStringConversion") + if (!getenv().containsKey("CI") && getenv("IN_PLACE")?.toBoolean()) { + errorproneArgs.addAll( + "-XepPatchLocation:IN_PLACE", + "-XepPatchChecks:RedundantStringConversion" + ) + } + } +} diff --git a/module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/PlainTextThreadDumpFormatter.java b/module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/PlainTextThreadDumpFormatter.java index 398bcf103b7b..55e0f65fa8f3 100644 --- a/module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/PlainTextThreadDumpFormatter.java +++ b/module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/PlainTextThreadDumpFormatter.java @@ -77,7 +77,7 @@ private List lockedMonitorsForDepth(MonitorInfo[] lockedMonitors, i private void writeStackTraceElement(PrintWriter writer, StackTraceElement element, ThreadInfo info, List lockedMonitors, boolean firstElement) { - writer.printf("\tat %s%n", element.toString()); + writer.printf("\tat %s%n", element); LockInfo lockInfo = info.getLockInfo(); if (firstElement && lockInfo != null) { if (element.getClassName().equals(Object.class.getName()) && element.getMethodName().equals("wait")) {