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 35c9da1

Browse files
committed
Fix NullAway findings
Signed-off-by: Stefano Cordio <stefano.cordio@gmail.com>
1 parent e87e1f5 commit 35c9da1

31 files changed

+187
-108
lines changed

‎pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
<!-- Check JSpecify annotations -->
192192
-Xep:NullAway:ERROR
193193
-XepOpt:NullAway:OnlyNullMarked
194+
-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract
194195
</compilerArg>
195196
</compilerArgs>
196197
<annotationProcessorPaths>

‎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

@@ -64,8 +67,7 @@ public Chunk(List<? extends W> items) {
6467
this(items, null);
6568
}
6669

67-
public Chunk(List<? extends W> items, List<SkipWrapper<W>> skips) {
68-
super();
70+
public Chunk(@Nullable List<? extends W> items, @Nullable List<SkipWrapper<W>> skips) {
6971
if (items != null) {
7072
this.items.addAll(items);
7173
}
@@ -200,7 +202,7 @@ public void clearSkips() {
200202
skips.clear();
201203
}
202204

203-
public Object getUserData() {
205+
public @NullableObject getUserData() {
204206
return userData;
205207
}
206208

@@ -247,9 +249,9 @@ public int hashCode() {
247249
*/
248250
public class ChunkIterator implements Iterator<W> {
249251

250-
finalprivate Iterator<W> iterator;
252+
privatefinal Iterator<W> iterator;
251253

252-
private W next;
254+
private @NullableW next;
253255

254256
public ChunkIterator(List<W> items) {
255257
iterator = items.iterator();

‎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/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/SkipWrapper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
*
2424
* @author Dave Syer
2525
* @author Mahmoud Ben Hassine
26+
* @author Stefano Cordio
2627
*
2728
*/
2829
public class SkipWrapper<T> {
2930

30-
final private Throwable exception;
31+
privatefinal @Nullable Throwable exception;
3132

32-
final private T item;
33+
privatefinal @Nullable T item;
3334

3435
/**
3536
* @param item the item being wrapped.
@@ -38,7 +39,7 @@ public SkipWrapper(T item) {
3839
this(item, null);
3940
}
4041

41-
public SkipWrapper(T item, @Nullable Throwable e) {
42+
public SkipWrapper(@NullableT item, @Nullable Throwable e) {
4243
this.item = item;
4344
this.exception = e;
4445
}
@@ -55,7 +56,7 @@ public SkipWrapper(T item, @Nullable Throwable e) {
5556
* Public getter for the item.
5657
* @return the item
5758
*/
58-
public T getItem() {
59+
public @NullableT getItem() {
5960
return item;
6061
}
6162

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

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

15+
import org.jspecify.annotations.Nullable;
1516
import org.springframework.core.convert.converter.Converter;
1617
import org.springframework.expression.Expression;
17-
import org.springframework.expression.ExpressionParser;
1818
import org.springframework.expression.spel.standard.SpelExpressionParser;
1919

2020
/**
2121
* An implementation of {@link Converter} that uses SpEL to map a Value to a key
2222
*
2323
* @author David Turanski
24+
* @author Stefano Cordio
2425
* @since 2.2
2526
*/
2627
public class SpELItemKeyMapper<K, V> implements Converter<V, K> {
2728

28-
private final ExpressionParser parser = new SpelExpressionParser();
29-
3029
private final Expression parsedExpression;
3130

3231
public SpELItemKeyMapper(String keyExpression) {
33-
parsedExpression = parser.parseExpression(keyExpression);
32+
parsedExpression = newSpelExpressionParser().parseExpression(keyExpression);
3433
}
3534

3635
@SuppressWarnings("unchecked")
3736
@Override
38-
public K convert(V item) {
37+
public @NullableK convert(V item) {
3938
return (K) parsedExpression.getValue(item);
4039
}
4140

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Arrays;
2323
import java.util.List;
2424

25+
import org.jspecify.annotations.Nullable;
2526
import org.springframework.beans.factory.InitializingBean;
2627
import org.springframework.util.Assert;
2728
import org.springframework.util.ClassUtils;
@@ -41,12 +42,13 @@
4142
* @author Robert Kasanicky
4243
* @author Mahmoud Ben Hassine
4344
* @author Glenn Renfro
45+
* @author Stefano Cordio
4446
*/
4547
public abstract class AbstractMethodInvokingDelegator<T> implements InitializingBean {
4648

47-
private Object targetObject;
49+
private @NullableObject targetObject;
4850

49-
private String targetMethod;
51+
private @NullableString targetMethod;
5052

5153
private Object[] arguments;
5254

@@ -88,7 +90,7 @@ protected T invokeDelegateMethodWithArguments(Object[] args) throws Exception {
8890
/**
8991
* Create a new configured instance of {@link MethodInvoker}.
9092
*/
91-
private MethodInvoker createMethodInvoker(Object targetObject, String targetMethod) {
93+
private MethodInvoker createMethodInvoker(@NullableObject targetObject,@Nullable String targetMethod) {
9294
HippyMethodInvoker invoker = new HippyMethodInvoker();
9395
invoker.setTargetObject(targetObject);
9496
invoker.setTargetMethod(targetMethod);
@@ -220,15 +222,15 @@ protected Object[] getArguments() {
220222
* @return the object on which the method will be invoked.
221223
* @since 5.1
222224
*/
223-
protected Object getTargetObject() {
225+
protected @NullableObject getTargetObject() {
224226
return targetObject;
225227
}
226228

227229
/**
228230
* @return the name of the method to be invoked.
229231
* @since 5.1
230232
*/
231-
protected String getTargetMethod() {
233+
protected @NullableString getTargetMethod() {
232234
return targetMethod;
233235
}
234236

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
/**
2525
* A {@link MethodInvoker} that is a bit relaxed about its arguments. You can give it
26-
* arguments in the wrong order or you can give it too many arguments and it will try and
27-
* find a method that matches a subset.
26+
* arguments in the wrong order, or you can give it too many arguments, and it will try
27+
* and find a method that matches a subset.
2828
*
2929
* @author Dave Syer
3030
* @since 2.1

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

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

1717
package org.springframework.batch.item.adapter;
1818

19-
import java.util.Arrays;
20-
19+
import org.jspecify.annotations.Nullable;
2120
import org.springframework.batch.item.Chunk;
2221
import org.springframework.batch.item.ItemWriter;
2322
import org.springframework.beans.BeanWrapper;
@@ -41,7 +40,7 @@
4140
public class PropertyExtractingDelegatingItemWriter<T> extends AbstractMethodInvokingDelegator<T>
4241
implements ItemWriter<T> {
4342

44-
private String[] fieldsUsedAsTargetMethodArguments;
43+
private @NullableString[] fieldsUsedAsTargetMethodArguments;
4544

4645
/**
4746
* Extracts values from item's fields named in fieldsUsedAsTargetMethodArguments and

0 commit comments

Comments
(0)

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