Skip to content

add jspecify #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jar {

dependencies {
api "org.reactivestreams:reactive-streams:$reactive_streams_version"
api "org.jspecify:jspecify:1.0.0"
}

task sourcesJar(type: Jar) {
Expand Down Expand Up @@ -197,4 +198,4 @@ tasks.named("dependencyUpdates").configure {
rejectVersionIf {
isNonStable(it.candidate.version)
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/dataloader/BatchLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.dataloader;

import org.dataloader.annotations.PublicSpi;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;

import java.util.List;
import java.util.concurrent.CompletionStage;
Expand Down Expand Up @@ -74,6 +76,7 @@
*/
@FunctionalInterface
@PublicSpi
@NullMarked
public interface BatchLoader<K, V> {

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/dataloader/BatchLoaderContextProvider.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package org.dataloader;

import org.dataloader.annotations.PublicSpi;
import org.jspecify.annotations.NullMarked;

/**
* A BatchLoaderContextProvider is used by the {@link org.dataloader.DataLoader} code to
* provide overall calling context to the {@link org.dataloader.BatchLoader} call. A common use
* case is for propagating user security credentials or database connection parameters for example.
*/
@PublicSpi
@NullMarked
public interface BatchLoaderContextProvider {
/**
* @return a context object that may be needed in batch load calls
*/
Object getContext();
}
}
5 changes: 4 additions & 1 deletion src/main/java/org/dataloader/BatchLoaderEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.dataloader.annotations.PublicApi;
import org.dataloader.impl.Assertions;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -14,6 +16,7 @@
* of the calling users for example or database parameters that allow the data layer call to succeed.
*/
@PublicApi
@NullMarked
public class BatchLoaderEnvironment {

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dataloader;

import org.dataloader.annotations.PublicSpi;
import org.jspecify.annotations.NullMarked;

/**
* A BatchLoaderEnvironmentProvider is used by the {@link org.dataloader.DataLoader} code to
Expand All @@ -9,9 +10,10 @@
* case is for propagating user security credentials or database connection parameters.
*/
@PublicSpi
@NullMarked
public interface BatchLoaderEnvironmentProvider {
/**
* @return a {@link org.dataloader.BatchLoaderEnvironment} that may be needed in batch calls
*/
BatchLoaderEnvironment get();
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/dataloader/BatchLoaderWithContext.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dataloader;

import org.dataloader.annotations.PublicSpi;
import org.jspecify.annotations.NullMarked;

import java.util.List;
import java.util.concurrent.CompletionStage;
Expand All @@ -14,6 +15,7 @@
* use this interface.
*/
@PublicSpi
@NullMarked
public interface BatchLoaderWithContext<K, V> {
/**
* Called to batch load the provided keys and return a promise to a list of values. This default
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/dataloader/BatchPublisher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.dataloader;

import org.dataloader.annotations.PublicSpi;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Subscriber;

import java.util.List;
Expand All @@ -18,6 +21,8 @@
* @param <V> type parameter indicating the type of values returned
* @see BatchLoader for the non-reactive version
*/
@NullMarked
@PublicSpi
public interface BatchPublisher<K, V> {
/**
* Called to batch the provided keys into a stream of values. You <b>must</b> provide
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/dataloader/BatchPublisherWithContext.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.dataloader;

import org.dataloader.annotations.PublicSpi;
import org.jspecify.annotations.NullMarked;
import org.reactivestreams.Subscriber;

import java.util.List;
Expand All @@ -12,6 +14,8 @@
* See {@link BatchPublisher} for more details on the design invariants that you must implement in order to
* use this interface.
*/
@NullMarked
@PublicSpi
public interface BatchPublisherWithContext<K, V> {
/**
* Called to batch the provided keys into a stream of values. You <b>must</b> provide
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/dataloader/CacheKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.dataloader;

import org.dataloader.annotations.PublicSpi;
import org.jspecify.annotations.NullMarked;

/**
* Function that is invoked on input keys of type {@code K} to derive keys that are required by the {@link CacheMap}
* implementation.
Expand All @@ -25,6 +28,8 @@
* @author <a href="https://github.com/aschrijver/">Arnold Schrijver</a>
*/
@FunctionalInterface
@NullMarked
@PublicSpi
public interface CacheKey<K> {

/**
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/dataloader/CacheMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.dataloader.annotations.PublicSpi;
import org.dataloader.impl.DefaultCacheMap;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

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

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

/**
* Gets a collection of CompletableFutures from the cache map.
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/org/dataloader/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.dataloader.impl.CompletableFutureKit;
import org.dataloader.stats.Statistics;
import org.dataloader.stats.StatisticsCollector;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import java.time.Clock;
import java.time.Duration;
Expand Down Expand Up @@ -64,6 +66,7 @@
* @author <a href="https://github.com/bbakerman/">Brad Baker</a>
*/
@PublicApi
@NullMarked
public class DataLoader<K, V> {

private final DataLoaderHelper<K, V> helper;
Expand Down Expand Up @@ -99,7 +102,7 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadF
* @deprecated use {@link DataLoaderFactory} instead
*/
@Deprecated
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadFunction, DataLoaderOptions options) {
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
}

Expand Down Expand Up @@ -139,7 +142,7 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>
* @deprecated use {@link DataLoaderFactory} instead
*/
@Deprecated
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) {
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
}

Expand Down Expand Up @@ -169,7 +172,7 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V>
* @deprecated use {@link DataLoaderFactory} instead
*/
@Deprecated
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V> batchLoadFunction, DataLoaderOptions options) {
public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
}

Expand Down Expand Up @@ -209,7 +212,7 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContex
* @deprecated use {@link DataLoaderFactory} instead
*/
@Deprecated
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContext<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContext<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) {
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
}

Expand Down Expand Up @@ -239,7 +242,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V
* @deprecated use {@link DataLoaderFactory} instead
*/
@Deprecated
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction, DataLoaderOptions options) {
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
}

Expand Down Expand Up @@ -280,7 +283,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
* @deprecated use {@link DataLoaderFactory} instead
*/
@Deprecated
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoader<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoader<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) {
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
}

Expand Down Expand Up @@ -310,7 +313,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithC
* @deprecated use {@link DataLoaderFactory} instead
*/
@Deprecated
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithContext<K, V> batchLoadFunction, DataLoaderOptions options) {
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithContext<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
}

Expand Down Expand Up @@ -350,7 +353,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
* @deprecated use {@link DataLoaderFactory} instead
*/
@Deprecated
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoaderWithContext<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoaderWithContext<K, Try<V>> batchLoadFunction, @Nullable DataLoaderOptions options) {
return DataLoaderFactory.mkDataLoader(batchLoadFunction, options);
}

Expand All @@ -373,17 +376,17 @@ public DataLoader(BatchLoader<K, V> batchLoadFunction) {
* @deprecated use {@link DataLoaderFactory} instead
*/
@Deprecated
public DataLoader(BatchLoader<K, V> batchLoadFunction, DataLoaderOptions options) {
public DataLoader(BatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
this((Object) batchLoadFunction, options);
}

@VisibleForTesting
DataLoader(Object batchLoadFunction, DataLoaderOptions options) {
DataLoader(Object batchLoadFunction, @Nullable DataLoaderOptions options) {
this(batchLoadFunction, options, Clock.systemUTC());
}

@VisibleForTesting
DataLoader(Object batchLoadFunction, DataLoaderOptions options, Clock clock) {
DataLoader(Object batchLoadFunction, @Nullable DataLoaderOptions options, Clock clock) {
DataLoaderOptions loaderOptions = options == null ? new DataLoaderOptions() : options;
this.futureCache = determineFutureCache(loaderOptions);
this.valueCache = determineValueCache(loaderOptions);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/dataloader/DataLoaderFactory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dataloader;

import org.dataloader.annotations.PublicApi;
import org.jspecify.annotations.Nullable;

/**
* A factory class to create {@link DataLoader}s
Expand Down Expand Up @@ -155,7 +156,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V
* @param <V> the value type
* @return a new DataLoader
*/
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction, DataLoaderOptions options) {
public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V> batchLoadFunction, @Nullable DataLoaderOptions options) {
return mkDataLoader(batchLoadFunction, options);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/dataloader/DispatchResult.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dataloader;

import org.dataloader.annotations.PublicApi;
import org.jspecify.annotations.NullMarked;

import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand All @@ -12,6 +13,7 @@
* @param <T> for two
*/
@PublicApi
@NullMarked
public class DispatchResult<T> {
private final CompletableFuture<List<T>> futureList;
private final int keysCount;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/dataloader/MappedBatchLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.dataloader;

import org.dataloader.annotations.PublicSpi;
import org.jspecify.annotations.NullMarked;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletionStage;
Expand Down Expand Up @@ -54,6 +57,8 @@
* @param <V> type parameter indicating the type of values returned
*
*/
@PublicSpi
@NullMarked
public interface MappedBatchLoader<K, V> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.dataloader;

import org.dataloader.annotations.PublicSpi;
import org.jspecify.annotations.NullMarked;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletionStage;
Expand All @@ -28,6 +31,8 @@
* See {@link MappedBatchLoader} for more details on the design invariants that you must implement in order to
* use this interface.
*/
@PublicSpi
@NullMarked
public interface MappedBatchLoaderWithContext<K, V> {
/**
* Called to batch load the provided keys and return a promise to a map of values.
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/dataloader/MappedBatchPublisher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.dataloader;

import org.dataloader.annotations.PublicSpi;
import org.jspecify.annotations.NullMarked;
import org.reactivestreams.Subscriber;

import java.util.Map;
Expand All @@ -16,6 +18,8 @@
* @param <V> type parameter indicating the type of values returned
* @see MappedBatchLoader for the non-reactive version
*/
@PublicSpi
@NullMarked
public interface MappedBatchPublisher<K, V> {
/**
* Called to batch the provided keys into a stream of map entries of keys and values.
Expand Down
Loading
Loading