Skip to content

Commit 9bdb6a4

Browse files
Fix nullable issues.
1 parent c84a6c2 commit 9bdb6a4

File tree

8 files changed

+31
-22
lines changed

8 files changed

+31
-22
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/AggregationBlocks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private static Class<?> getOutputType(MongoQueryMethod queryMethod) {
156156
Class<?> outputType = queryMethod.getReturnedObjectType();
157157
if (MongoSimpleTypes.HOLDER.isSimpleType(outputType)) {
158158
outputType = Document.class;
159-
} else if (ClassUtils.isAssignable(AggregationResults.class, outputType)) {
159+
} else if (ClassUtils.isAssignable(AggregationResults.class, outputType) && queryMethod.getReturnType().getComponentType() != null) {
160160
outputType = queryMethod.getReturnType().getComponentType().getType();
161161
}
162162
return outputType;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/AotPlaceholders.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static Placeholder indexed(int position) {
5353
* @param type
5454
* @return
5555
*/
56-
public static Shape geoJson(int index, String type) {
56+
static Shape geoJson(int index, String type) {
5757
return new GeoJsonPlaceholder(index, type);
5858
}
5959

@@ -63,7 +63,7 @@ public static Shape geoJson(int index, String type) {
6363
* @param index zero-based index referring to the bindable method parameter.
6464
* @return
6565
*/
66-
public static Point point(int index) {
66+
static Point point(int index) {
6767
return new PointPlaceholder(index);
6868
}
6969

@@ -73,7 +73,7 @@ public static Point point(int index) {
7373
* @param index zero-based index referring to the bindable method parameter.
7474
* @return
7575
*/
76-
public static Shape circle(int index) {
76+
static Shape circle(int index) {
7777
return new CirclePlaceholder(index);
7878
}
7979

@@ -83,7 +83,7 @@ public static Shape circle(int index) {
8383
* @param index zero-based index referring to the bindable method parameter.
8484
* @return
8585
*/
86-
public static Shape box(int index) {
86+
static Shape box(int index) {
8787
return new BoxPlaceholder(index);
8888
}
8989

@@ -93,7 +93,7 @@ public static Shape box(int index) {
9393
* @param index zero-based index referring to the bindable method parameter.
9494
* @return
9595
*/
96-
public static Shape sphere(int index) {
96+
static Shape sphere(int index) {
9797
return new SpherePlaceholder(index);
9898
}
9999

@@ -103,11 +103,11 @@ public static Shape sphere(int index) {
103103
* @param index zero-based index referring to the bindable method parameter.
104104
* @return
105105
*/
106-
public static Shape polygon(int index) {
106+
static Shape polygon(int index) {
107107
return new PolygonPlaceholder(index);
108108
}
109109

110-
public static RegexPlaceholder regex(int index, @Nullable String options) {
110+
static RegexPlaceholder regex(int index, @Nullable String options) {
111111
return new RegexPlaceholder(index, options);
112112
}
113113

@@ -117,7 +117,7 @@ public static RegexPlaceholder regex(int index, @Nullable String options) {
117117
* @since 5.0
118118
* @author Christoph Strobl
119119
*/
120-
public interface Placeholder {
120+
interface Placeholder {
121121

122122
String getValue();
123123
}
@@ -143,7 +143,7 @@ private static class PointPlaceholder extends Point implements Placeholder {
143143

144144
private final int index;
145145

146-
public PointPlaceholder(int index) {
146+
PointPlaceholder(int index) {
147147
super(Double.NaN, Double.NaN);
148148
this.index = index;
149149
}
@@ -188,7 +188,7 @@ private static class CirclePlaceholder extends Circle implements Placeholder {
188188

189189
private final int index;
190190

191-
public CirclePlaceholder(int index) {
191+
CirclePlaceholder(int index) {
192192
super(new PointPlaceholder(index), Distance.of(1, Metrics.NEUTRAL)); //
193193
this.index = index;
194194
}
@@ -209,7 +209,7 @@ private static class BoxPlaceholder extends Box implements Placeholder {
209209

210210
private final int index;
211211

212-
public BoxPlaceholder(int index) {
212+
BoxPlaceholder(int index) {
213213
super(new PointPlaceholder(index), new PointPlaceholder(index));
214214
this.index = index;
215215
}
@@ -230,7 +230,7 @@ private static class SpherePlaceholder extends Sphere implements Placeholder {
230230

231231
private final int index;
232232

233-
public SpherePlaceholder(int index) {
233+
SpherePlaceholder(int index) {
234234
super(new PointPlaceholder(index), Distance.of(1, Metrics.NEUTRAL)); //
235235
this.index = index;
236236
}
@@ -251,7 +251,7 @@ private static class PolygonPlaceholder extends Polygon implements Placeholder {
251251

252252
private final int index;
253253

254-
public PolygonPlaceholder(int index) {
254+
PolygonPlaceholder(int index) {
255255
super(new PointPlaceholder(index), new PointPlaceholder(index), new PointPlaceholder(index),
256256
new PointPlaceholder(index));
257257
this.index = index;
@@ -272,14 +272,14 @@ public String toString() {
272272
static class RegexPlaceholder implements Placeholder {
273273

274274
private final int index;
275-
private final String options;
275+
private final @Nullable String options;
276276

277-
public RegexPlaceholder(int index, String options) {
277+
RegexPlaceholder(int index, @Nullable String options) {
278278
this.index = index;
279279
this.options = options;
280280
}
281281

282-
public @Nullable String regexOptions() {
282+
@Nullable String regexOptions() {
283283
return options;
284284
}
285285

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/AotStringQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ boolean isRegexPlaceholderAt(int index) {
8787
return this.placeholders.get(index) instanceof RegexPlaceholder;
8888
}
8989

90-
String getRegexOptions(int index) {
90+
@Nullable String getRegexOptions(int index) {
9191
if(this.placeholders.isEmpty()) {
9292
return null;
9393
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/MongoAotRepositoryFragmentSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ protected Object toRegex(Object source) {
233233
return toRegex(source, null);
234234
}
235235

236-
protected Object toRegex(Object source, String options) {
236+
protected Object toRegex(Object source, @Nullable String options) {
237237

238238
if (source instanceof String sv) {
239239
return new BsonRegularExpression(MongoRegexCreator.INSTANCE.toRegularExpression(sv, MatchMode.LIKE), options);
@@ -256,6 +256,7 @@ protected BasicQuery createQuery(Method method, String queryString, Object... pa
256256
return new BasicQuery(queryDocument);
257257
}
258258

259+
@SuppressWarnings("NullAway")
259260
protected AggregationPipeline createPipeline(List<Object> rawStages) {
260261

261262
if (rawStages.isEmpty()) {

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/MongoRepositoryContributor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public MongoRepositoryContributor(AotRepositoryContext repositoryContext) {
9393
this.queryCreator = new AotQueryCreator(this.mappingContext);
9494
}
9595

96+
@SuppressWarnings("NullAway")
9697
private NamedQueries getNamedQueries(@Nullable RepositoryConfigurationSource configSource, ClassLoader classLoader) {
9798

9899
String location = configSource != null ? configSource.getNamedQueryLocation().orElse(null) : null;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/aot/Snippet.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.data.mongodb.repository.aot.Snippet.BuilderStyleVariableBuilder.BuilderStyleVariableBuilderImpl;
2424
import org.springframework.javapoet.CodeBlock;
2525
import org.springframework.javapoet.CodeBlock.Builder;
26+
import org.springframework.util.Assert;
2627

2728
/**
2829
* @author Christoph Strobl
@@ -192,12 +193,17 @@ public BuilderStyleMethodArgumentBuilder call(String methodName) {
192193

193194
@Override
194195
public BuilderStyleBuilder with(Snippet snippet) {
196+
197+
Assert.notNull(targetMethodName, "TargetMethodName must be set before calling this method");
198+
195199
new BuilderStyleSnippet(targetVariableName, targetMethodName, snippet).appendTo(targetBuilder);
196200
return this;
197201
}
198202

199203
@Override
200204
public VariableSnippet variable() {
205+
206+
Assert.notNull(variableSnippet, "VariableSnippet must not be null");
201207
return this.variableSnippet;
202208
}
203209
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,9 @@ private Criteria createNearCriteria(MongoPersistentProperty property, Criteria c
258258
Iterator<Object> parameters) {
259259

260260
Range<Distance> range = accessor.getDistanceRange();
261-
Optional<Distance> distance = range.getUpperBound().getValue();
262-
Optional<Distance> minDistance = range.getLowerBound().getValue();
261+
262+
Optional<Distance> distance = range != null ? range.getUpperBound().getValue() : Optional.empty();
263+
Optional<Distance> minDistance = range != null ? range.getLowerBound().getValue() : Optional.empty();
263264

264265
Point point = accessor.getGeoNearLocation();
265266
Point pointToUse = point == null ? nextAs(parameters, Point.class) : point;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryExecution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ NearQuery nearQuery(Query query) {
202202
}
203203

204204
Range<Distance> distances = accessor.getDistanceRange();
205-
Assert.notNull(nearLocation, "[query.distance] must not be null");
205+
Assert.notNull(distances, "[query.distances] must not be null");
206206

207207
distances.getLowerBound().getValue().ifPresent(it -> nearQuery.minDistance(it).in(it.getMetric()));
208208
distances.getUpperBound().getValue().ifPresent(it -> nearQuery.maxDistance(it).in(it.getMetric()));

0 commit comments

Comments
 (0)