Skip to content

Commit 18dd907

Browse files
committed
Introduce ErrorProne, fix compiler warnings
Signed-off-by: Stefano Cordio <[email protected]>
1 parent 2bd5b84 commit 18dd907

28 files changed

+112
-98
lines changed

Diff for: .mvn/jvm.config

+10
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

Diff for: pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,19 @@
180180
<release>${java.version}</release>
181181
<compilerArgs>
182182
<compilerArg>-parameters</compilerArg>
183+
<!-- https://errorprone.info/docs/installation#maven -->
184+
<compilerArg>-XDcompilePolicy=simple</compilerArg>
185+
<compilerArg>--should-stop=ifError=FLOW</compilerArg>
186+
<compilerArg>-Xplugin:ErrorProne -Xep:NonAtomicVolatileUpdate:OFF</compilerArg>
183187
</compilerArgs>
188+
<failOnWarning>true</failOnWarning>
189+
<annotationProcessorPaths>
190+
<path>
191+
<groupId>com.google.errorprone</groupId>
192+
<artifactId>error_prone_core</artifactId>
193+
<version>2.37.0</version>
194+
</path>
195+
</annotationProcessorPaths>
184196
</configuration>
185197
</plugin>
186198
<plugin>

Diff for: spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeItemReadListenerTests.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import static org.mockito.Mockito.mock;
1919

20-
import java.util.ArrayList;
20+
import java.util.List;
2121

2222
import org.junit.jupiter.api.BeforeEach;
2323
import org.junit.jupiter.api.Test;
@@ -67,11 +67,7 @@ void testOnReadError() {
6767

6868
@Test
6969
void testSetListeners() {
70-
compositeListener.setListeners(new ArrayList<>() {
71-
{
72-
add(listener);
73-
}
74-
});
70+
compositeListener.setListeners(List.of(listener));
7571
listener.beforeRead();
7672
compositeListener.beforeRead();
7773
}

Diff for: spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeItemWriteListenerTests.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.batch.core.listener;
1717

18-
import java.util.ArrayList;
18+
import java.util.List;
1919

2020
import org.junit.jupiter.api.BeforeEach;
2121
import org.junit.jupiter.api.Test;
@@ -69,11 +69,7 @@ void testOnWriteError() {
6969

7070
@Test
7171
void testSetListeners() {
72-
compositeListener.setListeners(new ArrayList<>() {
73-
{
74-
add(listener);
75-
}
76-
});
72+
compositeListener.setListeners(List.of(listener));
7773
Chunk<Object> item = Chunk.of(new Object());
7874
listener.beforeWrite(item);
7975
compositeListener.beforeWrite(item);

Diff for: spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapperTests.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,13 @@ class ConfigurableSystemProcessExitCodeMapperTests {
3636
*/
3737
@Test
3838
void testMapping() {
39-
Map<Object, ExitStatus> mappings = new HashMap<>() {
40-
{
41-
put(0, ExitStatus.COMPLETED);
42-
put(1, ExitStatus.FAILED);
43-
put(2, ExitStatus.EXECUTING);
44-
put(3, ExitStatus.NOOP);
45-
put(4, ExitStatus.UNKNOWN);
46-
put(ConfigurableSystemProcessExitCodeMapper.ELSE_KEY, ExitStatus.UNKNOWN);
47-
}
48-
};
39+
Map<Object, ExitStatus> mappings = Map.of( //
40+
0, ExitStatus.COMPLETED, //
41+
1, ExitStatus.FAILED, //
42+
2, ExitStatus.EXECUTING, //
43+
3, ExitStatus.NOOP, //
44+
4, ExitStatus.UNKNOWN, //
45+
ConfigurableSystemProcessExitCodeMapper.ELSE_KEY, ExitStatus.UNKNOWN);
4946

5047
mapper.setMappings(mappings);
5148

Diff for: spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
/**
2828
* Encapsulation of a list of items to be processed and possibly a list of failed items to
29-
* be skipped. To mark an item as skipped clients should iterate over the chunk using the
29+
* be skipped. To mark an item as skipped, clients should iterate over the chunk using the
3030
* {@link #iterator()} method, and if there is a failure call
3131
* {@link Chunk.ChunkIterator#remove()} on the iterator. The skipped items are then
3232
* available through the chunk.
@@ -100,21 +100,21 @@ public void clear() {
100100
}
101101

102102
/**
103-
* @return a copy of the items to be processed as an unmodifiable list
103+
* Return a copy of the items to be processed as an unmodifiable list.
104104
*/
105105
public List<W> getItems() {
106106
return Collections.unmodifiableList(items);
107107
}
108108

109109
/**
110-
* @return a copy of the skips as an unmodifiable list
110+
* Return a copy of the skips as an unmodifiable list.
111111
*/
112112
public List<SkipWrapper<W>> getSkips() {
113113
return Collections.unmodifiableList(skips);
114114
}
115115

116116
/**
117-
* @return a copy of the anonymous errors as an unmodifiable list
117+
* Return a copy of the anonymous errors as an unmodifiable list.
118118
*/
119119
public List<Exception> getErrors() {
120120
return Collections.unmodifiableList(errors);
@@ -130,7 +130,7 @@ public void skip(Exception e) {
130130
}
131131

132132
/**
133-
* @return true if there are no items in the chunk
133+
* Return {@code true} if there are no items in the chunk.
134134
*/
135135
public boolean isEmpty() {
136136
return items.isEmpty();
@@ -146,7 +146,7 @@ public ChunkIterator iterator() {
146146
}
147147

148148
/**
149-
* @return the number of items (excluding skips)
149+
* Returns the number of items (excluding skips).
150150
*/
151151
public int size() {
152152
return items.size();

Diff for: spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java

+13-15
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import org.springframework.util.StringUtils;
3030

3131
/**
32-
* Superclass for delegating classes which dynamically call a custom method of injected
33-
* object. Provides convenient API for dynamic method invocation shielding subclasses from
34-
* low-level details and exception handling.
32+
* Superclass for delegating classes which dynamically call a custom method of an injected
33+
* object. Provides a convenient API for dynamic method invocation shielding subclasses
34+
* from low-level details and exception handling.
3535
* <p>
3636
* {@link Exception}s thrown by a successfully invoked delegate method are re-thrown
3737
* without wrapping. In case the delegate method throws a {@link Throwable} that doesn't
@@ -164,7 +164,7 @@ private boolean targetClassDeclaresTargetMethod() {
164164
if (arguments[j] == null) {
165165
continue;
166166
}
167-
if (!(ClassUtils.isAssignableValue(params[j], arguments[j]))) {
167+
if (!ClassUtils.isAssignableValue(params[j], arguments[j])) {
168168
argumentsMatchParameters = false;
169169
}
170170
}
@@ -179,24 +179,23 @@ private boolean targetClassDeclaresTargetMethod() {
179179
}
180180

181181
/**
182-
* @param targetObject the delegate - bean id can be used to set this value in Spring
183-
* configuration
182+
* Set the delegate - bean id can be used to set this value in Spring configuration.
184183
*/
185184
public void setTargetObject(Object targetObject) {
186185
this.targetObject = targetObject;
187186
}
188187

189188
/**
190-
* @param targetMethod name of the method to be invoked on
191-
* {@link #setTargetObject(Object)}.
189+
* Set the name of the method to be invoked on {@link #setTargetObject(Object)}.
192190
*/
193191
public void setTargetMethod(String targetMethod) {
194192
this.targetMethod = targetMethod;
195193
}
196194

197195
/**
198-
* @param arguments arguments values for the { {@link #setTargetMethod(String)}. These
199-
* will be used only when the subclass tries to invoke the target method without
196+
* Set the argument values for the {@link #setTargetMethod(String)}.
197+
* <p>
198+
* These will be used only when the subclass tries to invoke the target method without
200199
* providing explicit argument values.
201200
* <p>
202201
* If arguments are set to not-null value {@link #afterPropertiesSet()} will check the
@@ -205,27 +204,26 @@ public void setTargetMethod(String targetMethod) {
205204
* will be supplied at runtime.
206205
*/
207206
public void setArguments(Object[] arguments) {
208-
this.arguments = arguments == null ? null : Arrays.asList(arguments).toArray();
207+
this.arguments = arguments == null ? null : arguments.clone();
209208
}
210209

211210
/**
212-
* Return arguments.
213-
* @return arguments
211+
* Return the argument values for the method to be invoked.
214212
*/
215213
protected Object[] getArguments() {
216214
return arguments;
217215
}
218216

219217
/**
220-
* @return the object on which the method will be invoked.
218+
* Return the object on which the method will be invoked.
221219
* @since 5.1
222220
*/
223221
protected Object getTargetObject() {
224222
return targetObject;
225223
}
226224

227225
/**
228-
* @return the name of the method to be invoked.
226+
* Return the name of the method to be invoked.
229227
* @since 5.1
230228
*/
231229
protected String getTargetMethod() {

Diff for: spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ public void afterPropertiesSet() throws Exception {
7272
}
7373

7474
/**
75-
* @param fieldsUsedAsMethodArguments the values of the these item's fields will be
76-
* used as arguments for the delegate method. Nested property values are supported,
77-
* e.g. <code>address.city</code>
75+
* Sets the values of the item's fields to be used as arguments for the delegate
76+
* method.
77+
* <p>
78+
* Nested property values are supported, e.g. <code>address.city</code>
7879
*/
7980
public void setFieldsUsedAsTargetMethodArguments(String[] fieldsUsedAsMethodArguments) {
80-
this.fieldsUsedAsTargetMethodArguments = Arrays.asList(fieldsUsedAsMethodArguments)
81-
.toArray(new String[fieldsUsedAsMethodArguments.length]);
81+
this.fieldsUsedAsTargetMethodArguments = fieldsUsedAsMethodArguments.clone();
8282
}
8383

8484
}

Diff for: spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/builder/AvroItemReaderBuilder.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.springframework.util.Assert;
2525
import org.springframework.util.StringUtils;
2626

27+
import java.nio.charset.Charset;
28+
2729
/**
2830
* A builder implementation for the {@link AvroItemReader}.
2931
*
@@ -80,7 +82,7 @@ public AvroItemReaderBuilder<T> schema(Resource schema) {
8082
*/
8183
public AvroItemReaderBuilder<T> schema(String schemaString) {
8284
Assert.hasText(schemaString, "A 'schema' is required.");
83-
this.schema = new ByteArrayResource(schemaString.getBytes());
85+
this.schema = new ByteArrayResource(schemaString.getBytes(Charset.defaultCharset()));
8486
return this;
8587
}
8688

Diff for: spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/builder/AvroItemWriterBuilder.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.springframework.core.io.WritableResource;
2323
import org.springframework.util.Assert;
2424

25+
import java.nio.charset.Charset;
26+
2527
/**
2628
* A builder implementation for the {@link AvroItemWriter}.
2729
*
@@ -40,7 +42,8 @@ public class AvroItemWriterBuilder<T> {
4042
private String name = AvroItemWriter.class.getSimpleName();
4143

4244
/**
43-
* @param resource the {@link WritableResource} used to write the serialized data.
45+
* Sets the {@link WritableResource} used to write the serialized data.
46+
* @param resource the {@code WritableResource} used to write the serialized data.
4447
* @return The current instance of the builder.
4548
*/
4649
public AvroItemWriterBuilder<T> resource(WritableResource resource) {
@@ -50,7 +53,9 @@ public AvroItemWriterBuilder<T> resource(WritableResource resource) {
5053
}
5154

5255
/**
53-
* @param schema the Resource containing the schema JSON used to serialize the output.
56+
* Sets the {@link Resource} containing the schema JSON used to serialize the output.
57+
* @param schema the {@code Resource} containing the schema JSON used to serialize the
58+
* output.
5459
* @return The current instance of the builder.
5560
*/
5661
public AvroItemWriterBuilder<T> schema(Resource schema) {
@@ -61,17 +66,19 @@ public AvroItemWriterBuilder<T> schema(Resource schema) {
6166
}
6267

6368
/**
69+
* Sets the String containing the schema JSON used to serialize the output.
6470
* @param schemaString the String containing the schema JSON used to serialize the
6571
* output.
6672
* @return The current instance of the builder.
6773
*/
6874
public AvroItemWriterBuilder<T> schema(String schemaString) {
6975
Assert.hasText(schemaString, "A 'schemaString' is required.");
70-
this.schema = new ByteArrayResource(schemaString.getBytes());
76+
this.schema = new ByteArrayResource(schemaString.getBytes(Charset.defaultCharset()));
7177
return this;
7278
}
7379

7480
/**
81+
* Sets the Class of objects to be serialized.
7582
* @param type the Class of objects to be serialized.
7683
* @return The current instance of the builder.
7784
*/

Diff for: spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoCursorItemReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void setTargetType(Class<? extends T> targetType) {
101101
}
102102

103103
/**
104-
* @param collection Mongo collection to be queried.
104+
* The Mongo collection to be queried.
105105
*/
106106
public void setCollection(String collection) {
107107
this.collection = collection;

Diff for: spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void setSort(Map<String, Sort.Direction> sorts) {
172172
}
173173

174174
/**
175-
* @param collection Mongo collection to be queried.
175+
* The Mongo collection to be queried.
176176
*/
177177
public void setCollection(String collection) {
178178
this.collection = collection;

Diff for: spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemWriter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public MongoItemWriter() {
107107
*/
108108
@Deprecated(since = "5.1", forRemoval = true)
109109
public void setDelete(boolean delete) {
110-
this.mode = (delete) ? Mode.REMOVE : Mode.UPSERT;
110+
this.mode = delete ? Mode.REMOVE : Mode.UPSERT;
111111
}
112112

113113
/**

Diff for: spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoPagingItemReader.java

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
* @author Mahmoud Ben Hassine
6868
* @author Parikshit Dutta
6969
*/
70+
@SuppressWarnings("removal")
7071
public class MongoPagingItemReader<T> extends MongoItemReader<T> {
7172

7273
/**

Diff for: spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemReader.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
/**
4545
* <p>
4646
* A {@link org.springframework.batch.item.ItemReader} that reads records utilizing a
47-
* {@link org.springframework.data.repository.PagingAndSortingRepository}.
47+
* {@link PagingAndSortingRepository}.
4848
* </p>
4949
*
5050
* <p>
@@ -55,7 +55,7 @@
5555
*
5656
* <p>
5757
* The reader must be configured with a
58-
* {@link org.springframework.data.repository.PagingAndSortingRepository}, a
58+
* {@link PagingAndSortingRepository}, a
5959
* {@link org.springframework.data.domain.Sort}, and a pageSize greater than 0.
6060
* </p>
6161
*
@@ -127,15 +127,14 @@ public void setSort(Map<String, Sort.Direction> sorts) {
127127
}
128128

129129
/**
130-
* @param pageSize The number of items to retrieve per page. Must be greater than 0.
130+
* The number of items to retrieve per page. Must be greater than 0.
131131
*/
132132
public void setPageSize(int pageSize) {
133133
this.pageSize = pageSize;
134134
}
135135

136136
/**
137-
* The {@link org.springframework.data.repository.PagingAndSortingRepository}
138-
* implementation used to read input from.
137+
* The {@link PagingAndSortingRepository} implementation used to read input from.
139138
* @param repository underlying repository for input to be read from.
140139
*/
141140
public void setRepository(PagingAndSortingRepository<?, ?> repository) {

0 commit comments

Comments
 (0)