Skip to content

Commit 34185f8

Browse files
Copilotandimarek
andcommitted
Add JSpecify @NullMarked annotations to all remaining files
Co-authored-by: andimarek <1706744+andimarek@users.noreply.github.com>
1 parent bcfef7b commit 34185f8

32 files changed

+207
-128
lines changed

src/main/java/org/dataloader/BatchLoaderContextProvider.java

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

33
import org.dataloader.annotations.PublicSpi;
44
import org.jspecify.annotations.NullMarked;
5+
import org.jspecify.annotations.Nullable;
56

67
/**
78
* A BatchLoaderContextProvider is used by the {@link org.dataloader.DataLoader} code to
@@ -12,7 +13,7 @@
1213
@NullMarked
1314
public interface BatchLoaderContextProvider {
1415
/**
15-
* @return a context object that may be needed in batch load calls
16+
* @return a context object that may be needed in batch load calls, can be null
1617
*/
17-
Object getContext();
18+
@Nullable Object getContext();
1819
}

src/main/java/org/dataloader/DataLoaderOptions.java

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
* Copyright (c) 2016 The original author or authors
3-
*
4-
* All rights reserved. This program and the accompanying materials
5-
* are made available under the terms of the Eclipse Public License v1.0
6-
* and Apache License v2.0 which accompanies this distribution.
7-
*
8-
* The Eclipse Public License is available at
9-
* http://www.eclipse.org/legal/epl-v10.html
10-
*
11-
* The Apache License v2.0 is available at
12-
* http://www.opensource.org/licenses/apache2.0.php
13-
*
14-
* You may elect to redistribute this code under either of these licenses.
15-
*/
16-
171
package org.dataloader;
182

193
import org.dataloader.annotations.PublicApi;
@@ -22,6 +6,8 @@
226
import org.dataloader.scheduler.BatchLoaderScheduler;
237
import org.dataloader.stats.NoOpStatisticsCollector;
248
import org.dataloader.stats.StatisticsCollector;
9+
import org.jspecify.annotations.NullMarked;
10+
import org.jspecify.annotations.Nullable;
2511

2612
import java.util.Objects;
2713
import java.util.Optional;
@@ -37,6 +23,7 @@
3723
* @author <a href="https://github.com/aschrijver/">Arnold Schrijver</a>
3824
*/
3925
@PublicApi
26+
@NullMarked
4027
public class DataLoaderOptions {
4128

4229
private static final BatchLoaderContextProvider NULL_PROVIDER = () -> null;
@@ -46,14 +33,14 @@ public class DataLoaderOptions {
4633
private final boolean batchingEnabled;
4734
private final boolean cachingEnabled;
4835
private final boolean cachingExceptionsEnabled;
49-
private final CacheKey<?> cacheKeyFunction;
50-
private final CacheMap<?, ?> cacheMap;
51-
private final ValueCache<?, ?> valueCache;
36+
private final @Nullable CacheKey<?> cacheKeyFunction;
37+
private final @Nullable CacheMap<?, ?> cacheMap;
38+
private final @Nullable ValueCache<?, ?> valueCache;
5239
private final int maxBatchSize;
5340
private final Supplier<StatisticsCollector> statisticsCollector;
5441
private final BatchLoaderContextProvider environmentProvider;
5542
private final ValueCacheOptions valueCacheOptions;
56-
private final BatchLoaderScheduler batchLoaderScheduler;
43+
private final @Nullable BatchLoaderScheduler batchLoaderScheduler;
5744
private final DataLoaderInstrumentation instrumentation;
5845

5946
/**
@@ -243,7 +230,7 @@ public ValueCacheOptions getValueCacheOptions() {
243230
/**
244231
* @return the {@link BatchLoaderScheduler} to use, which can be null
245232
*/
246-
public BatchLoaderScheduler getBatchLoaderScheduler() {
233+
public @Nullable BatchLoaderScheduler getBatchLoaderScheduler() {
247234
return batchLoaderScheduler;
248235
}
249236

@@ -258,14 +245,14 @@ public static class Builder {
258245
private boolean batchingEnabled;
259246
private boolean cachingEnabled;
260247
private boolean cachingExceptionsEnabled;
261-
private CacheKey<?> cacheKeyFunction;
262-
private CacheMap<?, ?> cacheMap;
263-
private ValueCache<?, ?> valueCache;
248+
private @Nullable CacheKey<?> cacheKeyFunction;
249+
private @Nullable CacheMap<?, ?> cacheMap;
250+
private @Nullable ValueCache<?, ?> valueCache;
264251
private int maxBatchSize;
265252
private Supplier<StatisticsCollector> statisticsCollector;
266253
private BatchLoaderContextProvider environmentProvider;
267254
private ValueCacheOptions valueCacheOptions;
268-
private BatchLoaderScheduler batchLoaderScheduler;
255+
private @Nullable BatchLoaderScheduler batchLoaderScheduler;
269256
private DataLoaderInstrumentation instrumentation;
270257

271258
public Builder() {
@@ -326,7 +313,7 @@ public Builder setCachingExceptionsEnabled(boolean cachingExceptionsEnabled) {
326313
* @param cacheKeyFunction the cache key function to use
327314
* @return this builder for fluent coding
328315
*/
329-
public Builder setCacheKeyFunction(CacheKey<?> cacheKeyFunction) {
316+
public Builder setCacheKeyFunction(@Nullable CacheKey<?> cacheKeyFunction) {
330317
this.cacheKeyFunction = cacheKeyFunction;
331318
return this;
332319
}
@@ -337,7 +324,7 @@ public Builder setCacheKeyFunction(CacheKey<?> cacheKeyFunction) {
337324
* @param cacheMap the cache map instance
338325
* @return this builder for fluent coding
339326
*/
340-
public Builder setCacheMap(CacheMap<?, ?> cacheMap) {
327+
public Builder setCacheMap(@Nullable CacheMap<?, ?> cacheMap) {
341328
this.cacheMap = cacheMap;
342329
return this;
343330
}
@@ -348,7 +335,7 @@ public Builder setCacheMap(CacheMap<?, ?> cacheMap) {
348335
* @param valueCache the value cache instance
349336
* @return this builder for fluent coding
350337
*/
351-
public Builder setValueCache(ValueCache<?, ?> valueCache) {
338+
public Builder setValueCache(@Nullable ValueCache<?, ?> valueCache) {
352339
this.valueCache = valueCache;
353340
return this;
354341
}
@@ -407,7 +394,7 @@ public Builder setValueCacheOptions(ValueCacheOptions valueCacheOptions) {
407394
* @param batchLoaderScheduler the scheduler
408395
* @return this builder for fluent coding
409396
*/
410-
public Builder setBatchLoaderScheduler(BatchLoaderScheduler batchLoaderScheduler) {
397+
public Builder setBatchLoaderScheduler(@Nullable BatchLoaderScheduler batchLoaderScheduler) {
411398
this.batchLoaderScheduler = batchLoaderScheduler;
412399
return this;
413400
}

src/main/java/org/dataloader/Try.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.dataloader;
22

33
import org.dataloader.annotations.PublicApi;
4+
import org.jspecify.annotations.NullMarked;
5+
import org.jspecify.annotations.Nullable;
46

57
import java.util.Optional;
68
import java.util.concurrent.Callable;
@@ -26,6 +28,7 @@
2628
* the value promise with that exception value.
2729
*/
2830
@PublicApi
31+
@NullMarked
2932
public class Try<V> {
3033
private final static Object NIL = new Object() {
3134
};
@@ -43,7 +46,7 @@ public synchronized Throwable fillInStackTrace() {
4346
};
4447

4548

46-
private final Throwable throwable;
49+
private final @Nullable Throwable throwable;
4750
private final V value;
4851

4952

@@ -169,7 +172,7 @@ public Throwable getThrowable() {
169172
if (isSuccess()) {
170173
throw new UnsupportedOperationException("You have called Try.getThrowable() with a successful Try");
171174
}
172-
return throwable;
175+
return nonNull(throwable);
173176
}
174177

175178
/**
@@ -199,7 +202,7 @@ public <U> Try<U> map(Function<? super V, U> mapper) {
199202
if (isSuccess()) {
200203
return succeeded(mapper.apply(value));
201204
}
202-
return failed(this.throwable);
205+
return failed(nonNull(this.throwable));
203206
}
204207

205208
/**
@@ -214,7 +217,7 @@ public <U> Try<U> flatMap(Function<? super V, Try<U>> mapper) {
214217
if (isSuccess()) {
215218
return mapper.apply(value);
216219
}
217-
return failed(this.throwable);
220+
return failed(nonNull(this.throwable));
218221
}
219222

220223
/**
@@ -258,7 +261,7 @@ public void reThrow() throws Throwable {
258261
if (isSuccess()) {
259262
throw new UnsupportedOperationException("You have called Try.reThrow() with a successful Try. There is nothing to rethrow");
260263
}
261-
throw throwable;
264+
throw nonNull(throwable);
262265
}
263266

264267
/**
@@ -281,7 +284,7 @@ void forEach(Consumer<? super V> action) {
281284
*/
282285
public Try<V> recover(Function<Throwable, V> recoverFunction) {
283286
if (isFailure()) {
284-
return succeeded(recoverFunction.apply(throwable));
287+
return succeeded(recoverFunction.apply(nonNull(throwable)));
285288
}
286289
return this;
287290
}

src/main/java/org/dataloader/impl/Assertions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.dataloader.impl;
22

33
import org.dataloader.annotations.Internal;
4+
import org.jspecify.annotations.NullMarked;
5+
import org.jspecify.annotations.Nullable;
46

57
import java.util.function.Supplier;
68

79
@Internal
10+
@NullMarked
811
public class Assertions {
912

1013
public static void assertState(boolean state, Supplier<String> message) {
@@ -13,11 +16,11 @@ public static void assertState(boolean state, Supplier<String> message) {
1316
}
1417
}
1518

16-
public static <T> T nonNull(T t) {
19+
public static <T> T nonNull(@Nullable T t) {
1720
return nonNull(t, () -> "nonNull object required");
1821
}
1922

20-
public static <T> T nonNull(T t, Supplier<String> message) {
23+
public static <T> T nonNull(@Nullable T t, Supplier<String> message) {
2124
if (t == null) {
2225
throw new NullPointerException(message.get());
2326
}

src/main/java/org/dataloader/impl/CompletableFutureKit.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.dataloader.impl;
22

33
import org.dataloader.annotations.Internal;
4+
import org.jspecify.annotations.NullMarked;
5+
import org.jspecify.annotations.Nullable;
46

57
import java.util.List;
68
import java.util.Map;
@@ -14,6 +16,7 @@
1416
* Some really basic helpers when working with CompletableFutures
1517
*/
1618
@Internal
19+
@NullMarked
1720
public class CompletableFutureKit {
1821

1922
public static <V> CompletableFuture<V> failedFuture(Exception e) {
@@ -22,7 +25,7 @@ public static <V> CompletableFuture<V> failedFuture(Exception e) {
2225
return future;
2326
}
2427

25-
public static <V> Throwable cause(CompletableFuture<V> completableFuture) {
28+
public static <V> @Nullable Throwable cause(CompletableFuture<V> completableFuture) {
2629
if (!completableFuture.isCompletedExceptionally()) {
2730
return null;
2831
}

src/main/java/org/dataloader/impl/DataLoaderAssertionException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.dataloader.impl;
22

3+
import org.jspecify.annotations.NullMarked;
4+
5+
@NullMarked
36
public class DataLoaderAssertionException extends IllegalStateException {
47
public DataLoaderAssertionException(String message) {
58
super(message);

src/main/java/org/dataloader/impl/NoOpValueCache.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.dataloader.Try;
55
import org.dataloader.ValueCache;
66
import org.dataloader.annotations.Internal;
7+
import org.jspecify.annotations.NullMarked;
8+
import org.jspecify.annotations.Nullable;
79

810
import java.util.List;
911
import java.util.concurrent.CompletableFuture;
@@ -20,7 +22,8 @@
2022
* @author <a href="https://github.com/craig-day">Craig Day</a>
2123
*/
2224
@Internal
23-
public class NoOpValueCache<K, V> implements ValueCache<K, V> {
25+
@NullMarked
26+
public class NoOpValueCache<K, V extends @Nullable Object> implements ValueCache<K, V> {
2427

2528
/**
2629
* a no op value cache instance

src/main/java/org/dataloader/impl/PromisedValues.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.dataloader.impl;
22

33
import org.dataloader.annotations.Internal;
4+
import org.jspecify.annotations.NullMarked;
5+
import org.jspecify.annotations.Nullable;
46

57
import java.util.List;
68
import java.util.concurrent.CancellationException;
@@ -25,6 +27,7 @@
2527
* @author <a href="https://github.com/bbakerman/">Brad Baker</a>
2628
*/
2729
@Internal
30+
@NullMarked
2831
public interface PromisedValues<T> {
2932

3033
/**
@@ -193,7 +196,7 @@ static <T> PromisedValues<T> allPromisedValues(PromisedValues<T> pv1, PromisedVa
193196
*
194197
* @return an exception or null if the future did not fail
195198
*/
196-
Throwable cause();
199+
@Nullable Throwable cause();
197200

198201
/**
199202
* The true if the {@link CompletionStage} at the specified index succeeded
@@ -211,7 +214,7 @@ static <T> PromisedValues<T> allPromisedValues(PromisedValues<T> pv1, PromisedVa
211214
*
212215
* @return an exception or null if the future did not fail
213216
*/
214-
Throwable cause(int index);
217+
@Nullable Throwable cause(int index);
215218

216219
/**
217220
* The value at index or null if it failed
@@ -220,7 +223,7 @@ static <T> PromisedValues<T> allPromisedValues(PromisedValues<T> pv1, PromisedVa
220223
*
221224
* @return the value of the future
222225
*/
223-
T get(int index);
226+
@Nullable T get(int index);
224227

225228
/**
226229
* Returns the underlying values as a list

src/main/java/org/dataloader/impl/PromisedValuesImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.dataloader.impl;
22

33
import org.dataloader.annotations.Internal;
4+
import org.jspecify.annotations.NullMarked;
5+
import org.jspecify.annotations.Nullable;
46

57
import java.util.ArrayList;
68
import java.util.List;
@@ -16,6 +18,7 @@
1618
import static org.dataloader.impl.Assertions.nonNull;
1719

1820
@Internal
21+
@NullMarked
1922
public class PromisedValuesImpl<T> implements PromisedValues<T> {
2023

2124
private final List<? extends CompletionStage<T>> futures;
@@ -88,7 +91,7 @@ public boolean isDone() {
8891
}
8992

9093
@Override
91-
public Throwable cause() {
94+
public @Nullable Throwable cause() {
9295
return cause.get();
9396
}
9497

@@ -98,12 +101,12 @@ public boolean succeeded(int index) {
98101
}
99102

100103
@Override
101-
public Throwable cause(int index) {
104+
public @Nullable Throwable cause(int index) {
102105
return CompletableFutureKit.cause(futures.get(index).toCompletableFuture());
103106
}
104107

105108
@Override
106-
public T get(int index) {
109+
public @Nullable T get(int index) {
107110
assertState(isDone(), () -> "The PromisedValues MUST be complete before calling the get() method");
108111
try {
109112
CompletionStage<T> future = futures.get(index);

0 commit comments

Comments
 (0)