Skip to content

Commit 3b35f4c

Browse files
authored
Merge pull request #929 from jeffgbutler/properly-handle-nulls
JSpecify Related Update: Properly handle nulls in the "when present" conditions
2 parents d8f3298 + b3b3b7d commit 3b35f4c

File tree

58 files changed

+2002
-648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2002
-648
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ Runtime behavior changes:
8282
2. We have updated the "ParameterTypeConverter" used in Spring applications to maintain compatibility with Spring's
8383
"Converter" interface. The primary change is that the framework will no longer call a type converter if the
8484
input value is null. This should simplify the coding of converters and foster reuse with existing Spring converters.
85+
3. The "map" method on the "WhenPresent" conditions will accept a mapper function that may return a null value. The
86+
conditions will now properly handle this outcome
8587

8688
### Other important changes:
8789

Diff for: pom.xml

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676

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

8082
<kotlin.code.style>official</kotlin.code.style>
8183
<test.containers.version>1.20.6</test.containers.version>

Diff for: src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.stream.Collectors;
2424
import java.util.stream.Stream;
2525

26+
import org.jspecify.annotations.NonNull;
2627
import org.mybatis.dynamic.sql.render.RenderedParameterInfo;
2728
import org.mybatis.dynamic.sql.render.RenderingContext;
2829
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
@@ -113,7 +114,7 @@ public interface Filterable<T> {
113114
* @return this condition if renderable and the value matches the predicate, otherwise a condition
114115
* that will not render.
115116
*/
116-
AbstractListValueCondition<T> filter(Predicate<? super T> predicate);
117+
AbstractListValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
117118
}
118119

119120
/**
@@ -138,6 +139,6 @@ public interface Mappable<T> {
138139
* @return a new condition with the result of applying the mapper to the value of this condition,
139140
* if renderable, otherwise a condition that will not render.
140141
*/
141-
<R> AbstractListValueCondition<R> map(Function<? super T, ? extends R> mapper);
142+
<R> AbstractListValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper);
142143
}
143144
}

Diff for: src/main/java/org/mybatis/dynamic/sql/AbstractNoValueCondition.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public interface Filterable {
6060
* @param <S>
6161
* condition type - not used except for compilation compliance
6262
*
63-
* @return this condition if renderable and the supplier returns true, otherwise a condition that will not render.
63+
* @return this condition if renderable and the supplier returns true, otherwise a condition that will not
64+
* render.
6465
*/
6566
<S> AbstractNoValueCondition<S> filter(BooleanSupplier booleanSupplier);
6667
}

Diff for: src/main/java/org/mybatis/dynamic/sql/AbstractSingleValueCondition.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.function.Predicate;
2222
import java.util.function.Supplier;
2323

24+
import org.jspecify.annotations.NonNull;
2425
import org.mybatis.dynamic.sql.render.RenderedParameterInfo;
2526
import org.mybatis.dynamic.sql.render.RenderingContext;
2627
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
@@ -88,7 +89,7 @@ public interface Filterable<T> {
8889
* @return this condition if renderable and the value matches the predicate, otherwise a condition
8990
* that will not render.
9091
*/
91-
AbstractSingleValueCondition<T> filter(Predicate<? super T> predicate);
92+
AbstractSingleValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
9293
}
9394

9495
/**
@@ -113,6 +114,6 @@ public interface Mappable<T> {
113114
* @return a new condition with the result of applying the mapper to the value of this condition,
114115
* if renderable, otherwise a condition that will not render.
115116
*/
116-
<R> AbstractSingleValueCondition<R> map(Function<? super T, ? extends R> mapper);
117+
<R> AbstractSingleValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper);
117118
}
118119
}

Diff for: src/main/java/org/mybatis/dynamic/sql/AbstractTwoValueCondition.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.function.Predicate;
2424
import java.util.function.Supplier;
2525

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

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

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

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

0 commit comments

Comments
 (0)