Skip to content

Commit 9a2bd4a

Browse files
authored
Merge pull request #180 from graphql-java/add-jspecify
add jspecify
2 parents 4ec5fe8 + 6cf5c78 commit 9a2bd4a

19 files changed

+79
-18
lines changed

build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ jar {
6666

6767
dependencies {
6868
api "org.reactivestreams:reactive-streams:$reactive_streams_version"
69+
api "org.jspecify:jspecify:1.0.0"
6970
}
7071

7172
task sourcesJar(type: Jar) {
@@ -197,4 +198,4 @@ tasks.named("dependencyUpdates").configure {
197198
rejectVersionIf {
198199
isNonStable(it.candidate.version)
199200
}
200-
}
201+
}

src/main/java/org/dataloader/BatchLoader.java

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.dataloader;
1818

1919
import org.dataloader.annotations.PublicSpi;
20+
import org.jspecify.annotations.NonNull;
21+
import org.jspecify.annotations.NullMarked;
2022

2123
import java.util.List;
2224
import java.util.concurrent.CompletionStage;
@@ -74,6 +76,7 @@
7476
*/
7577
@FunctionalInterface
7678
@PublicSpi
79+
@NullMarked
7780
public interface BatchLoader<K, V> {
7881

7982
/**
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package org.dataloader;
22

33
import org.dataloader.annotations.PublicSpi;
4+
import org.jspecify.annotations.NullMarked;
45

56
/**
67
* A BatchLoaderContextProvider is used by the {@link org.dataloader.DataLoader} code to
78
* provide overall calling context to the {@link org.dataloader.BatchLoader} call. A common use
89
* case is for propagating user security credentials or database connection parameters for example.
910
*/
1011
@PublicSpi
12+
@NullMarked
1113
public interface BatchLoaderContextProvider {
1214
/**
1315
* @return a context object that may be needed in batch load calls
1416
*/
1517
Object getContext();
16-
}
18+
}

src/main/java/org/dataloader/BatchLoaderEnvironment.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.dataloader.annotations.PublicApi;
44
import org.dataloader.impl.Assertions;
5+
import org.jspecify.annotations.NullMarked;
6+
import org.jspecify.annotations.Nullable;
57

68
import java.util.ArrayList;
79
import java.util.Collections;
@@ -14,6 +16,7 @@
1416
* of the calling users for example or database parameters that allow the data layer call to succeed.
1517
*/
1618
@PublicApi
19+
@NullMarked
1720
public class BatchLoaderEnvironment {
1821

1922
private final Object context;
@@ -34,7 +37,7 @@ private BatchLoaderEnvironment(Object context, List<Object> keyContextsList, Map
3437
* @return a context object or null if there isn't one
3538
*/
3639
@SuppressWarnings("unchecked")
37-
public <T> T getContext() {
40+
public <T> @Nullable T getContext() {
3841
return (T) context;
3942
}
4043

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.dataloader;
22

33
import org.dataloader.annotations.PublicSpi;
4+
import org.jspecify.annotations.NullMarked;
45

56
/**
67
* A BatchLoaderEnvironmentProvider is used by the {@link org.dataloader.DataLoader} code to
@@ -9,9 +10,10 @@
910
* case is for propagating user security credentials or database connection parameters.
1011
*/
1112
@PublicSpi
13+
@NullMarked
1214
public interface BatchLoaderEnvironmentProvider {
1315
/**
1416
* @return a {@link org.dataloader.BatchLoaderEnvironment} that may be needed in batch calls
1517
*/
1618
BatchLoaderEnvironment get();
17-
}
19+
}

src/main/java/org/dataloader/BatchLoaderWithContext.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.dataloader;
22

33
import org.dataloader.annotations.PublicSpi;
4+
import org.jspecify.annotations.NullMarked;
45

56
import java.util.List;
67
import java.util.concurrent.CompletionStage;
@@ -14,6 +15,7 @@
1415
* use this interface.
1516
*/
1617
@PublicSpi
18+
@NullMarked
1719
public interface BatchLoaderWithContext<K, V> {
1820
/**
1921
* Called to batch load the provided keys and return a promise to a list of values. This default

src/main/java/org/dataloader/BatchPublisher.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.dataloader;
22

3+
import org.dataloader.annotations.PublicSpi;
4+
import org.jspecify.annotations.NullMarked;
5+
import org.jspecify.annotations.Nullable;
36
import org.reactivestreams.Subscriber;
47

58
import java.util.List;
@@ -18,6 +21,8 @@
1821
* @param <V> type parameter indicating the type of values returned
1922
* @see BatchLoader for the non-reactive version
2023
*/
24+
@NullMarked
25+
@PublicSpi
2126
public interface BatchPublisher<K, V> {
2227
/**
2328
* Called to batch the provided keys into a stream of values. You <b>must</b> provide

src/main/java/org/dataloader/BatchPublisherWithContext.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.dataloader;
22

3+
import org.dataloader.annotations.PublicSpi;
4+
import org.jspecify.annotations.NullMarked;
35
import org.reactivestreams.Subscriber;
46

57
import java.util.List;
@@ -12,6 +14,8 @@
1214
* See {@link BatchPublisher} for more details on the design invariants that you must implement in order to
1315
* use this interface.
1416
*/
17+
@NullMarked
18+
@PublicSpi
1519
public interface BatchPublisherWithContext<K, V> {
1620
/**
1721
* Called to batch the provided keys into a stream of values. You <b>must</b> provide

src/main/java/org/dataloader/CacheKey.java

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package org.dataloader;
1818

19+
import org.dataloader.annotations.PublicSpi;
20+
import org.jspecify.annotations.NullMarked;
21+
1922
/**
2023
* Function that is invoked on input keys of type {@code K} to derive keys that are required by the {@link CacheMap}
2124
* implementation.
@@ -25,6 +28,8 @@
2528
* @author <a href="https://github.com/aschrijver/">Arnold Schrijver</a>
2629
*/
2730
@FunctionalInterface
31+
@NullMarked
32+
@PublicSpi
2833
public interface CacheKey<K> {
2934

3035
/**

src/main/java/org/dataloader/CacheMap.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.dataloader.annotations.PublicSpi;
2020
import org.dataloader.impl.DefaultCacheMap;
21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
2123

2224
import java.util.Collection;
2325
import java.util.concurrent.CompletableFuture;
@@ -39,6 +41,7 @@
3941
* @author <a href="https://github.com/bbakerman/">Brad Baker</a>
4042
*/
4143
@PublicSpi
44+
@NullMarked
4245
public interface CacheMap<K, V> {
4346

4447
/**
@@ -71,7 +74,7 @@ static <K, V> CacheMap<K, V> simpleMap() {
7174
*
7275
* @return the cached value, or {@code null} if not found (depends on cache implementation)
7376
*/
74-
CompletableFuture<V> get(K key);
77+
@Nullable CompletableFuture<V> get(K key);
7578

7679
/**
7780
* Gets a collection of CompletableFutures from the cache map.

src/main/java/org/dataloader/DataLoader.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.dataloader.impl.CompletableFutureKit;
2222
import org.dataloader.stats.Statistics;
2323
import org.dataloader.stats.StatisticsCollector;
24+
import org.jspecify.annotations.NullMarked;
25+
import org.jspecify.annotations.Nullable;
2426

2527
import java.time.Clock;
2628
import java.time.Duration;
@@ -64,6 +66,7 @@
6466
* @author <a href="https://github.com/bbakerman/">Brad Baker</a>
6567
*/
6668
@PublicApi
69+
@NullMarked
6770
public class DataLoader<K, V> {
6871

6972
private final DataLoaderHelper<K, V> helper;
@@ -99,7 +102,7 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadF
99102
* @deprecated use {@link DataLoaderFactory} instead
100103
*/
101104
@Deprecated
102-
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadFunction, DataLoaderOptions options) {
105+
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
103106
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
104107
}
105108

@@ -139,7 +142,7 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>
139142
* @deprecated use {@link DataLoaderFactory} instead
140143
*/
141144
@Deprecated
142-
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
145+
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) {
143146
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
144147
}
145148

@@ -169,7 +172,7 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V>
169172
* @deprecated use {@link DataLoaderFactory} instead
170173
*/
171174
@Deprecated
172-
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V> batchLoadFunction, DataLoaderOptions options) {
175+
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
173176
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
174177
}
175178

@@ -209,7 +212,7 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContex
209212
* @deprecated use {@link DataLoaderFactory} instead
210213
*/
211214
@Deprecated
212-
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContext<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
215+
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContext<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) {
213216
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
214217
}
215218

@@ -239,7 +242,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V
239242
* @deprecated use {@link DataLoaderFactory} instead
240243
*/
241244
@Deprecated
242-
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction, DataLoaderOptions options) {
245+
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
243246
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
244247
}
245248

@@ -280,7 +283,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
280283
* @deprecated use {@link DataLoaderFactory} instead
281284
*/
282285
@Deprecated
283-
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoader<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
286+
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoader<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) {
284287
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
285288
}
286289

@@ -310,7 +313,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithC
310313
* @deprecated use {@link DataLoaderFactory} instead
311314
*/
312315
@Deprecated
313-
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithContext<K, V> batchLoadFunction, DataLoaderOptions options) {
316+
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithContext<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
314317
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
315318
}
316319

@@ -350,7 +353,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
350353
* @deprecated use {@link DataLoaderFactory} instead
351354
*/
352355
@Deprecated
353-
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoaderWithContext<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
356+
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoaderWithContext<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) {
354357
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
355358
}
356359

@@ -373,17 +376,17 @@ public DataLoader(BatchLoader<K, V> batchLoadFunction) {
373376
* @deprecated use {@link DataLoaderFactory} instead
374377
*/
375378
@Deprecated
376-
public DataLoader(BatchLoader<K, V> batchLoadFunction, DataLoaderOptions options) {
379+
public DataLoader(BatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
377380
this((Object) batchLoadFunction, options);
378381
}
379382

380383
@VisibleForTesting
381-
DataLoader(Object batchLoadFunction, DataLoaderOptions options) {
384+
DataLoader(Object batchLoadFunction, @Nullable DataLoaderOptions options) {
382385
this(batchLoadFunction, options, Clock.systemUTC());
383386
}
384387

385388
@VisibleForTesting
386-
DataLoader(Object batchLoadFunction, DataLoaderOptions options, Clock clock) {
389+
DataLoader(Object batchLoadFunction, @Nullable DataLoaderOptions options, Clock clock) {
387390
DataLoaderOptions loaderOptions = options == null ? new DataLoaderOptions() : options;
388391
this.futureCache = determineFutureCache(loaderOptions);
389392
this.valueCache = determineValueCache(loaderOptions);

src/main/java/org/dataloader/DataLoaderFactory.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.dataloader;
22

33
import org.dataloader.annotations.PublicApi;
4+
import org.jspecify.annotations.Nullable;
45

56
/**
67
* A factory class to create {@link DataLoader}s
@@ -155,7 +156,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V
155156
* @param <V> the value type
156157
* @return a new DataLoader
157158
*/
158-
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction, DataLoaderOptions options) {
159+
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
159160
return mkDataLoader(batchLoadFunction, options);
160161
}
161162

src/main/java/org/dataloader/DispatchResult.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.dataloader;
22

33
import org.dataloader.annotations.PublicApi;
4+
import org.jspecify.annotations.NullMarked;
45

56
import java.util.List;
67
import java.util.concurrent.CompletableFuture;
@@ -12,6 +13,7 @@
1213
* @param <T> for two
1314
*/
1415
@PublicApi
16+
@NullMarked
1517
public class DispatchResult<T> {
1618
private final CompletableFuture<List<T>> futureList;
1719
private final int keysCount;

src/main/java/org/dataloader/MappedBatchLoader.java

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package org.dataloader;
1818

19+
import org.dataloader.annotations.PublicSpi;
20+
import org.jspecify.annotations.NullMarked;
21+
1922
import java.util.Map;
2023
import java.util.Set;
2124
import java.util.concurrent.CompletionStage;
@@ -54,6 +57,8 @@
5457
* @param <V> type parameter indicating the type of values returned
5558
*
5659
*/
60+
@PublicSpi
61+
@NullMarked
5762
public interface MappedBatchLoader<K, V> {
5863

5964
/**

src/main/java/org/dataloader/MappedBatchLoaderWithContext.java

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package org.dataloader;
1818

19+
import org.dataloader.annotations.PublicSpi;
20+
import org.jspecify.annotations.NullMarked;
21+
1922
import java.util.Map;
2023
import java.util.Set;
2124
import java.util.concurrent.CompletionStage;
@@ -28,6 +31,8 @@
2831
* See {@link MappedBatchLoader} for more details on the design invariants that you must implement in order to
2932
* use this interface.
3033
*/
34+
@PublicSpi
35+
@NullMarked
3136
public interface MappedBatchLoaderWithContext<K, V> {
3237
/**
3338
* Called to batch load the provided keys and return a promise to a map of values.

src/main/java/org/dataloader/MappedBatchPublisher.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.dataloader;
22

3+
import org.dataloader.annotations.PublicSpi;
4+
import org.jspecify.annotations.NullMarked;
35
import org.reactivestreams.Subscriber;
46

57
import java.util.Map;
@@ -16,6 +18,8 @@
1618
* @param <V> type parameter indicating the type of values returned
1719
* @see MappedBatchLoader for the non-reactive version
1820
*/
21+
@PublicSpi
22+
@NullMarked
1923
public interface MappedBatchPublisher<K, V> {
2024
/**
2125
* Called to batch the provided keys into a stream of map entries of keys and values.

0 commit comments

Comments
 (0)