Skip to content

Commit 13488b1

Browse files
committed
Introduce ErrorProne, fix compiler warnings
Signed-off-by: Stefano Cordio <[email protected]>
1 parent c6f88b8 commit 13488b1

File tree

173 files changed

+630
-693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+630
-693
lines changed

.mvn/jvm.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
2+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
3+
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
4+
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
5+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
6+
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
7+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
8+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
9+
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10+
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,40 @@
181181
<release>${java.version}</release>
182182
<compilerArgs>
183183
<compilerArg>-parameters</compilerArg>
184+
<!-- https://errorprone.info/docs/installation#maven -->
185+
<compilerArg>-XDcompilePolicy=simple</compilerArg>
186+
<compilerArg>--should-stop=ifError=FLOW</compilerArg>
187+
<compilerArg>
188+
-Xplugin:ErrorProne
189+
-Xep:CollectionUndefinedEquality:OFF
190+
-Xep:DefaultCharset:OFF
191+
-Xep:DirectInvocationOnMock:OFF
192+
-Xep:EqualsGetClass:OFF
193+
-Xep:Finally:OFF
194+
-Xep:HidingField:OFF
195+
-Xep:InlineMeSuggester:OFF
196+
-Xep:JavaTimeDefaultTimeZone:OFF
197+
-Xep:JdkObsolete:OFF
198+
-Xep:MissingSummary:OFF
199+
-Xep:MixedMutabilityReturnType:OFF
200+
-Xep:MutablePublicArray:OFF
201+
-Xep:NonAtomicVolatileUpdate:OFF
202+
-Xep:ReferenceEquality:OFF
203+
-Xep:StringCaseLocaleUsage:OFF
204+
-Xep:StringSplitter:OFF
205+
-Xep:SynchronizeOnNonFinalField:OFF
206+
-Xep:UndefinedEquals:OFF
207+
-Xep:UnnecessaryStringBuilder:OFF
208+
</compilerArg>
184209
</compilerArgs>
210+
<failOnWarning>true</failOnWarning>
211+
<annotationProcessorPaths>
212+
<path>
213+
<groupId>com.google.errorprone</groupId>
214+
<artifactId>error_prone_core</artifactId>
215+
<version>2.38.0</version>
216+
</path>
217+
</annotationProcessorPaths>
185218
</configuration>
186219
</plugin>
187220
<plugin>

spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public boolean equals(Object other) {
146146
@Override
147147
public int hashCode() {
148148
if (id == null) {
149-
return super.hashCode();
149+
return System.identityHashCode(this);
150150
}
151151
return 39 + 87 * id.hashCode();
152152
}

spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.io.ObjectInputStream;
21+
import java.time.Clock;
2122
import java.time.LocalDateTime;
2223
import java.util.ArrayList;
2324
import java.util.Collection;
@@ -203,7 +204,7 @@ public void upgradeStatus(BatchStatus status) {
203204
/**
204205
* Convenience getter for the {@code id} of the enclosing job. Useful for DAO
205206
* implementations.
206-
* @return the @{code id} of the enclosing job.
207+
* @return the {@code id} of the enclosing job.
207208
*/
208209
public Long getJobId() {
209210
if (jobInstance != null) {

spring-batch-core/src/main/java/org/springframework/batch/core/JobParameters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public String toString() {
373373
for (Map.Entry<String, JobParameter<?>> entry : this.parameters.entrySet()) {
374374
parameters.add(String.format("'%s':'%s'", entry.getKey(), entry.getValue()));
375375
}
376-
return new StringBuilder("{").append(String.join(",", parameters)).append("}").toString();
376+
return "{" + String.join(",", parameters) + "}";
377377
}
378378

379379
}

spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public boolean equals(Object obj) {
492492
return super.equals(obj);
493493
}
494494

495-
return stepName.equals(other.getStepName()) && (jobExecutionId.equals(other.getJobExecutionId()))
495+
return stepName.equals(other.getStepName()) && jobExecutionId.equals(other.getJobExecutionId())
496496
&& getId().equals(other.getId());
497497
}
498498

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchObservabilityBeanPostProcessor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
5050
try {
5151
if (bean instanceof AbstractJob || bean instanceof AbstractStep) {
5252
ObservationRegistry observationRegistry = this.beanFactory.getBean(ObservationRegistry.class);
53-
if (bean instanceof AbstractJob) {
54-
((AbstractJob) bean).setObservationRegistry(observationRegistry);
53+
if (bean instanceof AbstractJob job) {
54+
job.setObservationRegistry(observationRegistry);
5555
}
56-
if (bean instanceof AbstractStep) {
57-
((AbstractStep) bean).setObservationRegistry(observationRegistry);
56+
if (bean instanceof AbstractStep step) {
57+
step.setObservationRegistry(observationRegistry);
5858
}
5959
}
6060
}

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchRegistrar.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ class BatchRegistrar implements ImportBeanDefinitionRegistrar {
4848

4949
private static final Log LOGGER = LogFactory.getLog(BatchRegistrar.class);
5050

51-
private static final String MISSING_ANNOTATION_ERROR_MESSAGE = "EnableBatchProcessing is not present on importing class '%s' as expected";
52-
5351
private static final String JOB_REPOSITORY = "jobRepository";
5452

5553
private static final String JOB_REGISTRY = "jobRegistry";
@@ -77,7 +75,8 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
7775
private void validateState(AnnotationMetadata importingClassMetadata) {
7876
if (!importingClassMetadata.isAnnotated(EnableBatchProcessing.class.getName())) {
7977
String className = importingClassMetadata.getClassName();
80-
String errorMessage = String.format(MISSING_ANNOTATION_ERROR_MESSAGE, className);
78+
String errorMessage = "EnableBatchProcessing is not present on importing class '%s' as expected"
79+
.formatted(className);
8180
throw new IllegalStateException(errorMessage);
8281
}
8382
}

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AbstractApplicationContextFactory.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Arrays;
2121
import java.util.Collection;
22+
import java.util.Collections;
2223
import java.util.List;
2324

2425
import org.apache.commons.logging.Log;
@@ -196,13 +197,11 @@ protected void prepareContext(ConfigurableApplicationContext parent, Configurabl
196197
protected void prepareBeanFactory(ConfigurableListableBeanFactory parent,
197198
ConfigurableListableBeanFactory beanFactory) {
198199
if (copyConfiguration && parent != null) {
199-
List<BeanPostProcessor> parentPostProcessors = new ArrayList<>();
200-
List<BeanPostProcessor> childPostProcessors = new ArrayList<>();
201-
202-
childPostProcessors.addAll(beanFactory instanceof AbstractBeanFactory
203-
? ((AbstractBeanFactory) beanFactory).getBeanPostProcessors() : new ArrayList<>());
204-
parentPostProcessors.addAll(parent instanceof AbstractBeanFactory
205-
? ((AbstractBeanFactory) parent).getBeanPostProcessors() : new ArrayList<>());
200+
List<BeanPostProcessor> childPostProcessors = new ArrayList<>(
201+
beanFactory instanceof AbstractBeanFactory factory ? factory.getBeanPostProcessors()
202+
: new ArrayList<>());
203+
List<BeanPostProcessor> parentPostProcessors = new ArrayList<>(parent instanceof AbstractBeanFactory factory
204+
? factory.getBeanPostProcessors() : new ArrayList<>());
206205

207206
try {
208207
Class<?> applicationContextAwareProcessorClass = ClassUtils.forName(
@@ -237,8 +236,8 @@ protected void prepareBeanFactory(ConfigurableListableBeanFactory parent,
237236

238237
beanFactory.copyConfigurationFrom(parent);
239238

240-
List<BeanPostProcessor> beanPostProcessors = beanFactory instanceof AbstractBeanFactory
241-
? ((AbstractBeanFactory) beanFactory).getBeanPostProcessors() : new ArrayList<>();
239+
List<BeanPostProcessor> beanPostProcessors = beanFactory instanceof AbstractBeanFactory abstractBeanFactory
240+
? abstractBeanFactory.getBeanPostProcessors() : new ArrayList<>();
242241

243242
beanPostProcessors.clear();
244243
beanPostProcessors.addAll(aggregatedPostProcessors);

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/AutomaticJobRegistrar.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public void setApplicationContext(ApplicationContext applicationContext) {
7979
* use
8080
*/
8181
public void addApplicationContextFactory(ApplicationContextFactory applicationContextFactory) {
82-
if (applicationContextFactory instanceof ApplicationContextAware) {
83-
((ApplicationContextAware) applicationContextFactory).setApplicationContext(applicationContext);
82+
if (applicationContextFactory instanceof ApplicationContextAware applicationContextAware) {
83+
applicationContextAware.setApplicationContext(applicationContext);
8484
}
8585
this.applicationContextFactories.add(applicationContextFactory);
8686
}

0 commit comments

Comments
 (0)