Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b164024

Browse files
committed
Migrate spring-batch-infrastructure to JSpecify annotations
Signed-off-by: Stefano Cordio <stefano.cordio@gmail.com>
1 parent 0b61525 commit b164024

File tree

192 files changed

+1123
-934
lines changed

Some content is hidden

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

192 files changed

+1123
-934
lines changed

‎pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
159159
<spring-javaformat-maven-plugin.version>0.0.47</spring-javaformat-maven-plugin.version>
160160
<error-prone.version>2.41.0</error-prone.version>
161+
<nullaway.version>0.12.7</nullaway.version>
161162
</properties>
162163

163164
<build>
@@ -189,6 +190,10 @@
189190
<compilerArg>--should-stop=ifError=FLOW</compilerArg>
190191
<compilerArg>
191192
-Xplugin:ErrorProne
193+
<!-- Check JSpecify annotations -->
194+
-Xep:NullAway:ERROR
195+
-XepOpt:NullAway:OnlyNullMarked
196+
-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract
192197
</compilerArg>
193198
</compilerArgs>
194199
<annotationProcessorPaths>
@@ -197,6 +202,11 @@
197202
<artifactId>error_prone_core</artifactId>
198203
<version>${error-prone.version}</version>
199204
</path>
205+
<path>
206+
<groupId>com.uber.nullaway</groupId>
207+
<artifactId>nullaway</artifactId>
208+
<version>${nullaway.version}</version>
209+
</path>
200210
</annotationProcessorPaths>
201211
</configuration>
202212
</plugin>

‎spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.batch.item;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import java.io.Serializable;
2022
import java.util.ArrayList;
2123
import java.util.Arrays;
@@ -34,6 +36,7 @@
3436
* @author Dave Syer
3537
* @author Mahmoud Ben Hassine
3638
* @author Jinwoo Bae
39+
* @author Stefano Cordio
3740
* @since 2.0
3841
*/
3942
public class Chunk<W> implements Iterable<W>, Serializable {
@@ -44,7 +47,7 @@ public class Chunk<W> implements Iterable<W>, Serializable {
4447

4548
private final List<Exception> errors = new ArrayList<>();
4649

47-
private Object userData;
50+
private @NullableObject userData;
4851

4952
private boolean end;
5053

@@ -65,8 +68,7 @@ public Chunk(List<? extends W> items) {
6568
}
6669

6770
@Deprecated(since = "6.0", forRemoval = true)
68-
public Chunk(List<? extends W> items, List<SkipWrapper<W>> skips) {
69-
super();
71+
public Chunk(@Nullable List<? extends W> items, @Nullable List<SkipWrapper<W>> skips) {
7072
if (items != null) {
7173
this.items.addAll(items);
7274
}
@@ -218,7 +220,7 @@ public void clearSkips() {
218220
}
219221

220222
@Deprecated(since = "6.0", forRemoval = true)
221-
public Object getUserData() {
223+
public @NullableObject getUserData() {
222224
return userData;
223225
}
224226

@@ -266,9 +268,9 @@ public int hashCode() {
266268
*/
267269
public class ChunkIterator implements Iterator<W> {
268270

269-
finalprivate Iterator<W> iterator;
271+
privatefinal Iterator<W> iterator;
270272

271-
private W next;
273+
private @NullableW next;
272274

273275
public ChunkIterator(List<W> items) {
274276
iterator = items.iterator();

‎spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Set;
2424
import java.util.concurrent.ConcurrentHashMap;
2525

26-
import org.springframework.lang.Nullable;
26+
import org.jspecify.annotations.Nullable;
2727

2828
/**
2929
* Object representing a context for an {@link ItemStream}. It is a thin wrapper for a map
@@ -254,8 +254,7 @@ public double getDouble(String key, double defaultDouble) {
254254
* @return The value represented by the given key or {@code null} if the key is not
255255
* present
256256
*/
257-
@Nullable
258-
public Object get(String key) {
257+
public @Nullable Object get(String key) {
259258
return this.map.get(key);
260259
}
261260

@@ -269,8 +268,7 @@ public Object get(String key) {
269268
* key is not present
270269
* @since 5.1
271270
*/
272-
@Nullable
273-
public <V> V get(String key, Class<V> type) {
271+
public <V> @Nullable V get(String key, Class<V> type) {
274272
Object value = this.map.get(key);
275273
if (value == null) {
276274
return null;
@@ -289,8 +287,7 @@ public <V> V get(String key, Class<V> type) {
289287
* if the key is not present
290288
* @since 5.1
291289
*/
292-
@Nullable
293-
public <V> V get(String key, Class<V> type, @Nullable V defaultValue) {
290+
public <V> @Nullable V get(String key, Class<V> type, @Nullable V defaultValue) {
294291
Object value = this.map.get(key);
295292
if (value == null) {
296293
return defaultValue;
@@ -373,8 +370,7 @@ public boolean containsKey(String key) {
373370
*
374371
* @see java.util.Map#remove(Object)
375372
*/
376-
@Nullable
377-
public Object remove(String key) {
373+
public @Nullable Object remove(String key) {
378374
return this.map.remove(key);
379375
}
380376

‎spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemProcessor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.batch.item;
1818

19-
import org.springframework.lang.NonNull;
20-
import org.springframework.lang.Nullable;
19+
import org.jspecify.annotations.Nullable;
2120

2221
/**
2322
* Interface for item transformation. Given an item as input, this interface provides an
@@ -53,7 +52,6 @@ public interface ItemProcessor<I, O> {
5352
* processing of the provided item should not continue.
5453
* @throws Exception thrown if exception occurs during processing.
5554
*/
56-
@Nullable
57-
O process(@NonNull I item) throws Exception;
55+
@Nullable O process(I item) throws Exception;
5856

5957
}

‎spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemReader.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.batch.item;
1818

19-
import org.springframework.lang.Nullable;
19+
import org.jspecify.annotations.Nullable;
2020

2121
/**
2222
* Strategy interface for providing the data. <br>
@@ -57,7 +57,6 @@ public interface ItemReader<T> {
5757
* @throws Exception if an there is a non-specific error.
5858
* @return T the item to be processed or {@code null} if the data source is exhausted
5959
*/
60-
@Nullable
61-
T read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException;
60+
@Nullable T read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException;
6261

6362
}

‎spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStreamException.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
*/
1616
package org.springframework.batch.item;
1717

18+
import org.jspecify.annotations.Nullable;
19+
1820
/**
1921
* Exception representing any errors encountered while processing a stream.
2022
*
2123
* @author Dave Syer
2224
* @author Lucas Ward
2325
* @author Mahmoud Ben Hassine
26+
* @author Stefano Cordio
2427
*/
2528
public class ItemStreamException extends RuntimeException {
2629

@@ -33,11 +36,10 @@ public ItemStreamException(String message) {
3336

3437
/**
3538
* Constructs a new instance with a message and nested exception.
36-
* @param msg the exception message.
39+
* @param msg the exception message (can be {@code null}).
3740
* @param nested the cause of the exception.
38-
*
3941
*/
40-
public ItemStreamException(String msg, Throwable nested) {
42+
public ItemStreamException(@NullableString msg, Throwable nested) {
4143
super(msg, nested);
4244
}
4345

‎spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStreamSupport.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.batch.item;
1717

18+
import org.jspecify.annotations.Nullable;
1819
import org.springframework.batch.item.util.ExecutionContextUserSupport;
1920

2021
/**
@@ -23,6 +24,7 @@
2324
* @author Dave Syer
2425
* @author Dean de Bree
2526
* @author Mahmoud Ben Hassine
27+
* @author Stefano Cordio
2628
*
2729
*/
2830
public abstract class ItemStreamSupport implements ItemStream {
@@ -43,7 +45,7 @@ public void setName(String name) {
4345
* Get the name of the component
4446
* @return the name of the component
4547
*/
46-
public String getName() {
48+
public @NullableString getName() {
4749
return executionContextUserSupport.getName();
4850
}
4951

‎spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemWriter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.batch.item;
1818

19-
import org.springframework.lang.NonNull;
20-
2119
/**
2220
* <p>
2321
* Basic interface for generic output operations. Class implementing this interface will
@@ -48,6 +46,6 @@ public interface ItemWriter<T> {
4846
* @throws Exception if there are errors. The framework will catch the exception and
4947
* convert or rethrow it as appropriate.
5048
*/
51-
void write(@NonNullChunk<? extends T> chunk) throws Exception;
49+
void write(Chunk<? extends T> chunk) throws Exception;
5250

5351
}

‎spring-batch-infrastructure/src/main/java/org/springframework/batch/item/KeyValueItemWriter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package org.springframework.batch.item;
1414

15+
import org.jspecify.annotations.Nullable;
1516
import org.springframework.beans.factory.InitializingBean;
1617
import org.springframework.core.convert.converter.Converter;
1718
import org.springframework.util.Assert;
@@ -22,21 +23,20 @@
2223
*
2324
* @author David Turanski
2425
* @author Mahmoud Ben Hassine
26+
* @author Stefano Cordio
2527
* @since 2.2
2628
*
2729
*/
2830
public abstract class KeyValueItemWriter<K, V> implements ItemWriter<V>, InitializingBean {
2931

30-
protected Converter<V, K> itemKeyMapper;
32+
protected @NullableConverter<V, K> itemKeyMapper;
3133

3234
protected boolean delete;
3335

3436
@Override
35-
public void write(Chunk<? extends V> items) throws Exception {
36-
if (items == null) {
37-
return;
38-
}
39-
for (V item : items) {
37+
public void write(Chunk<? extends V> chunk) throws Exception {
38+
for (V item : chunk) {
39+
@SuppressWarnings({ "DataFlowIssue", "NullAway" })
4040
K key = itemKeyMapper.convert(item);
4141
writeKeyValue(key, item);
4242
}
@@ -55,7 +55,7 @@ protected void flush() throws Exception {
5555
* @param key the key
5656
* @param value the item
5757
*/
58-
protected abstract void writeKeyValue(K key, V value);
58+
protected abstract void writeKeyValue(@NullableK key, V value);
5959

6060
/**
6161
* afterPropertiesSet() hook

‎spring-batch-infrastructure/src/main/java/org/springframework/batch/item/PeekableItemReader.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.batch.item;
1717

18-
import org.springframework.lang.Nullable;
18+
import org.jspecify.annotations.Nullable;
1919

2020
/**
2121
* <p>
@@ -45,7 +45,6 @@ public interface PeekableItemReader<T> extends ItemReader<T> {
4545
* @return the next item or {@code null} if the data source is exhausted
4646
* @throws Exception if there is a problem
4747
*/
48-
@Nullable
49-
T peek() throws Exception, UnexpectedInputException, ParseException;
48+
@Nullable T peek() throws Exception, UnexpectedInputException, ParseException;
5049

5150
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /