Skip to content

Commit

Permalink
Fix more nullability issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Sitnikov committed Jun 7, 2024
1 parent 36c7887 commit 949f472
Show file tree
Hide file tree
Showing 206 changed files with 1,022 additions and 766 deletions.
20 changes: 10 additions & 10 deletions api/src/main/java/net/jqwik/api/Arbitraries.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static abstract class ArbitrariesFacade {

public abstract <T extends @Nullable Object> Arbitrary<T> oneOf(Collection<? extends Arbitrary<? extends T>> all);

public abstract <M> ActionSequenceArbitrary<M> sequences(Arbitrary<? extends Action<M>> actionArbitrary);
public abstract <M extends @Nullable Object> ActionSequenceArbitrary<M> sequences(Arbitrary<? extends Action<M>> actionArbitrary);

public abstract <T extends @Nullable Object> Arbitrary<T> frequencyOf(List<? extends Tuple2<Integer, ? extends Arbitrary<T>>> frequencies);

Expand Down Expand Up @@ -55,7 +55,7 @@ public static abstract class ArbitrariesFacade {

public abstract <T> Arbitrary<T> defaultFor(Class<T> type, Class<?>[] typeParameters);

public abstract <T> Arbitrary<T> defaultFor(TypeUsage typeUsage, Function<TypeUsage, Arbitrary<Object>> noDefaultResolver);
public abstract <T extends @Nullable Object> Arbitrary<T> defaultFor(TypeUsage typeUsage, Function<? super TypeUsage, ? extends Arbitrary<T>> noDefaultResolver);

public abstract <T extends @Nullable Object> Arbitrary<T> lazy(Supplier<? extends Arbitrary<T>> arbitrarySupplier);

Expand All @@ -78,7 +78,7 @@ public static abstract class ArbitrariesFacade {

public abstract Arbitrary<Character> of(char[] chars);

public abstract <T extends @Nullable Object> Arbitrary<T> of(Collection<T> values);
public abstract <T extends @Nullable Object> Arbitrary<T> of(Collection<? extends T> values);

public abstract <T extends @Nullable Object> Arbitrary<T> create(Supplier<T> supplier);

Expand Down Expand Up @@ -172,7 +172,7 @@ public static Arbitrary<Random> randoms() {
* @return a new arbitrary instance
*/
@API(status = MAINTAINED, since = "1.3.1")
public static <T extends @Nullable Object> Arbitrary<T> of(Collection<T> values) {
public static <T extends @Nullable Object> Arbitrary<T> of(Collection<? extends T> values) {
return ArbitrariesFacade.implementation.of(values);
}

Expand Down Expand Up @@ -430,7 +430,7 @@ public static CharacterArbitrary chars() {
* @return a new arbitrary instance
*/
@API(status = MAINTAINED, since = "1.3.2")
public static <@Nullable T> Arbitrary<T> just(@Nullable T value) {
public static <T extends @Nullable Object> Arbitrary<T> just(T value) {
return ArbitrariesFacade.implementation.just(value);
}

Expand Down Expand Up @@ -515,7 +515,7 @@ public static <T> Arbitrary<T> defaultFor(Class<T> type, Class<?>... typeParamet
* @return a new arbitrary instance
*/
@API(status = MAINTAINED, since = "1.1")
public static <T> Arbitrary<T> defaultFor(TypeUsage typeUsage) {
public static <T extends @Nullable Object> Arbitrary<T> defaultFor(TypeUsage typeUsage) {
return defaultFor(typeUsage, ignore -> {throw new CannotFindArbitraryException(typeUsage);});
}

Expand All @@ -534,7 +534,7 @@ public static <T> Arbitrary<T> defaultFor(TypeUsage typeUsage) {
* @return a new arbitrary instance
*/
@API(status = EXPERIMENTAL, since = "1.6.1")
public static <T> Arbitrary<T> defaultFor(TypeUsage typeUsage, Function<TypeUsage, Arbitrary<Object>> noDefaultResolver) {
public static <T> Arbitrary<T> defaultFor(TypeUsage typeUsage, Function<? super TypeUsage, ? extends Arbitrary<T>> noDefaultResolver) {
return ArbitrariesFacade.implementation.defaultFor(typeUsage, noDefaultResolver);
}

Expand Down Expand Up @@ -739,8 +739,8 @@ public static Arbitrary<Void> nothing() {
* @return a new arbitrary instance
*/
@API(status = MAINTAINED, since = "1.6.4")
public static <@Nullable T> SetArbitrary<T> subsetOf(Collection<T> values) {
return of(values).set();
public static <T extends @Nullable Object> SetArbitrary<T> subsetOf(Collection<? extends T> values) {
return Arbitraries.<T>of(values).set();
}

/**
Expand All @@ -750,7 +750,7 @@ public static Arbitrary<Void> nothing() {
*/
@SafeVarargs
@API(status = MAINTAINED, since = "1.6.4")
public static <T> SetArbitrary<T> subsetOf(T... values) {
public static <T extends @Nullable Object> SetArbitrary<T> subsetOf(T... values) {
return subsetOf(Arrays.asList(values));
}

Expand Down
44 changes: 22 additions & 22 deletions api/src/main/java/net/jqwik/api/Arbitrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,39 @@ abstract class ArbitraryFacade {
implementation = FacadeLoader.load(ArbitraryFacade.class);
}

public abstract <T> ListArbitrary<T> list(Arbitrary<T> elementArbitrary);
public abstract <T extends @Nullable Object> ListArbitrary<T> list(Arbitrary<T> elementArbitrary);

public abstract <T> SetArbitrary<T> set(Arbitrary<T> elementArbitrary);
public abstract <T extends @Nullable Object> SetArbitrary<T> set(Arbitrary<T> elementArbitrary);

public abstract <T> StreamArbitrary<T> stream(Arbitrary<T> elementArbitrary);
public abstract <T extends @Nullable Object> StreamArbitrary<T> stream(Arbitrary<T> elementArbitrary);

public abstract <T> IteratorArbitrary<T> iterator(Arbitrary<T> elementArbitrary);
public abstract <T extends @Nullable Object> IteratorArbitrary<T> iterator(Arbitrary<T> elementArbitrary);

public abstract <T, A> ArrayArbitrary<T, A> array(Arbitrary<T> elementArbitrary, Class<A> arrayClass);
public abstract <T extends @Nullable Object, A> ArrayArbitrary<T, A> array(Arbitrary<T> elementArbitrary, Class<A> arrayClass);

public abstract <T> Stream<T> sampleStream(Arbitrary<T> arbitrary);
public abstract <T extends @Nullable Object> Stream<T> sampleStream(Arbitrary<T> arbitrary);

public abstract <T> Arbitrary<T> injectNull(Arbitrary<T> self, double nullProbability);
public abstract <T extends @Nullable Object> Arbitrary<@Nullable T> injectNull(Arbitrary<T> self, double nullProbability);

public abstract <T> Arbitrary<T> filter(Arbitrary<T> self, Predicate<T> filterPredicate, int maxMisses);
public abstract <T extends @Nullable Object> Arbitrary<T> filter(Arbitrary<T> self, Predicate<? super T> filterPredicate, int maxMisses);

public abstract <T, U> Arbitrary<U> map(Arbitrary<T> self, Function<T, U> mapper);
public abstract <T, U extends @Nullable Object> Arbitrary<U> map(Arbitrary<T> self, Function<? super T, ? extends U> mapper);

public abstract <T, U> Arbitrary<U> flatMap(Arbitrary<T> self, Function<T, Arbitrary<U>> mapper);
public abstract <T, U extends @Nullable Object> Arbitrary<U> flatMap(Arbitrary<T> self, Function<? super T, ? extends Arbitrary<U>> mapper);

public abstract <T> Arbitrary<T> ignoreExceptions(Arbitrary<T> self, int maxThrows, Class<? extends Throwable>[] exceptionTypes);
public abstract <T extends @Nullable Object> Arbitrary<T> ignoreExceptions(Arbitrary<T> self, int maxThrows, Class<? extends Throwable>[] exceptionTypes);

public abstract <T> Arbitrary<T> dontShrink(Arbitrary<T> self);
public abstract <T extends @Nullable Object> Arbitrary<T> dontShrink(Arbitrary<T> self);

public abstract <T> Arbitrary<T> configureEdgeCases(Arbitrary<T> self, Consumer<EdgeCases.Config<T>> configurator);
public abstract <T extends @Nullable Object> Arbitrary<T> configureEdgeCases(Arbitrary<T> self, Consumer<? super EdgeCases.Config<T>> configurator);

public abstract <T> Arbitrary<T> withoutEdgeCases(Arbitrary<T> self);
public abstract <T extends @Nullable Object> Arbitrary<T> withoutEdgeCases(Arbitrary<T> self);

public abstract <T> RandomGenerator<T> memoizedGenerator(Arbitrary<T> self, int genSize, boolean withEdgeCases);
public abstract <T extends @Nullable Object> RandomGenerator<T> memoizedGenerator(Arbitrary<T> self, int genSize, boolean withEdgeCases);

public abstract <T> Arbitrary<T> fixGenSize(Arbitrary<T> self, int genSize);
public abstract <T extends @Nullable Object> Arbitrary<T> fixGenSize(Arbitrary<T> self, int genSize);

public abstract <T> Arbitrary<List<T>> collect(Arbitrary<T> self, Predicate<List<T>> until);
public abstract <T extends @Nullable Object> Arbitrary<List<T>> collect(Arbitrary<T> self, Predicate<? super List<? extends T>> until);
}

/**
Expand Down Expand Up @@ -208,7 +208,7 @@ default void forEachValue(Consumer<? super T> action) {
* @return a new arbitrary instance
* @throws TooManyFilterMissesException if filtering will fail to come up with a value after 10000 tries
*/
default Arbitrary<T> filter(Predicate<T> filterPredicate) {
default Arbitrary<T> filter(Predicate<? super T> filterPredicate) {
return filter(10000, filterPredicate);
}

Expand All @@ -222,7 +222,7 @@ default Arbitrary<T> filter(Predicate<T> filterPredicate) {
* @throws TooManyFilterMissesException if filtering will fail to come up with a value after {@code maxMisses} tries
*/
@API(status = EXPERIMENTAL, since = "1.7.0")
default Arbitrary<T> filter(int maxMisses, Predicate<T> filterPredicate) {
default Arbitrary<T> filter(int maxMisses, Predicate<? super T> filterPredicate) {
return ArbitraryFacade.implementation.filter(this, filterPredicate, maxMisses);
}

Expand All @@ -234,7 +234,7 @@ default Arbitrary<T> filter(int maxMisses, Predicate<T> filterPredicate) {
* @param mapper the function used to map
* @return a new arbitrary instance
*/
default <U> Arbitrary<U> map(Function<T, U> mapper) {
default <U extends @Nullable Object> Arbitrary<U> map(Function<? super T, ? extends U> mapper) {
return ArbitraryFacade.implementation.map(this, mapper);
}

Expand All @@ -246,7 +246,7 @@ default <U> Arbitrary<U> map(Function<T, U> mapper) {
* @param mapper the function used to map to arbitrary
* @return a new arbitrary instance
*/
default <U> Arbitrary<U> flatMap(Function<T, Arbitrary<U>> mapper) {
default <U extends @Nullable Object> Arbitrary<U> flatMap(Function<? super T, ? extends Arbitrary<U>> mapper) {
return ArbitraryFacade.implementation.flatMap(this, mapper);
}

Expand Down Expand Up @@ -359,7 +359,7 @@ default Arbitrary<Optional<T>> optional(double presenceProbability) {
* @return a new arbitrary instance
*/
@API(status = MAINTAINED, since = "1.3.0")
default Arbitrary<List<T>> collect(Predicate<List<T>> until) {
default Arbitrary<List<T>> collect(Predicate<? super List<? extends T>> until) {
return ArbitraryFacade.implementation.collect(this, until);
}

Expand Down
6 changes: 2 additions & 4 deletions api/src/main/java/net/jqwik/api/ArbitrarySupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public interface ArbitrarySupplier<T> extends Supplier<Arbitrary<T>> {
*
* @return A new arbitrary instance
*/
@Nullable
default Arbitrary<T> supplyFor(TypeUsage targetType) {
default @Nullable Arbitrary<T> supplyFor(TypeUsage targetType) {
return get();
}

Expand All @@ -50,8 +49,7 @@ default Arbitrary<T> supplyFor(TypeUsage targetType) {
*
* @return A new arbitrary instance
*/
@Nullable
default Arbitrary<T> get() {
default @Nullable Arbitrary<T> get() {
throw new JqwikException("You have to override either ArbitrarySupplier.get() or ArbitrarySupplier.supplyFor()");
}

Expand Down
5 changes: 2 additions & 3 deletions api/src/main/java/net/jqwik/api/Builders.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ private BuilderCombinator(Supplier<B> starter, List<Tuple3<Double, Arbitrary<Obj
* @param <T> the target object's type
* @return arbitrary of target object
*/
public <T> Arbitrary<T> build(Function<B, T> buildFunction) {
public <T extends @Nullable Object> Arbitrary<T> build(Function<B, T> buildFunction) {

class Holder {
@Nullable
final Object value;
final @Nullable Object value;

Holder(@Nullable Object value) {
this.value = value;
Expand Down
Loading

0 comments on commit 949f472

Please sign in to comment.