Skip to content

JSpecify Related Update: Properly handle nulls in the "when present" conditions #929

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 11 commits into from
Apr 7, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Runtime behavior changes:
2. We have updated the "ParameterTypeConverter" used in Spring applications to maintain compatibility with Spring's
"Converter" interface. The primary change is that the framework will no longer call a type converter if the
input value is null. This should simplify the coding of converters and foster reuse with existing Spring converters.
3. The "map" method on the "WhenPresent" conditions will accept a mapper function that may return a null value. The
conditions will now properly handle this outcome

### Other important changes:

Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@

<sonar.sources>pom.xml,src/main/java,src/main/kotlin</sonar.sources>
<sonar.tests>src/test/java,src/test/kotlin</sonar.tests>
<!-- setup sonar to run locally by default -->
<sonar.host.url>http://localhost:9000</sonar.host.url>

<kotlin.code.style>official</kotlin.code.style>
<test.containers.version>1.20.6</test.containers.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.jspecify.annotations.NonNull;
import org.mybatis.dynamic.sql.render.RenderedParameterInfo;
import org.mybatis.dynamic.sql.render.RenderingContext;
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
Expand Down Expand Up @@ -113,7 +114,7 @@ public interface Filterable<T> {
* @return this condition if renderable and the value matches the predicate, otherwise a condition
* that will not render.
*/
AbstractListValueCondition<T> filter(Predicate<? super T> predicate);
AbstractListValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
}

/**
Expand All @@ -138,6 +139,6 @@ public interface Mappable<T> {
* @return a new condition with the result of applying the mapper to the value of this condition,
* if renderable, otherwise a condition that will not render.
*/
<R> AbstractListValueCondition<R> map(Function<? super T, ? extends R> mapper);
<R> AbstractListValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public interface Filterable {
* @param <S>
* condition type - not used except for compilation compliance
*
* @return this condition if renderable and the supplier returns true, otherwise a condition that will not render.
* @return this condition if renderable and the supplier returns true, otherwise a condition that will not
* render.
*/
<S> AbstractNoValueCondition<S> filter(BooleanSupplier booleanSupplier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

import org.jspecify.annotations.NonNull;
import org.mybatis.dynamic.sql.render.RenderedParameterInfo;
import org.mybatis.dynamic.sql.render.RenderingContext;
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
Expand Down Expand Up @@ -88,7 +89,7 @@ public interface Filterable<T> {
* @return this condition if renderable and the value matches the predicate, otherwise a condition
* that will not render.
*/
AbstractSingleValueCondition<T> filter(Predicate<? super T> predicate);
AbstractSingleValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
}

/**
Expand All @@ -113,6 +114,6 @@ public interface Mappable<T> {
* @return a new condition with the result of applying the mapper to the value of this condition,
* if renderable, otherwise a condition that will not render.
*/
<R> AbstractSingleValueCondition<R> map(Function<? super T, ? extends R> mapper);
<R> AbstractSingleValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

import org.jspecify.annotations.NonNull;
import org.mybatis.dynamic.sql.render.RenderedParameterInfo;
import org.mybatis.dynamic.sql.render.RenderingContext;
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
Expand Down Expand Up @@ -110,7 +111,7 @@ public interface Filterable<T> {
* @return this condition if renderable and the values match the predicate, otherwise a condition
* that will not render.
*/
AbstractTwoValueCondition<T> filter(BiPredicate<? super T, ? super T> predicate);
AbstractTwoValueCondition<T> filter(BiPredicate<? super @NonNull T, ? super @NonNull T> predicate);

/**
* If renderable and both values match the predicate, returns this condition. Else returns a condition
Expand All @@ -121,7 +122,7 @@ public interface Filterable<T> {
* @return this condition if renderable and the values match the predicate, otherwise a condition
* that will not render.
*/
AbstractTwoValueCondition<T> filter(Predicate<? super T> predicate);
AbstractTwoValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
}

/**
Expand All @@ -147,8 +148,8 @@ public interface Mappable<T> {
* @return a new condition with the result of applying the mappers to the values of this condition,
* if renderable, otherwise a condition that will not render.
*/
<R> AbstractTwoValueCondition<R> map(Function<? super T, ? extends R> mapper1,
Function<? super T, ? extends R> mapper2);
<R> AbstractTwoValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper1,
Function<? super @NonNull T, ? extends R> mapper2);

/**
* If renderable, apply the mapping to both values and return a new condition with the new values. Else return a
Expand All @@ -159,6 +160,6 @@ <R> AbstractTwoValueCondition<R> map(Function<? super T, ? extends R> mapper1,
* @return a new condition with the result of applying the mappers to the values of this condition,
* if renderable, otherwise a condition that will not render.
*/
<R> AbstractTwoValueCondition<R> map(Function<? super T, ? extends R> mapper);
<R> AbstractTwoValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper);
}
}
Loading
Loading