Skip to content

Commit 697b1dc

Browse files
authoredJan 4, 2025
Merge pull request #890 from jeffgbutler/jspecify
Adopt JSpecify
2 parents fb789ac + 4f81c07 commit 697b1dc

File tree

180 files changed

+1459
-710
lines changed

Some content is hidden

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

180 files changed

+1459
-710
lines changed
 

‎CHANGELOG.md

+60-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ you are unable to move to this version of Java then the releases in the 1.x line
1010
In addition, we have taken the opportunity to make changes to the library that may break existing code. We have
1111
worked to make these changes as minimal as possible.
1212

13-
**Potentially Breaking Changes:**
13+
### Potentially Breaking Changes:
1414

1515
- If you use this library with MyBatis' Spring Batch integration, you will need to make changes as we have
1616
refactored that support to be more flexible. Please see the
@@ -25,7 +25,65 @@ worked to make these changes as minimal as possible.
2525
[Extending the Library](https://mybatis.org/mybatis-dynamic-sql/docs/extending.html) page, the change should be
2626
limited to changing the private constructor to accept `BasicColumn` rather than `BindableColumn`.
2727

28-
Other important changes:
28+
### Adoption of JSpecify (https://jspecify.dev/)
29+
30+
Following the lead of many other projects (including The Spring Framework), we have adopted JSpecify to fully
31+
document the null handling properties of this library. JSpecify is now a runtime dependency - as is
32+
recommended practice with JSpecify.
33+
34+
This change should not impact the running of any existing code, but depending on your usage you may see new IDE or
35+
tooling warnings based on the declared nullability of methods in the library. You may choose to ignore the
36+
warnings and things should continue to function. Of course, we recommend that you do not ignore these warnings!
37+
38+
In general, the library does not expect that you will pass a null value into any method. There are two exceptions to
39+
this rule:
40+
41+
1. Some builder methods will accept a null value if the target object will properly handle null values through the
42+
use of java.util.Optional
43+
2. Methods with names that include "WhenPresent" will properly handle null parameters
44+
(for example, "isEqualToWhenPresent")
45+
46+
As you might expect, standardizing null handling revealed some issues in the library that may impact you.
47+
48+
Fixing compiler warnings and errors:
49+
50+
1. We expect that most of the warnings you encounter will be related to passing null values into a where condition.
51+
These warnings should be resolved by changing your code to use the "WhenPresent" versions of methods as those
52+
methods handle null values in a predictable way.
53+
2. Java Classes that extend "AliasableSqlTable" will likely see IDE warnings about non-null type arguments. This can be
54+
resolved by adding a "@NullMarked" annotation to the class or package. This issue does not affect Kotlin classes
55+
that extend "AliasableSqlTable".
56+
3. Similarly, if you have coded any functions for use with your queries, you can resolve most IDE warnings by adding
57+
the "@NullMarked" annotation.
58+
4. If you have coded any Kotlin functions that operate on a generic Java class from the library, then you should
59+
change the type parameter definition to specify a non-nullable type. For example...
60+
61+
```kotlin
62+
import org.mybatis.dynamic.sql.SqlColumn
63+
64+
fun <T> foo(column: SqlColumn<T>) {
65+
}
66+
```
67+
68+
Should change to:
69+
70+
```kotlin
71+
import org.mybatis.dynamic.sql.SqlColumn
72+
73+
fun <T : Any> foo(column: SqlColumn<T>) {
74+
}
75+
```
76+
77+
Runtime behavior changes:
78+
79+
1. The where conditions (isEqualTo, isLessThan, etc.) can be filtered and result in an "empty" condition -
80+
similar to java.util.Optional. Previously, calling a "value" method of the condition would return null. Now
81+
those methods will throw "NoSuchElementException". This should not impact you in normal usage.
82+
2. We have updated the "ParameterTypeConverter" used in Spring applications to maintain compatibility with Spring's
83+
"Converter" interface. The primary change is that the framework will no longer call a type converter if the
84+
input value is null. This should simplify the coding of converters and foster reuse with existing Spring converters.
85+
86+
### Other important changes:
2987

3088
- The library now requires Java 17
3189
- Deprecated code from prior releases is removed

‎README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ The library test cases provide several complete examples of using the library in
7878
| Kotlin | Spring JDBC | Example using Kotlin utility classes for Spring JDBC Template | [../examples/kotlin/spring/canonical](src/test/kotlin/examples/kotlin/spring/canonical) |
7979

8080

81-
## Requirements
81+
## Requirements and Dependencies
8282

83-
The library has no dependencies. Version 2.x requires Java 17. Version 1.x requires Java 8.
83+
Version 2.x requires Java 17 and has a required runtime dependency on JSpecify (https://jspecify.dev/). Version 1.x
84+
requires Java 8 and has no required runtime dependencies.
85+
86+
All versions have support for MyBatis3, Spring Framework, and Kotlin - all those dependencies are optional. The library
87+
should work in those environments as the dependencies will be made available at runtime.

0 commit comments

Comments
 (0)