Skip to content

Commit 13ff2d6

Browse files
christophstroblmp911de
authored andcommittedMay 16, 2025
Migrate to JSpecify annotations for nullability constraints.
Closes: #4874
1 parent 6531bc7 commit 13ff2d6

File tree

422 files changed

+3143
-1761
lines changed

Some content is hidden

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

422 files changed

+3143
-1761
lines changed
 

‎spring-data-mongodb/pom.xml

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,76 @@
353353

354354
</dependencies>
355355

356-
<build>
356+
<profiles>
357+
<profile>
358+
<id>nullaway</id>
359+
<build>
360+
<plugins>
361+
<plugin>
362+
<groupId>org.apache.maven.plugins</groupId>
363+
<artifactId>maven-compiler-plugin</artifactId>
364+
<configuration>
365+
<annotationProcessorPaths>
366+
<path>
367+
<groupId>com.querydsl</groupId>
368+
<artifactId>querydsl-apt</artifactId>
369+
<version>${querydsl}</version>
370+
</path>
371+
<path>
372+
<groupId>org.openjdk.jmh</groupId>
373+
<artifactId>jmh-generator-annprocess</artifactId>
374+
<version>${jmh}</version>
375+
</path>
376+
<path>
377+
<groupId>com.google.errorprone</groupId>
378+
<artifactId>error_prone_core</artifactId>
379+
<version>${errorprone}</version>
380+
</path>
381+
<path>
382+
<groupId>com.uber.nullaway</groupId>
383+
<artifactId>nullaway</artifactId>
384+
<version>${nullaway}</version>
385+
</path>
386+
</annotationProcessorPaths>
387+
</configuration>
388+
<executions>
389+
<execution>
390+
<id>default-compile</id>
391+
<phase>none</phase>
392+
</execution>
393+
<execution>
394+
<id>default-testCompile</id>
395+
<phase>none</phase>
396+
</execution>
397+
<execution>
398+
<id>java-compile</id>
399+
<phase>compile</phase>
400+
<goals>
401+
<goal>compile</goal>
402+
</goals>
403+
<configuration>
404+
<compilerArgs>
405+
<arg>-XDcompilePolicy=simple</arg>
406+
<arg>--should-stop=ifError=FLOW</arg>
407+
<arg>-Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true -XepOpt:NullAway:TreatGeneratedAsUnannotated=true -XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract</arg>
408+
</compilerArgs>
409+
</configuration>
410+
</execution>
411+
<execution>
412+
<id>java-test-compile</id>
413+
<phase>test-compile</phase>
414+
<goals>
415+
<goal>testCompile</goal>
416+
</goals>
417+
</execution>
418+
</executions>
419+
</plugin>
420+
</plugins>
421+
</build>
422+
</profile>
423+
</profiles>
357424

425+
<build>
358426
<plugins>
359427

360428
<plugin>

‎spring-data-mongodb/src/main/java/org/springframework/data/mongodb/BindableMongoExpression.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import org.bson.Document;
2121
import org.bson.codecs.DocumentCodec;
2222
import org.bson.codecs.configuration.CodecRegistry;
23+
import org.jspecify.annotations.Nullable;
2324
import org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec;
2425
import org.springframework.data.util.Lazy;
25-
import org.springframework.lang.Nullable;
26+
import org.springframework.lang.Contract;
2627
import org.springframework.util.Assert;
2728
import org.springframework.util.ObjectUtils;
2829
import org.springframework.util.StringUtils;
@@ -31,8 +32,7 @@
3132
* A {@link MongoExpression} using the {@link ParameterBindingDocumentCodec} for parsing a raw ({@literal json})
3233
* expression. The expression will be wrapped within <code>{ ... }</code> if necessary. The actual parsing and parameter
3334
* binding of placeholders like {@code ?0} is delayed upon first call on the target {@link Document} via
34-
* {@link #toDocument()}.
35-
* <br />
35+
* {@link #toDocument()}. <br />
3636
*
3737
* <pre class="code">
3838
* $toUpper : $name -> { '$toUpper' : '$name' }
@@ -55,17 +55,17 @@ public class BindableMongoExpression implements MongoExpression {
5555

5656
private final @Nullable CodecRegistryProvider codecRegistryProvider;
5757

58-
private final @Nullable Object[] args;
58+
private final Object @Nullable [] args;
5959

6060
private final Lazy<Document> target;
6161

6262
/**
6363
* Create a new instance of {@link BindableMongoExpression}.
6464
*
6565
* @param expression must not be {@literal null}.
66-
* @param args can be {@literal null}.
66+
* @param args must not be {@literal null} but may contain {@literal null} elements.
6767
*/
68-
public BindableMongoExpression(String expression, @Nullable Object[] args) {
68+
public BindableMongoExpression(String expression, Object @Nullable [] args) {
6969
this(expression, null, args);
7070
}
7171

@@ -74,10 +74,10 @@ public BindableMongoExpression(String expression, @Nullable Object[] args) {
7474
*
7575
* @param expression must not be {@literal null}.
7676
* @param codecRegistryProvider can be {@literal null}.
77-
* @param args can be {@literal null}.
77+
* @param args must not be {@literal null} but may contain {@literal null} elements.
7878
*/
7979
public BindableMongoExpression(String expression, @Nullable CodecRegistryProvider codecRegistryProvider,
80-
@Nullable Object[] args) {
80+
Object @Nullable [] args) {
8181

8282
Assert.notNull(expression, "Expression must not be null");
8383

@@ -93,6 +93,7 @@ public BindableMongoExpression(String expression, @Nullable CodecRegistryProvide
9393
* @param codecRegistry must not be {@literal null}.
9494
* @return new instance of {@link BindableMongoExpression}.
9595
*/
96+
@Contract("_ -> new")
9697
public BindableMongoExpression withCodecRegistry(CodecRegistry codecRegistry) {
9798
return new BindableMongoExpression(expressionString, () -> codecRegistry, args);
9899
}
@@ -103,6 +104,7 @@ public BindableMongoExpression withCodecRegistry(CodecRegistry codecRegistry) {
103104
* @param args must not be {@literal null}.
104105
* @return new instance of {@link BindableMongoExpression}.
105106
*/
107+
@Contract("_ -> new")
106108
public BindableMongoExpression bind(Object... args) {
107109
return new BindableMongoExpression(expressionString, codecRegistryProvider, args);
108110
}
@@ -139,7 +141,7 @@ private Document parse() {
139141

140142
private static String wrapJsonIfNecessary(String json) {
141143

142-
if(!StringUtils.hasText(json)) {
144+
if (!StringUtils.hasText(json)) {
143145
return json;
144146
}
145147

0 commit comments

Comments
 (0)
Please sign in to comment.