diff --git a/src/main/java/org/springframework/data/elasticsearch/BulkFailureException.java b/src/main/java/org/springframework/data/elasticsearch/BulkFailureException.java index aa5ffe199..2af490710 100644 --- a/src/main/java/org/springframework/data/elasticsearch/BulkFailureException.java +++ b/src/main/java/org/springframework/data/elasticsearch/BulkFailureException.java @@ -15,10 +15,11 @@ */ package org.springframework.data.elasticsearch; -import org.springframework.dao.DataRetrievalFailureException; - import java.util.Map; +import org.jspecify.annotations.Nullable; +import org.springframework.dao.DataRetrievalFailureException; + /** * @author Peter-Josef Meisch * @author Illia Ulianov @@ -42,6 +43,6 @@ public class BulkFailureException extends DataRetrievalFailureException { * @author Illia Ulianov * @since 5.2 */ - public record FailureDetails(Integer status, String errorMessage) { + public record FailureDetails(Integer status, @Nullable String errorMessage) { } } diff --git a/src/main/java/org/springframework/data/elasticsearch/ElasticsearchErrorCause.java b/src/main/java/org/springframework/data/elasticsearch/ElasticsearchErrorCause.java index 54f486466..73274228c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/ElasticsearchErrorCause.java +++ b/src/main/java/org/springframework/data/elasticsearch/ElasticsearchErrorCause.java @@ -28,7 +28,7 @@ import org.jspecify.annotations.Nullable; public class ElasticsearchErrorCause { @Nullable private final String type; - private final String reason; + @Nullable private final String reason; @Nullable private final String stackTrace; @@ -38,7 +38,7 @@ public class ElasticsearchErrorCause { private final List suppressed; - public ElasticsearchErrorCause(@Nullable String type, String reason, @Nullable String stackTrace, + public ElasticsearchErrorCause(@Nullable String type, @Nullable String reason, @Nullable String stackTrace, @Nullable ElasticsearchErrorCause causedBy, List rootCause, List suppressed) { this.type = type; @@ -54,7 +54,7 @@ public class ElasticsearchErrorCause { return type; } - public String getReason() { + public @Nullable String getReason() { return reason; } diff --git a/src/main/java/org/springframework/data/elasticsearch/annotations/package-info.java b/src/main/java/org/springframework/data/elasticsearch/annotations/package-info.java index 4b8ccdf64..cf00c624a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/annotations/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/annotations/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.annotations; diff --git a/src/main/java/org/springframework/data/elasticsearch/aot/package-info.java b/src/main/java/org/springframework/data/elasticsearch/aot/package-info.java index 56697c102..d9ac43b78 100644 --- a/src/main/java/org/springframework/data/elasticsearch/aot/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/aot/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.aot; diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java index 4ec57321b..e5fcc1ef5 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java @@ -24,6 +24,14 @@ import co.elastic.clients.elasticsearch.core.search.Hit; import co.elastic.clients.elasticsearch.core.search.NestedIdentity; import co.elastic.clients.json.JsonData; import co.elastic.clients.json.JsonpMapper; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jspecify.annotations.Nullable; @@ -36,13 +44,6 @@ import org.springframework.data.elasticsearch.core.document.SearchDocumentAdapte import org.springframework.data.elasticsearch.core.document.SearchDocumentResponse; import org.springframework.util.Assert; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - /** * Utility class to adapt different Elasticsearch responses to a * {@link org.springframework.data.elasticsearch.core.document.Document} @@ -54,188 +55,187 @@ import java.util.stream.Collectors; */ final class DocumentAdapters { - private static final Log LOGGER = LogFactory.getLog(DocumentAdapters.class); + private static final Log LOGGER = LogFactory.getLog(DocumentAdapters.class); - private DocumentAdapters() { - } + private DocumentAdapters() {} - /** - * Creates a {@link SearchDocument} from a {@link Hit} returned by the Elasticsearch client. - * - * @param hit the hit object - * @param jsonpMapper to map JsonData objects - * @return the created {@link SearchDocument} - */ - public static SearchDocument from(Hit hit, JsonpMapper jsonpMapper) { + /** + * Creates a {@link SearchDocument} from a {@link Hit} returned by the Elasticsearch client. + * + * @param hit the hit object + * @param jsonpMapper to map JsonData objects + * @return the created {@link SearchDocument} + */ + public static SearchDocument from(Hit hit, JsonpMapper jsonpMapper) { - Assert.notNull(hit, "hit must not be null"); + Assert.notNull(hit, "hit must not be null"); - Map> highlightFields = hit.highlight(); + Map> highlightFields = hit.highlight(); - Map innerHits = new LinkedHashMap<>(); - hit.innerHits().forEach((name, innerHitsResult) -> { - // noinspection ReturnOfNull - innerHits.put(name, SearchDocumentResponseBuilder.from(innerHitsResult.hits(), null, null, null, 0, null, null, - searchDocument -> null, jsonpMapper)); - }); + Map innerHits = new LinkedHashMap<>(); + hit.innerHits().forEach((name, innerHitsResult) -> { + // noinspection ReturnOfNull + innerHits.put(name, SearchDocumentResponseBuilder.from(innerHitsResult.hits(), null, null, null, 0, null, null, + searchDocument -> null, jsonpMapper)); + }); - NestedMetaData nestedMetaData = from(hit.nested()); + NestedMetaData nestedMetaData = from(hit.nested()); - Explanation explanation = from(hit.explanation()); + Explanation explanation = from(hit.explanation()); - Map matchedQueries = hit.matchedQueries(); + Map matchedQueries = hit.matchedQueries(); - Function, EntityAsMap> fromFields = fields -> { - StringBuilder sb = new StringBuilder("{"); - final boolean[] firstField = {true}; - hit.fields().forEach((key, jsonData) -> { - if (!firstField[0]) { - sb.append(','); - } - sb.append('"').append(key).append("\":") // - .append(jsonData.toJson(jsonpMapper).toString()); - firstField[0] = false; - }); - sb.append('}'); - return new EntityAsMap().fromJson(sb.toString()); - }; + Function, EntityAsMap> fromFields = fields -> { + StringBuilder sb = new StringBuilder("{"); + final boolean[] firstField = { true }; + hit.fields().forEach((key, jsonData) -> { + if (!firstField[0]) { + sb.append(','); + } + sb.append('"').append(key).append("\":") // + .append(jsonData.toJson(jsonpMapper).toString()); + firstField[0] = false; + }); + sb.append('}'); + return new EntityAsMap().fromJson(sb.toString()); + }; - EntityAsMap hitFieldsAsMap = fromFields.apply(hit.fields()); + EntityAsMap hitFieldsAsMap = fromFields.apply(hit.fields()); - Map> documentFields = new LinkedHashMap<>(); - hitFieldsAsMap.forEach((key, value) -> { - if (value instanceof List) { - // noinspection unchecked - documentFields.put(key, (List) value); - } else { - documentFields.put(key, Collections.singletonList(value)); - } - }); + Map> documentFields = new LinkedHashMap<>(); + hitFieldsAsMap.forEach((key, value) -> { + if (value instanceof List) { + // noinspection unchecked + documentFields.put(key, (List) value); + } else { + documentFields.put(key, Collections.singletonList(value)); + } + }); - Document document; - Object source = hit.source(); - if (source == null) { - document = Document.from(hitFieldsAsMap); - } else { - if (source instanceof EntityAsMap entityAsMap) { - document = Document.from(entityAsMap); - } else if (source instanceof JsonData jsonData) { - document = Document.from(jsonData.to(EntityAsMap.class)); - } else { + Document document; + Object source = hit.source(); + if (source == null) { + document = Document.from(hitFieldsAsMap); + } else { + if (source instanceof EntityAsMap entityAsMap) { + document = Document.from(entityAsMap); + } else if (source instanceof JsonData jsonData) { + document = Document.from(jsonData.to(EntityAsMap.class)); + } else { - if (LOGGER.isWarnEnabled()) { - LOGGER.warn(String.format("Cannot map from type " + source.getClass().getName())); - } - document = Document.create(); - } - } - document.setIndex(hit.index()); - document.setId(hit.id()); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(String.format("Cannot map from type " + source.getClass().getName())); + } + document = Document.create(); + } + } + document.setIndex(hit.index()); + document.setId(hit.id()); - if (hit.version() != null) { - document.setVersion(hit.version()); - } - document.setSeqNo(hit.seqNo() != null && hit.seqNo() >= 0 ? hit.seqNo() : -2); // -2 was the default value in the - // old client - document.setPrimaryTerm(hit.primaryTerm() != null && hit.primaryTerm() > 0 ? hit.primaryTerm() : 0); + if (hit.version() != null) { + document.setVersion(hit.version()); + } + document.setSeqNo(hit.seqNo() != null && hit.seqNo() >= 0 ? hit.seqNo() : -2); // -2 was the default value in the + // old client + document.setPrimaryTerm(hit.primaryTerm() != null && hit.primaryTerm() > 0 ? hit.primaryTerm() : 0); - float score = hit.score() != null ? hit.score().floatValue() : Float.NaN; - return new SearchDocumentAdapter(document, score, hit.sort().stream().map(TypeUtils::toObject).toArray(), - documentFields, highlightFields, innerHits, nestedMetaData, explanation, matchedQueries, hit.routing()); - } + float score = hit.score() != null ? hit.score().floatValue() : Float.NaN; + return new SearchDocumentAdapter(document, score, hit.sort().stream().map(TypeUtils::toObject).toArray(), + documentFields, highlightFields, innerHits, nestedMetaData, explanation, matchedQueries, hit.routing()); + } - public static SearchDocument from(CompletionSuggestOption completionSuggestOption) { + public static SearchDocument from(CompletionSuggestOption completionSuggestOption) { - Document document = completionSuggestOption.source() != null ? Document.from(completionSuggestOption.source()) - : Document.create(); - document.setIndex(completionSuggestOption.index()); + Document document = completionSuggestOption.source() != null ? Document.from(completionSuggestOption.source()) + : Document.create(); + document.setIndex(completionSuggestOption.index()); - if (completionSuggestOption.id() != null) { - document.setId(completionSuggestOption.id()); - } + if (completionSuggestOption.id() != null) { + document.setId(completionSuggestOption.id()); + } - float score = completionSuggestOption.score() != null ? completionSuggestOption.score().floatValue() : Float.NaN; - return new SearchDocumentAdapter(document, score, new Object[]{}, Collections.emptyMap(), Collections.emptyMap(), - Collections.emptyMap(), null, null, null, completionSuggestOption.routing()); - } + float score = completionSuggestOption.score() != null ? completionSuggestOption.score().floatValue() : Float.NaN; + return new SearchDocumentAdapter(document, score, new Object[] {}, Collections.emptyMap(), Collections.emptyMap(), + Collections.emptyMap(), null, null, null, completionSuggestOption.routing()); + } - @Nullable - private static Explanation from(co.elastic.clients.elasticsearch.core.explain.@Nullable Explanation explanation) { + @Nullable + private static Explanation from(co.elastic.clients.elasticsearch.core.explain.@Nullable Explanation explanation) { - if (explanation == null) { - return null; - } - List details = explanation.details().stream().map(DocumentAdapters::from).collect(Collectors.toList()); - return new Explanation(true, (double) explanation.value(), explanation.description(), details); - } + if (explanation == null) { + return null; + } + List details = explanation.details().stream().map(DocumentAdapters::from).collect(Collectors.toList()); + return new Explanation(true, (double) explanation.value(), explanation.description(), details); + } - private static Explanation from(ExplanationDetail explanationDetail) { + private static Explanation from(ExplanationDetail explanationDetail) { - List details = explanationDetail.details().stream().map(DocumentAdapters::from) - .collect(Collectors.toList()); - return new Explanation(null, (double) explanationDetail.value(), explanationDetail.description(), details); - } + List details = explanationDetail.details().stream().map(DocumentAdapters::from) + .collect(Collectors.toList()); + return new Explanation(null, (double) explanationDetail.value(), explanationDetail.description(), details); + } - @Nullable - private static NestedMetaData from(@Nullable NestedIdentity nestedIdentity) { + @Nullable + private static NestedMetaData from(@Nullable NestedIdentity nestedIdentity) { - if (nestedIdentity == null) { - return null; - } + if (nestedIdentity == null) { + return null; + } - NestedMetaData child = from(nestedIdentity.nested()); - return NestedMetaData.of(nestedIdentity.field(), nestedIdentity.offset(), child); - } + NestedMetaData child = from(nestedIdentity.nested()); + return NestedMetaData.of(nestedIdentity.field(), nestedIdentity.offset(), child); + } - /** - * Creates a {@link Document} from a {@link GetResponse} where the found document is contained as {@link EntityAsMap}. - * - * @param getResponse the response instance - * @return the Document - */ - @Nullable - public static Document from(GetResult getResponse) { + /** + * Creates a {@link Document} from a {@link GetResponse} where the found document is contained as {@link EntityAsMap}. + * + * @param getResponse the response instance + * @return the Document + */ + @Nullable + public static Document from(GetResult getResponse) { - Assert.notNull(getResponse, "getResponse must not be null"); + Assert.notNull(getResponse, "getResponse must not be null"); - if (!getResponse.found()) { - return null; - } + if (!getResponse.found()) { + return null; + } - Document document = getResponse.source() != null ? Document.from(getResponse.source()) : Document.create(); - document.setIndex(getResponse.index()); - document.setId(getResponse.id()); + Document document = getResponse.source() != null ? Document.from(getResponse.source()) : Document.create(); + document.setIndex(getResponse.index()); + document.setId(getResponse.id()); - if (getResponse.version() != null) { - document.setVersion(getResponse.version()); - } + if (getResponse.version() != null) { + document.setVersion(getResponse.version()); + } - if (getResponse.seqNo() != null) { - document.setSeqNo(getResponse.seqNo()); - } + if (getResponse.seqNo() != null) { + document.setSeqNo(getResponse.seqNo()); + } - if (getResponse.primaryTerm() != null) { - document.setPrimaryTerm(getResponse.primaryTerm()); - } + if (getResponse.primaryTerm() != null) { + document.setPrimaryTerm(getResponse.primaryTerm()); + } - return document; - } + return document; + } - /** - * Creates a list of {@link MultiGetItem}s from a {@link MgetResponse} where the data is contained as - * {@link EntityAsMap} instances. - * - * @param mgetResponse the response instance - * @return list of multiget items - */ - public static List> from(MgetResponse mgetResponse) { + /** + * Creates a list of {@link MultiGetItem}s from a {@link MgetResponse} where the data is contained as + * {@link EntityAsMap} instances. + * + * @param mgetResponse the response instance + * @return list of multiget items + */ + public static List> from(MgetResponse mgetResponse) { - Assert.notNull(mgetResponse, "mgetResponse must not be null"); + Assert.notNull(mgetResponse, "mgetResponse must not be null"); - return mgetResponse.docs().stream() // - .map(itemResponse -> MultiGetItem.of( // - itemResponse.isFailure() ? null : from(itemResponse.result()), // - ResponseConverter.getFailure(itemResponse))) - .collect(Collectors.toList()); - } + return mgetResponse.docs().stream() // + .map(itemResponse -> MultiGetItem.of( // + itemResponse.isFailure() ? null : from(itemResponse.result()), // + ResponseConverter.getFailure(itemResponse))) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/IndicesTemplate.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/IndicesTemplate.java index 1e1f8a741..eab321eaa 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/IndicesTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/IndicesTemplate.java @@ -114,7 +114,7 @@ public class IndicesTemplate extends ChildTemplate settings) { + public boolean create(Map settings) { Assert.notNull(settings, "settings must not be null"); @@ -122,7 +122,7 @@ public class IndicesTemplate extends ChildTemplate settings, Document mapping) { + public boolean create(Map settings, Document mapping) { Assert.notNull(settings, "settings must not be null"); Assert.notNull(mapping, "mapping must not be null"); @@ -135,7 +135,7 @@ public class IndicesTemplate extends ChildTemplate settings, + protected boolean doCreate(IndexCoordinates indexCoordinates, Map settings, @Nullable Document mapping) { Set aliases = (boundClass != null) ? getAliasesFor(boundClass) : new HashSet<>(); CreateIndexSettings indexSettings = CreateIndexSettings.builder(indexCoordinates) @@ -233,7 +233,7 @@ public class IndicesTemplate extends ChildTemplate getMapping() { + public Map getMapping() { IndexCoordinates indexCoordinates = getIndexCoordinates(); GetMappingRequest getMappingRequest = requestConverter.indicesGetMappingRequest(indexCoordinates); diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchTemplate.java index 97289c85c..38699137a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchTemplate.java @@ -18,9 +18,30 @@ package org.springframework.data.elasticsearch.client.elc; import static co.elastic.clients.util.ApiTypeHelper.*; import static org.springframework.data.elasticsearch.client.elc.TypeUtils.*; +import co.elastic.clients.elasticsearch._types.Result; +import co.elastic.clients.elasticsearch.core.*; +import co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem; +import co.elastic.clients.elasticsearch.core.search.ResponseBody; +import co.elastic.clients.json.JsonpMapper; +import co.elastic.clients.transport.Version; +import co.elastic.clients.transport.endpoints.BooleanResponse; +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationRegistry; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.util.function.Tuple2; + +import java.time.Duration; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.stream.Collectors; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.springframework.beans.BeansException; @@ -52,28 +73,6 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import java.time.Duration; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.stream.Collectors; - -import co.elastic.clients.elasticsearch._types.Result; -import co.elastic.clients.elasticsearch.core.*; -import co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem; -import co.elastic.clients.elasticsearch.core.search.ResponseBody; -import co.elastic.clients.json.JsonpMapper; -import co.elastic.clients.transport.Version; -import co.elastic.clients.transport.endpoints.BooleanResponse; -import io.micrometer.observation.Observation; -import io.micrometer.observation.ObservationRegistry; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.util.function.Tuple2; - /** * Implementation of {@link org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations} using the new * Elasticsearch client. @@ -269,7 +268,7 @@ public class ReactiveElasticsearchTemplate extends AbstractReactiveElasticsearch ExistsRequest existsRequest = requestConverter.documentExistsRequest(id, routingResolver.getRouting(), index); return Mono.from(execute( - ((ClientCallback<@NonNull Publisher>) client -> client.exists(existsRequest)))) + ((ClientCallback>) client -> client.exists(existsRequest)))) .map(BooleanResponse::value) // .onErrorReturn(NoSuchIndexException.class, false); } @@ -381,7 +380,7 @@ public class ReactiveElasticsearchTemplate extends AbstractReactiveElasticsearch for (BulkResponseItem item : bulkResponse.items()) { - if (item.error() != null) { + if (item.error() != null && item.id() != null) { failedDocuments.put(item.id(), new BulkFailureException.FailureDetails(item.status(), item.error().reason())); } } @@ -538,7 +537,7 @@ public class ReactiveElasticsearchTemplate extends AbstractReactiveElasticsearch return Mono.empty(); } - List sortOptions = hits.get(hits.size() - 1).sort().stream().map(TypeUtils::toObject) + List sortOptions = hits.get(hits.size() - 1).sort().stream().map(TypeUtils::toObjectNotNull) .collect(Collectors.toList()); baseQuery.setSearchAfter(sortOptions); SearchRequest followSearchRequest = requestConverter.searchRequest(baseQuery, @@ -632,8 +631,8 @@ public class ReactiveElasticsearchTemplate extends AbstractReactiveElasticsearch SearchRequest searchRequest = requestConverter.searchRequest(query, routingResolver.getRouting(), clazz, index, false); - // noinspection unchecked SearchDocumentCallback callback = new ReadSearchDocumentCallback<>((Class) clazz, index); + SearchDocumentResponse.EntityCreator entityCreator = searchDocument -> callback.toEntity(searchDocument) .toFuture(); diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveIndicesTemplate.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveIndicesTemplate.java index 57277ff13..f5133c3f8 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveIndicesTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveIndicesTemplate.java @@ -108,7 +108,7 @@ public class ReactiveIndicesTemplate } @Override - public Mono create(Map settings) { + public Mono create(Map settings) { Assert.notNull(settings, "settings must not be null"); @@ -116,7 +116,7 @@ public class ReactiveIndicesTemplate } @Override - public Mono create(Map settings, Document mapping) { + public Mono create(Map settings, Document mapping) { Assert.notNull(settings, "settings must not be null"); Assert.notNull(mapping, "mapping must not be null"); @@ -132,7 +132,7 @@ public class ReactiveIndicesTemplate doCreate(getIndexCoordinates(), settings, mapping))); // } - private Mono doCreate(IndexCoordinates indexCoordinates, Map settings, + private Mono doCreate(IndexCoordinates indexCoordinates, Map settings, @Nullable Document mapping) { Set aliases = (boundClass != null) ? getAliasesFor(boundClass) : new HashSet<>(); CreateIndexSettings indexSettings = CreateIndexSettings.builder(indexCoordinates) @@ -270,7 +270,7 @@ public class ReactiveIndicesTemplate return getAliases(null, indexNames); } - private Mono>> getAliases(@Nullable String[] aliasNames, @Nullable String[] indexNames) { + private Mono>> getAliases(String@Nullable [] aliasNames, String@Nullable [] indexNames) { GetAliasRequest getAliasRequest = requestConverter.indicesGetAliasRequest(aliasNames, indexNames); Mono getAliasResponse = Mono.from(execute(client -> client.getAlias(getAliasRequest))); diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/ResponseConverter.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/ResponseConverter.java index d4e1c0d81..fba85f149 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/ResponseConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/ResponseConverter.java @@ -66,6 +66,7 @@ import org.springframework.data.elasticsearch.core.reindex.ReindexResponse; import org.springframework.data.elasticsearch.core.script.Script; import org.springframework.data.elasticsearch.core.sql.SqlResponse; import org.springframework.data.elasticsearch.support.DefaultStringObjectMap; +import org.springframework.lang.Contract; import org.springframework.util.Assert; /** @@ -339,7 +340,7 @@ class ResponseConverter { List composedOf) { var mapping = typeMapping(indexTemplateSummary.mappings()); - Function indexSettingsToSettings = indexSettings -> { + Function<@Nullable IndexSettings, @Nullable Settings> indexSettingsToSettings = indexSettings -> { if (indexSettings == null) { return null; @@ -497,7 +498,7 @@ class ResponseConverter { builder.withDeleted(response.deleted()); } - if(response.updated() != null) { + if (response.updated() != null) { builder.withUpdated(response.updated()); } @@ -574,17 +575,20 @@ class ResponseConverter { } } + @Contract("null -> null; !null -> !null") @Nullable static ElasticsearchErrorCause toErrorCause(@Nullable ErrorCause errorCause) { if (errorCause != null) { - return new ElasticsearchErrorCause( // - errorCause.type(), // - errorCause.reason(), // - errorCause.stackTrace(), // - toErrorCause(errorCause.causedBy()), // - errorCause.rootCause().stream().map(ResponseConverter::toErrorCause).collect(Collectors.toList()), // - errorCause.suppressed().stream().map(ResponseConverter::toErrorCause).collect(Collectors.toList())); + return new ElasticsearchErrorCause( + errorCause.type(), + errorCause.reason(), + errorCause.stackTrace(), + toErrorCause(errorCause.causedBy()), + (List) (errorCause.rootCause().stream() + .map(ResponseConverter::toErrorCause).collect(Collectors.toList())), + (List) (errorCause.suppressed().stream().map(ResponseConverter::toErrorCause) + .collect(Collectors.toList()))); } else { return null; } diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/TypeUtils.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/TypeUtils.java index a724158ee..b3b56a2de 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/TypeUtils.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/TypeUtils.java @@ -36,6 +36,7 @@ import java.util.EnumSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import org.jspecify.annotations.Nullable; @@ -144,6 +145,12 @@ final class TypeUtils { } } + static Object toObjectNotNull(FieldValue fieldValue) { + + Objects.requireNonNull(fieldValue); + return toObject(fieldValue); + } + @Nullable static Object toObject(@Nullable FieldValue fieldValue) { @@ -485,7 +492,7 @@ final class TypeUtils { } @Nullable - static IndexSettings indexSettings(@Nullable Map settings) { + static IndexSettings indexSettings(@Nullable Map settings) { return settings != null ? IndexSettings.of(b -> b.withJson(new StringReader(Document.from(settings).toJson()))) : null; } diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/aot/package-info.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/aot/package-info.java index 2718c30fb..48f8b568a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/aot/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/aot/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.client.elc.aot; diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/rest5_client/Rest5Clients.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/rest5_client/Rest5Clients.java index 22d60a9cc..f0b17fb4a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/rest5_client/Rest5Clients.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/rest5_client/Rest5Clients.java @@ -28,7 +28,6 @@ import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.message.BasicHeader; import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy; import org.apache.hc.core5.util.Timeout; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.springframework.data.elasticsearch.client.ClientConfiguration; import org.springframework.data.elasticsearch.support.HttpHeaders; @@ -181,7 +180,7 @@ public final class Rest5Clients { return builder; } - private static HttpHost @NonNull [] getHttpHosts(ClientConfiguration clientConfiguration) { + private static HttpHost[] getHttpHosts(ClientConfiguration clientConfiguration) { List hosts = clientConfiguration.getEndpoints(); boolean useSsl = clientConfiguration.useSsl(); return hosts.stream() diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/rest_client/RestClients.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/rest_client/RestClients.java index 5c51f8c31..d94859eb4 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/rest_client/RestClients.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/rest_client/RestClients.java @@ -21,10 +21,8 @@ import org.apache.http.protocol.HttpContext; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.springframework.data.elasticsearch.client.ClientConfiguration; -import org.springframework.data.elasticsearch.client.elc.ElasticsearchClients; import org.springframework.data.elasticsearch.support.HttpHeaders; import org.springframework.util.Assert; @@ -107,7 +105,7 @@ public final class RestClients { return builder; } - private static HttpHost @NonNull [] getHttpHosts(ClientConfiguration clientConfiguration) { + private static HttpHost[] getHttpHosts(ClientConfiguration clientConfiguration) { List hosts = clientConfiguration.getEndpoints(); boolean useSsl = clientConfiguration.useSsl(); return hosts.stream() @@ -130,10 +128,10 @@ public final class RestClients { record CustomHeaderInjector(Supplier headersSupplier) implements HttpRequestInterceptor { @Override - public void process(HttpRequest request, HttpContext context) { + public void process(@Nullable HttpRequest request, @Nullable HttpContext context) { HttpHeaders httpHeaders = headersSupplier.get(); - if (httpHeaders != null && !httpHeaders.isEmpty()) { + if (!httpHeaders.isEmpty() && request != null) { Arrays.stream(toHeaderArray(httpHeaders)).forEach(request::addHeader); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/client/package-info.java b/src/main/java/org/springframework/data/elasticsearch/client/package-info.java index 1aa3d179a..ca07916ad 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.client; diff --git a/src/main/java/org/springframework/data/elasticsearch/client/util/package-info.java b/src/main/java/org/springframework/data/elasticsearch/client/util/package-info.java index 3e0be8092..b2bf31c86 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/util/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/util/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.client.util; diff --git a/src/main/java/org/springframework/data/elasticsearch/config/ElasticsearchConfigurationSupport.java b/src/main/java/org/springframework/data/elasticsearch/config/ElasticsearchConfigurationSupport.java index 864081814..8af56c4e2 100644 --- a/src/main/java/org/springframework/data/elasticsearch/config/ElasticsearchConfigurationSupport.java +++ b/src/main/java/org/springframework/data/elasticsearch/config/ElasticsearchConfigurationSupport.java @@ -18,6 +18,7 @@ package org.springframework.data.elasticsearch.config; import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.jspecify.annotations.Nullable; @@ -98,7 +99,7 @@ public class ElasticsearchConfigurationSupport { protected Collection getMappingBasePackages() { Package mappingBasePackage = getClass().getPackage(); - return Collections.singleton(mappingBasePackage == null ? null : mappingBasePackage.getName()); + return mappingBasePackage == null ? Collections.emptyList() : List.of(mappingBasePackage.getName()); } /** diff --git a/src/main/java/org/springframework/data/elasticsearch/config/package-info.java b/src/main/java/org/springframework/data/elasticsearch/config/package-info.java index 351c2495d..13583609a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/config/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/config/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.config; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java index 13962f7c2..6693a944c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java @@ -59,6 +59,7 @@ import org.springframework.data.elasticsearch.support.VersionInfo; import org.springframework.data.mapping.callback.EntityCallbacks; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.util.Streamable; +import org.springframework.lang.Contract; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -260,7 +261,7 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper List indexedObjectInformationList = bulkIndex(indexQueries, index); Iterator iterator = indexedObjectInformationList.iterator(); - // noinspection unchecked + // noinspection unchecked,DataFlowIssue return indexQueries.stream() // .map(IndexQuery::getObject) // .map(entity -> (T) entityOperations.updateIndexedObject( @@ -593,7 +594,7 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper } protected SearchDocumentResponse.EntityCreator getEntityCreator(ReadDocumentCallback documentCallback) { - return searchDocument -> CompletableFuture.completedFuture(documentCallback.doWith(searchDocument)); + return searchDocument -> CompletableFuture. completedFuture(documentCallback.doWith(searchDocument)); } /** @@ -752,6 +753,7 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper // region Document callbacks protected interface DocumentCallback { + @Contract("null -> null") @Nullable T doWith(@Nullable Document document); } @@ -815,6 +817,7 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper @Override public SearchHits doWith(SearchDocumentResponse response) { + // noinspection NullableProblems,DataFlowIssue List entities = response.getSearchDocuments().stream().map(delegate::doWith).collect(Collectors.toList()); return SearchHitMapping.mappingFor(type, elasticsearchConverter).mapHits(response, entities); } @@ -835,6 +838,7 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper @Override public SearchScrollHits doWith(SearchDocumentResponse response) { + // noinspection DataFlowIssue,NullableProblems List entities = response.getSearchDocuments().stream().map(delegate::doWith).collect(Collectors.toList()); return SearchHitMapping.mappingFor(type, elasticsearchConverter).mapScrollHits(response, entities); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/AbstractReactiveElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/AbstractReactiveElasticsearchTemplate.java index 3a502acdc..75e3c0023 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/AbstractReactiveElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/AbstractReactiveElasticsearchTemplate.java @@ -766,7 +766,8 @@ abstract public class AbstractReactiveElasticsearchTemplate /** * Value class to capture client independent information from a response to an index request. */ - public record IndexResponseMetaData(String id, String index, long seqNo, long primaryTerm, long version) { + public record IndexResponseMetaData(String id, String index, @Nullable Long seqNo, @Nullable Long primaryTerm, + long version) { } // endregion diff --git a/src/main/java/org/springframework/data/elasticsearch/core/EntityOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/EntityOperations.java index 8be208ed2..9403e3e18 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/EntityOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/EntityOperations.java @@ -17,7 +17,6 @@ package org.springframework.data.elasticsearch.core; import java.util.Map; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.springframework.core.convert.ConversionService; import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter; @@ -370,7 +369,7 @@ public class EntityOperations { * @see org.springframework.data.elasticsearch.core.EntityOperations.AdaptableEntity#initializeVersionProperty() */ @Override - public @NonNull T initializeVersionProperty() { + public T initializeVersionProperty() { return map; } @@ -399,7 +398,7 @@ public class EntityOperations { * @see org.springframework.data.elasticsearch.core.EntityOperations.AdaptableEntity#incrementVersion() */ @Override - public @NonNull T incrementVersion() { + public T incrementVersion() { return map; } @@ -408,7 +407,7 @@ public class EntityOperations { * @see org.springframework.data.elasticsearch.core.EntityOperations.Entity#getBean() */ @Override - public @NonNull T getBean() { + public T getBean() { return map; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/IndexOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/IndexOperations.java index 3eaedbec5..e038faa6b 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/IndexOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/IndexOperations.java @@ -52,7 +52,7 @@ public interface IndexOperations { * @param settings the index settings * @return {@literal true} if the index was created */ - boolean create(Map settings); + boolean create(Map settings); /** * Create an index for given settings and mapping. @@ -62,7 +62,7 @@ public interface IndexOperations { * @return {@literal true} if the index was created * @since 4.2 */ - boolean create(Map settings, Document mapping); + boolean create(Map settings, Document mapping); /** * Create an index with the settings and mapping defined for the entity this IndexOperations is bound to. @@ -142,7 +142,7 @@ public interface IndexOperations { * * @return the mapping */ - Map getMapping(); + Map getMapping(); // endregion diff --git a/src/main/java/org/springframework/data/elasticsearch/core/IndexOperationsAdapter.java b/src/main/java/org/springframework/data/elasticsearch/core/IndexOperationsAdapter.java index 6cca679df..1e9f87ac3 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/IndexOperationsAdapter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/IndexOperationsAdapter.java @@ -46,12 +46,12 @@ public interface IndexOperationsAdapter extends IndexOperations { } @Override - public boolean create(Map settings) { + public boolean create(Map settings) { return Boolean.TRUE.equals(reactiveIndexOperations.create(settings).block()); } @Override - public boolean create(Map settings, Document mapping) { + public boolean create(Map settings, Document mapping) { return Boolean.TRUE.equals(reactiveIndexOperations.create(settings, mapping).block()); } @@ -92,7 +92,7 @@ public interface IndexOperationsAdapter extends IndexOperations { } @Override - public Map getMapping() { + public Map getMapping() { return Objects.requireNonNull(reactiveIndexOperations.getMapping().block()); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/MultiGetItem.java b/src/main/java/org/springframework/data/elasticsearch/core/MultiGetItem.java index 03fbe17b5..3175184e1 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/MultiGetItem.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/MultiGetItem.java @@ -36,7 +36,7 @@ public class MultiGetItem { } public static MultiGetItem of(@Nullable T item, @Nullable Failure failure) { - return new MultiGetItem<>(item, failure); + return new MultiGetItem(item, failure); } public boolean hasItem() { diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveIndexOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveIndexOperations.java index 85be2eb4d..d8d6ff18d 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveIndexOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveIndexOperations.java @@ -21,6 +21,7 @@ import reactor.core.publisher.Mono; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; import org.springframework.data.elasticsearch.core.document.Document; import org.springframework.data.elasticsearch.core.index.*; import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; @@ -50,7 +51,7 @@ public interface ReactiveIndexOperations { * @return a {@link Mono} signalling successful operation completion or an {@link Mono#error(Throwable) error} if eg. * the index already exist. */ - Mono create(Map settings); + Mono create(Map settings); /** * Create an index for given settings and mapping. @@ -61,7 +62,7 @@ public interface ReactiveIndexOperations { * the index already exist. * @since 4.2 */ - Mono create(Map settings, Document mapping); + Mono create(Map settings, Document mapping); /** * Create an index with the settings and mapping defined for the entity this IndexOperations is bound to. diff --git a/src/main/java/org/springframework/data/elasticsearch/core/SearchHit.java b/src/main/java/org/springframework/data/elasticsearch/core/SearchHit.java index d4b42d8e7..30baae108 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/SearchHit.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/SearchHit.java @@ -51,7 +51,7 @@ public class SearchHit { private final Map matchedQueries = new LinkedHashMap<>(); public SearchHit(@Nullable String index, @Nullable String id, @Nullable String routing, float score, - @Nullable Object[] sortValues, @Nullable Map> highlightFields, + Object @Nullable [] sortValues, @Nullable Map> highlightFields, @Nullable Map> innerHits, @Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation, @Nullable Map matchedQueries, T content) { this.index = index; @@ -193,7 +193,6 @@ public class SearchHit { /** * @return the matched queries for this SearchHit. */ - @Nullable public Map getMatchedQueries() { return matchedQueries; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/SearchHitSupport.java b/src/main/java/org/springframework/data/elasticsearch/core/SearchHitSupport.java index 2904a6082..0a5e00fa7 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/SearchHitSupport.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/SearchHitSupport.java @@ -22,11 +22,11 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.jspecify.annotations.Nullable; - import org.springframework.data.core.ReactiveWrappers; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.util.CloseableIterator; +import org.springframework.lang.Contract; /** * Utility class with helper methods for working with {@link SearchHit}. @@ -47,6 +47,7 @@ public final class SearchHitSupport { * @return a corresponding object where the SearchHits are replaced by their content if possible, otherwise the * original object */ + @Contract("null -> null; !null -> !null") @Nullable public static Object unwrapSearchHits(@Nullable Object result) { diff --git a/src/main/java/org/springframework/data/elasticsearch/core/SearchHitsImpl.java b/src/main/java/org/springframework/data/elasticsearch/core/SearchHitsImpl.java index 93a989d15..6a50cf004 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/SearchHitsImpl.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/SearchHitsImpl.java @@ -133,7 +133,7 @@ public class SearchHitsImpl implements SearchScrollHits { } @Override - public SearchShardStatistics getSearchShardStatistics() { + public @Nullable SearchShardStatistics getSearchShardStatistics() { return searchShardStatistics; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/cluster/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/cluster/package-info.java index 8532409aa..cc821667c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/cluster/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/cluster/package-info.java @@ -1,5 +1,18 @@ -/** - * Interfaces and classes related to Elasticsearch cluster information and management. +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.cluster; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/ElasticsearchTypeMapper.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/ElasticsearchTypeMapper.java index a38a46bba..3486438d6 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/ElasticsearchTypeMapper.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/ElasticsearchTypeMapper.java @@ -29,7 +29,7 @@ import org.springframework.data.mapping.context.MappingContext; * @author Christoph Strobl * @since 3.2 */ -public interface ElasticsearchTypeMapper extends TypeMapper> { +public interface ElasticsearchTypeMapper extends TypeMapper> { String DEFAULT_TYPE_KEY = "_class"; @@ -47,7 +47,7 @@ public interface ElasticsearchTypeMapper extends TypeMapper> @Nullable String getTypeKey(); - default boolean containsTypeInformation(Map source) { + default boolean containsTypeInformation(Map source) { return readType(source) != null; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/GeoConverters.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/GeoConverters.java index 651819e29..03be59f99 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/GeoConverters.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/GeoConverters.java @@ -20,9 +20,9 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.ReadingConverter; import org.springframework.data.convert.WritingConverter; @@ -167,7 +167,7 @@ public class GeoConverters { INSTANCE; @Override - public GeoJson> convert(Map source) { + public GeoJson> convert(Map source) { String type = GeoConverters.getGeoJsonType(source); @@ -206,7 +206,7 @@ public class GeoConverters { INSTANCE; @Override - public GeoJsonPoint convert(Map source) { + public GeoJsonPoint convert(Map source) { String type = GeoConverters.getGeoJsonType(source); Assert.isTrue(type.equalsIgnoreCase(GeoJsonPoint.TYPE), "does not contain a type 'Point'"); @@ -244,7 +244,7 @@ public class GeoConverters { INSTANCE; @Override - public GeoJsonMultiPoint convert(Map source) { + public GeoJsonMultiPoint convert(Map source) { String type = GeoConverters.getGeoJsonType(source); Assert.isTrue(type.equalsIgnoreCase(GeoJsonMultiPoint.TYPE), "does not contain a type 'MultiPoint'"); @@ -279,7 +279,7 @@ public class GeoConverters { INSTANCE; @Override - public GeoJsonLineString convert(Map source) { + public GeoJsonLineString convert(Map source) { String type = GeoConverters.getGeoJsonType(source); Assert.isTrue(type.equalsIgnoreCase(GeoJsonLineString.TYPE), "does not contain a type 'LineString'"); @@ -311,7 +311,7 @@ public class GeoConverters { INSTANCE; @Override - public GeoJsonMultiLineString convert(Map source) { + public GeoJsonMultiLineString convert(Map source) { String type = GeoConverters.getGeoJsonType(source); Assert.isTrue(type.equalsIgnoreCase(GeoJsonMultiLineString.TYPE), "does not contain a type 'MultiLineString'"); @@ -339,7 +339,7 @@ public class GeoConverters { INSTANCE; @Override - public GeoJsonPolygon convert(Map source) { + public GeoJsonPolygon convert(Map source) { String type = GeoConverters.getGeoJsonType(source); Assert.isTrue(type.equalsIgnoreCase(GeoJsonPolygon.TYPE), "does not contain a type 'Polygon'"); @@ -368,7 +368,6 @@ public class GeoConverters { List coordinates = source.getCoordinates().stream() // .map(GeoJsonPolygonToMapConverter.INSTANCE::convert) // - .filter(Objects::nonNull) // .map(it -> it.get("coordinates")) // .collect(Collectors.toList()); // map.put("coordinates", coordinates); @@ -383,7 +382,7 @@ public class GeoConverters { INSTANCE; @Override - public GeoJsonMultiPolygon convert(Map source) { + public GeoJsonMultiPolygon convert(Map source) { String type = GeoConverters.getGeoJsonType(source); Assert.isTrue(type.equalsIgnoreCase(GeoJsonMultiPolygon.TYPE), "does not contain a type 'MultiPolygon'"); @@ -430,7 +429,7 @@ public class GeoConverters { INSTANCE; @Override - public GeoJsonGeometryCollection convert(Map source) { + public GeoJsonGeometryCollection convert(Map source) { String type = GeoConverters.getGeoJsonType(source); Assert.isTrue(type.equalsIgnoreCase(GeoJsonGeometryCollection.TYPE), @@ -448,7 +447,7 @@ public class GeoConverters { // endregion // region helper functions - private static String getGeoJsonType(Map source) { + private static String getGeoJsonType(Map source) { Object type = source.get("type"); Assert.notNull(type, "Document to convert does not contain a type"); @@ -485,7 +484,7 @@ public class GeoConverters { return map; } - private static List geoJsonLineStringsFromMap(Map source) { + private static List geoJsonLineStringsFromMap(Map source) { Object coordinates = source.get("coordinates"); Assert.notNull(coordinates, "Document to convert does not contain coordinates"); Assert.isTrue(coordinates instanceof List, "coordinates must be a List"); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java index 8de68ecfa..e40e2e35a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java @@ -24,7 +24,6 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jspecify.annotations.Nullable; - import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; @@ -63,16 +62,7 @@ import org.springframework.data.mapping.Parameter; import org.springframework.data.mapping.PersistentPropertyAccessor; import org.springframework.data.mapping.SimplePropertyHandler; import org.springframework.data.mapping.context.MappingContext; -import org.springframework.data.mapping.model.CachingValueExpressionEvaluatorFactory; -import org.springframework.data.mapping.model.ConvertingPropertyAccessor; -import org.springframework.data.mapping.model.EntityInstantiator; -import org.springframework.data.mapping.model.EntityInstantiators; -import org.springframework.data.mapping.model.ParameterValueProvider; -import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider; -import org.springframework.data.mapping.model.PropertyValueProvider; -import org.springframework.data.mapping.model.SpELContext; -import org.springframework.data.mapping.model.ValueExpressionEvaluator; -import org.springframework.data.mapping.model.ValueExpressionParameterValueProvider; +import org.springframework.data.mapping.model.*; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.format.datetime.DateFormatterRegistrar; import org.springframework.util.Assert; @@ -267,7 +257,7 @@ public class MappingElasticsearchConverter @Nullable @SuppressWarnings("unchecked") - private R read(TypeInformation typeInformation, Map source) { + private R read(TypeInformation typeInformation, Map source) { Assert.notNull(source, "Source must not be null!"); @@ -301,7 +291,7 @@ public class MappingElasticsearchConverter } @SuppressWarnings("unchecked") - private R readMap(TypeInformation type, Map source) { + private R readMap(TypeInformation type, Map source) { Assert.notNull(source, "Document must not be null!"); @@ -313,9 +303,10 @@ public class MappingElasticsearchConverter Class rawKeyType = keyType != null ? keyType.getType() : null; Class rawValueType = valueType != null ? valueType.getType() : null; - Map map = CollectionFactory.createMap(mapType, rawKeyType, source.keySet().size()); + Map map = (Map) CollectionFactory.createMap(mapType, + rawKeyType, source.keySet().size()); - for (Entry entry : source.entrySet()) { + for (Entry entry : source.entrySet()) { if (typeMapper.isTypeKey(entry.getKey())) { continue; @@ -325,6 +316,7 @@ public class MappingElasticsearchConverter if (rawKeyType != null && !rawKeyType.isAssignableFrom(key.getClass())) { key = conversionService.convert(key, rawKeyType); + Assert.notNull(key, "converted key must not be null"); } Object value = entry.getValue(); @@ -343,7 +335,7 @@ public class MappingElasticsearchConverter return (R) map; } - private R readEntity(ElasticsearchPersistentEntity entity, Map source) { + private R readEntity(ElasticsearchPersistentEntity entity, Map source) { ElasticsearchPersistentEntity targetEntity = computeClosestEntity(entity, source); ValueExpressionEvaluator evaluator = expressionEvaluatorFactory.create(source); @@ -582,7 +574,7 @@ public class MappingElasticsearchConverter : TypeInformation.OBJECT; Class rawComponentType = componentType.getType(); - Collection items = targetType.getType().isArray() // + Collection<@Nullable Object> items = targetType.getType().isArray() // ? new ArrayList<>(source.size()) // : CollectionFactory.createCollection(collectionType, rawComponentType, source.size()); @@ -672,7 +664,7 @@ public class MappingElasticsearchConverter */ private void populateScriptedFields(ElasticsearchPersistentEntity entity, T result, SearchDocument searchDocument) { - Map> fields = searchDocument.getFields(); + Map> fields = searchDocument.getFields(); entity.doWithProperties((SimplePropertyHandler) property -> { if (property.isAnnotationPresent(ScriptedField.class)) { ScriptedField scriptedField = property.findAnnotation(ScriptedField.class); @@ -695,7 +687,7 @@ public class MappingElasticsearchConverter * Compute the type to use by checking the given entity against the store type; */ private ElasticsearchPersistentEntity computeClosestEntity(ElasticsearchPersistentEntity entity, - Map source) { + Map source) { TypeInformation typeToUse = typeMapper.readType(source); @@ -770,7 +762,7 @@ public class MappingElasticsearchConverter INSTANCE; @Override - public T getParameterValue(Parameter parameter) { + public @Nullable T getParameterValue(Parameter parameter) { return null; } } @@ -822,7 +814,7 @@ public class MappingElasticsearchConverter * @param typeInformation type information for the source */ @SuppressWarnings("unchecked") - private void writeInternal(@Nullable Object source, Map sink, + private void writeInternal(@Nullable Object source, Map sink, @Nullable TypeInformation typeInformation) { if (null == source) { @@ -833,7 +825,7 @@ public class MappingElasticsearchConverter Optional> customTarget = conversions.getCustomWriteTarget(entityType, Map.class); if (customTarget.isPresent()) { - Map result = conversionService.convert(source, Map.class); + Map result = conversionService.convert(source, Map.class); if (result != null) { sink.putAll(result); @@ -863,7 +855,7 @@ public class MappingElasticsearchConverter * @param sink the destination * @param entity entity for the source */ - private void writeInternal(@Nullable Object source, Map sink, + private void writeInternal(@Nullable Object source, Map sink, @Nullable ElasticsearchPersistentEntity entity) { if (source == null) { @@ -905,7 +897,7 @@ public class MappingElasticsearchConverter * @param sink must not be {@literal null}. * @param propertyType must not be {@literal null}. */ - private Map writeMapInternal(Map source, Map sink, + private Map writeMapInternal(Map source, Map sink, TypeInformation propertyType) { for (Map.Entry entry : source.entrySet()) { @@ -922,7 +914,7 @@ public class MappingElasticsearchConverter sink.put(simpleKey, writeCollectionInternal(asCollection(value), propertyType.getMapValueType(), new ArrayList<>())); } else { - Map document = Document.create(); + Map document = Document.create(); TypeInformation valueTypeInfo = propertyType.isMap() ? propertyType.getMapValueType() : TypeInformation.OBJECT; writeInternal(value, document, valueTypeInfo); @@ -966,7 +958,7 @@ public class MappingElasticsearchConverter } else if (element instanceof Collection || elementType.isArray()) { collection.add(writeCollectionInternal(asCollection(element), componentType, new ArrayList<>())); } else { - Map document = Document.create(); + Map document = Document.create(); writeInternal(element, document, componentType); collection.add(document); } @@ -1080,7 +1072,7 @@ public class MappingElasticsearchConverter : mappingContext.getRequiredPersistentEntity(type); Object existingValue = sink.get(property); - Map document = existingValue instanceof Map ? (Map) existingValue + Map document = existingValue instanceof Map ? (Map) existingValue : Document.create(); addCustomTypeKeyIfNecessary(value, document, TypeInformation.of(property.getRawType())); @@ -1097,7 +1089,7 @@ public class MappingElasticsearchConverter * @param sink must not be {@literal null}. * @param type type to compare to */ - private void addCustomTypeKeyIfNecessary(Object source, Map sink, + private void addCustomTypeKeyIfNecessary(Object source, Map sink, @Nullable TypeInformation type) { if (!writeTypeHints) { @@ -1218,7 +1210,7 @@ public class MappingElasticsearchConverter Assert.notNull(map, "Given map must not be null!"); Assert.notNull(property, "PersistentProperty must not be null!"); - return writeMapInternal(map, new LinkedHashMap<>(map.size()), property.getTypeInformation()); + return writeMapInternal(map, new LinkedHashMap(map.size()), property.getTypeInformation()); } /** @@ -1492,9 +1484,9 @@ public class MappingElasticsearchConverter @SuppressWarnings("ClassCanBeRecord") static class MapValueAccessor { - final Map target; + final Map target; - MapValueAccessor(Map target) { + MapValueAccessor(Map target) { this.target = target; } @@ -1528,7 +1520,7 @@ public class MappingElasticsearchConverter } Iterator parts = Arrays.asList(fieldName.split("\\.")).iterator(); - Map source = target; + Map source = target; Object result = null; while (parts.hasNext()) { @@ -1559,11 +1551,11 @@ public class MappingElasticsearchConverter target.put(property.getFieldName(), value); } - private Map getAsMap(Object result) { + private Map getAsMap(Object result) { if (result instanceof Map) { // noinspection unchecked - return (Map) result; + return (Map) result; } throw new IllegalArgumentException(String.format("%s is not a Map.", result)); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/package-info.java index 88db6c0aa..828d7bd33 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.convert; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/document/Explanation.java b/src/main/java/org/springframework/data/elasticsearch/core/document/Explanation.java index 1a5970be6..6fee7a01f 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/document/Explanation.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/document/Explanation.java @@ -62,7 +62,7 @@ public class Explanation { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -81,7 +81,7 @@ public class Explanation { @Override public int hashCode() { - int result = (match ? 1 : 0); + int result = (Boolean.TRUE.equals(match) ? 1 : 0); result = 31 * result + value.hashCode(); result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + details.hashCode(); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/document/MapDocument.java b/src/main/java/org/springframework/data/elasticsearch/core/document/MapDocument.java index eb20d1945..af18a3dae 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/document/MapDocument.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/document/MapDocument.java @@ -215,7 +215,7 @@ class MapDocument implements Document { * @see java.util.Map#containsKey(java.lang.Object) */ @Override - public boolean containsKey(Object key) { + public boolean containsKey(@Nullable Object key) { return documentAsMap.containsKey(key); } @@ -224,7 +224,7 @@ class MapDocument implements Document { * @see java.util.Map#containsValue(java.lang.Object) */ @Override - public boolean containsValue(Object value) { + public boolean containsValue(@Nullable Object value) { return documentAsMap.containsValue(value); } @@ -233,7 +233,7 @@ class MapDocument implements Document { * @see java.util.Map#get(java.lang.Object) */ @Override - public Object get(Object key) { + public Object get(@Nullable Object key) { return documentAsMap.get(key); } @@ -242,7 +242,7 @@ class MapDocument implements Document { * @see java.lang.Object#getOrDefault(java.lang.Object, java.lang.Object) */ @Override - public Object getOrDefault(Object key, Object defaultValue) { + public Object getOrDefault(@Nullable Object key, @Nullable Object defaultValue) { return documentAsMap.getOrDefault(key, defaultValue); } @@ -251,7 +251,7 @@ class MapDocument implements Document { * @see java.util.Map#put(java.lang.Object, java.lang.Object) */ @Override - public Object put(String key, Object value) { + public Object put(String key, @Nullable Object value) { return documentAsMap.put(key, value); } @@ -260,7 +260,7 @@ class MapDocument implements Document { * @see java.util.Map#remove(java.lang.Object) */ @Override - public Object remove(Object key) { + public Object remove(@Nullable Object key) { return documentAsMap.remove(key); } @@ -314,7 +314,7 @@ class MapDocument implements Document { * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { return documentAsMap.equals(o); } @@ -332,7 +332,8 @@ class MapDocument implements Document { * @see java.util.Map#forEach(java.util.function.BiConsumer) */ @Override - public void forEach(BiConsumer action) { + public void forEach( + @SuppressWarnings("NullableProblems") BiConsumer action) { documentAsMap.forEach(action); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocument.java b/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocument.java index 3507aa83b..c05872e38 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocument.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocument.java @@ -41,7 +41,7 @@ public interface SearchDocument extends Document { /** * @return the fields for the search result, not {@literal null} */ - Map> getFields(); + Map> getFields(); /** * The first value of the given field. @@ -50,7 +50,7 @@ public interface SearchDocument extends Document { */ @Nullable default V getFieldValue(final String name) { - List values = getFields().get(name); + List<@Nullable Object> values = getFields().get(name); if (values == null || values.isEmpty()) { return null; } @@ -64,7 +64,7 @@ public interface SearchDocument extends Document { */ @Nullable default List getFieldValues(final String name) { - List values = getFields().get(name); + List<@Nullable Object> values = getFields().get(name); if (values == null) { return null; } @@ -74,8 +74,7 @@ public interface SearchDocument extends Document { /** * @return the sort values for the search hit */ - @Nullable - default Object[] getSortValues() { + default Object @Nullable [] getSortValues() { return null; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocumentAdapter.java b/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocumentAdapter.java index 848e339f3..0831a2e30 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocumentAdapter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocumentAdapter.java @@ -35,7 +35,7 @@ public class SearchDocumentAdapter implements SearchDocument { private final float score; private final Object[] sortValues; - private final Map> fields = new HashMap<>(); + private final Map> fields = new HashMap<>(); private final Document delegate; private final Map> highlightFields = new HashMap<>(); private final Map innerHits = new HashMap<>(); @@ -44,9 +44,11 @@ public class SearchDocumentAdapter implements SearchDocument { @Nullable private final Map matchedQueries; @Nullable private final String routing; - public SearchDocumentAdapter(Document delegate, float score, Object[] sortValues, Map> fields, + public SearchDocumentAdapter(Document delegate, float score, Object[] sortValues, + Map> fields, Map> highlightFields, Map innerHits, - @Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation, @Nullable Map matchedQueries, + @Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation, + @Nullable Map matchedQueries, @Nullable String routing) { this.delegate = delegate; @@ -74,7 +76,7 @@ public class SearchDocumentAdapter implements SearchDocument { } @Override - public Map> getFields() { + public Map> getFields() { return fields; } @@ -186,17 +188,17 @@ public class SearchDocumentAdapter implements SearchDocument { } @Override - public boolean containsKey(Object key) { + public boolean containsKey(@Nullable Object key) { return delegate.containsKey(key); } @Override - public boolean containsValue(Object value) { + public boolean containsValue(@Nullable Object value) { return delegate.containsValue(value); } @Override - public Object get(Object key) { + public Object get(@Nullable Object key) { if (delegate.containsKey(key)) { return delegate.get(key); @@ -207,12 +209,12 @@ public class SearchDocumentAdapter implements SearchDocument { } @Override - public Object put(String key, Object value) { + public @Nullable Object put(String key, @Nullable Object value) { return delegate.put(key, value); } @Override - public Object remove(Object key) { + public Object remove(@Nullable Object key) { return delegate.remove(key); } @@ -232,12 +234,12 @@ public class SearchDocumentAdapter implements SearchDocument { } @Override - public Collection values() { + public Collection<@Nullable Object> values() { return delegate.values(); } @Override - public Set> entrySet() { + public Set> entrySet() { return delegate.entrySet(); } @@ -254,7 +256,7 @@ public class SearchDocumentAdapter implements SearchDocument { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; } @@ -270,17 +272,17 @@ public class SearchDocumentAdapter implements SearchDocument { } @Override - public void forEach(BiConsumer action) { + public void forEach(@Nullable BiConsumer action) { delegate.forEach(action); } @Override - public boolean remove(Object key, Object value) { + public boolean remove(@Nullable Object key, @Nullable Object value) { return delegate.remove(key, value); } @Override - public String getRouting() { + public @Nullable String getRouting() { return routing; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/document/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/document/package-info.java index 514f80ad1..e2d5dd9d5 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/document/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/document/package-info.java @@ -1,5 +1,18 @@ -/** - * Classes related to the Document structure of Elasticsearch documents and search responses. +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.document; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/event/AfterLoadCallback.java b/src/main/java/org/springframework/data/elasticsearch/core/event/AfterLoadCallback.java index 8a5eaf538..0c776ce2a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/event/AfterLoadCallback.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/event/AfterLoadCallback.java @@ -31,10 +31,11 @@ import org.springframework.data.mapping.callback.EntityCallback; public interface AfterLoadCallback extends EntityCallback { /** - * Entity callback method invoked after a domain object is materialized from a {@link Document}. Can return either the - * same or a modified instance of the {@link Document} object. + * Entity callback method invoked after a {@link Document} is read from Elasticsearch. Can return either the same or a + * modified instance of the {@link Document} object. * * @param document the document. + * @param type the type into which the document will be converted * @param indexCoordinates of the index the document was read from. * @return a possible modified or new {@link Document}. */ diff --git a/src/main/java/org/springframework/data/elasticsearch/core/event/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/event/package-info.java index f596552bf..0c762df1e 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/event/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/event/package-info.java @@ -1,5 +1,18 @@ -/** - * classes and interfaces related to Spring Data Elasticsearch events and callbacks. +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.event; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/geo/CustomGeoModule.java b/src/main/java/org/springframework/data/elasticsearch/core/geo/CustomGeoModule.java index 842e3d9c3..bc3316b60 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/geo/CustomGeoModule.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/geo/CustomGeoModule.java @@ -8,18 +8,27 @@ import tools.jackson.databind.SerializationContext; import tools.jackson.databind.ValueDeserializer; import tools.jackson.databind.ValueSerializer; +import org.jspecify.annotations.Nullable; import org.springframework.data.geo.Point; +import org.springframework.util.Assert; class PointSerializer extends ValueSerializer { @Override - public void serialize(Point value, JsonGenerator gen, SerializationContext serializers) throws JacksonException { + public void serialize(Point value, @Nullable JsonGenerator gen, @Nullable SerializationContext serializers) + throws JacksonException { + + Assert.notNull(gen, "gen must not be null"); + gen.writePOJO(GeoPoint.fromPoint(value)); } } class PointDeserializer extends ValueDeserializer { @Override - public Point deserialize(JsonParser p, DeserializationContext context) throws JacksonException { + public Point deserialize(@Nullable JsonParser p, @Nullable DeserializationContext context) throws JacksonException { + + Assert.notNull(p, "p must not be null"); + return GeoPoint.toPoint(p.readValueAs(GeoPoint.class)); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonGeometryCollection.java b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonGeometryCollection.java index 83b2d1111..336e86b5d 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonGeometryCollection.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonGeometryCollection.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; import org.springframework.util.Assert; /** @@ -68,7 +69,7 @@ public class GeoJsonGeometryCollection implements GeoJson>> } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonLineString.java b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonLineString.java index 24c8f80c1..06a2d63c9 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonLineString.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonLineString.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import org.springframework.data.geo.Point; import org.springframework.util.Assert; @@ -122,7 +123,7 @@ public class GeoJsonLineString implements GeoJson> { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonMultiLineString.java b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonMultiLineString.java index 2c74472d8..7b1d1d9a9 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonMultiLineString.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonMultiLineString.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import org.springframework.data.geo.Point; import org.springframework.util.Assert; @@ -81,7 +82,7 @@ public class GeoJsonMultiLineString implements GeoJson> { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonMultiPolygon.java b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonMultiPolygon.java index 6a16797cc..00c1a86f0 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonMultiPolygon.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonMultiPolygon.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; import org.springframework.util.Assert; /** @@ -62,7 +63,7 @@ public class GeoJsonMultiPolygon implements GeoJson> { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonPoint.java b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonPoint.java index fb0f3715b..1c89e3b4b 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonPoint.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonPoint.java @@ -18,6 +18,7 @@ package org.springframework.data.elasticsearch.core.geo; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; import org.springframework.data.geo.Point; /** @@ -89,7 +90,7 @@ public class GeoJsonPoint implements GeoJson> { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonPolygon.java b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonPolygon.java index 8b8145f73..aa32e1f91 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonPolygon.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonPolygon.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import org.jspecify.annotations.Nullable; import org.springframework.data.geo.Point; import org.springframework.util.Assert; @@ -207,7 +208,7 @@ public class GeoJsonPolygon implements GeoJson> { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoPoint.java b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoPoint.java index 1e29d74fb..798190a01 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoPoint.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/geo/GeoPoint.java @@ -17,6 +17,7 @@ package org.springframework.data.elasticsearch.core.geo; import java.util.Objects; +import org.jspecify.annotations.Nullable; import org.springframework.data.geo.Point; /** @@ -63,7 +64,7 @@ public class GeoPoint { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/geo/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/geo/package-info.java index b3dc72af0..45ca34e66 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/geo/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/geo/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.geo; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/AliasActionParameters.java b/src/main/java/org/springframework/data/elasticsearch/core/index/AliasActionParameters.java index 0e2414682..5256ad320 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/AliasActionParameters.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/AliasActionParameters.java @@ -27,7 +27,7 @@ import org.springframework.util.Assert; */ public class AliasActionParameters { private final String[] indices; - @Nullable private final String[] aliases; + private final String @Nullable [] aliases; @Nullable private final Query filterQuery; @Nullable private final Class filterQueryClass; @Nullable private final Boolean isHidden; @@ -36,7 +36,7 @@ public class AliasActionParameters { @Nullable private final String indexRouting; @Nullable private final String searchRouting; - private AliasActionParameters(String[] indices, @Nullable String[] aliases, @Nullable Boolean isHidden, + private AliasActionParameters(String[] indices, String @Nullable [] aliases, @Nullable Boolean isHidden, @Nullable Boolean isWriteIndex, @Nullable String routing, @Nullable String indexRouting, @Nullable String searchRouting, @Nullable Query filterQuery, @Nullable Class filterQueryClass) { this.indices = indices; @@ -66,7 +66,7 @@ public class AliasActionParameters { return indices; } - public String@Nullable[] getAliases() { + public String @Nullable [] getAliases() { return aliases; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/AliasActions.java b/src/main/java/org/springframework/data/elasticsearch/core/index/AliasActions.java index 61c2d0b74..b1985e53d 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/AliasActions.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/AliasActions.java @@ -38,7 +38,7 @@ public class AliasActions { * * @param actions {@link AliasAction} elements */ - public AliasActions(@Nullable AliasAction... actions) { + public AliasActions(AliasAction @Nullable... actions) { add(actions); } @@ -52,10 +52,9 @@ public class AliasActions { * @param actions elements to add * @return this object */ - public AliasActions add(@Nullable AliasAction... actions) { + public AliasActions add(AliasAction @Nullable... actions) { if (actions != null) { - // noinspection NullableProblems this.actions.addAll(Arrays.asList(actions)); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/ComponentTemplateRequestData.java b/src/main/java/org/springframework/data/elasticsearch/core/index/ComponentTemplateRequestData.java index 2b90f6984..93d880466 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/ComponentTemplateRequestData.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/ComponentTemplateRequestData.java @@ -40,7 +40,7 @@ public record ComponentTemplateRequestData(@Nullable Settings settings, @Nullabl @Nullable private AliasActions aliasActions; @Nullable private Boolean allowAutoCreate; - public Builder withSettings(Map settings) { + public Builder withSettings(Map settings) { this.settings = new Settings(settings); return this; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java b/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java index 0584f013d..2cbd82b57 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java @@ -36,7 +36,6 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.springframework.core.io.ClassPathResource; import org.springframework.data.annotation.Transient; @@ -280,7 +279,7 @@ public class MappingBuilder { writeTypeHintMapping(propertiesNode); if (entity != null) { - entity.doWithProperties((PropertyHandler<@NonNull ElasticsearchPersistentProperty>) property -> { + entity.doWithProperties((PropertyHandler) property -> { try { if (property.isAnnotationPresent(Transient.class) || isInIgnoreFields(property, parentFieldAnnotation)) { return; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/MappingParameters.java b/src/main/java/org/springframework/data/elasticsearch/core/index/MappingParameters.java index 63b4d7edf..162029425 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/MappingParameters.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/MappingParameters.java @@ -89,7 +89,7 @@ public class MappingParameters { private final String analyzer; private final boolean coerce; - @Nullable private final String[] copyTo; + private final String @Nullable [] copyTo; private final DateFormat[] dateFormats; private final String[] dateFormatPatterns; private final boolean docValues; @@ -429,7 +429,7 @@ public class MappingParameters { return coerce; } - protected String[] copyTo() { + protected String @Nullable [] copyTo() { return copyTo; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/MappingParametersCustomizer.java b/src/main/java/org/springframework/data/elasticsearch/core/index/MappingParametersCustomizer.java index 859120cf8..8e53b3208 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/MappingParametersCustomizer.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/MappingParametersCustomizer.java @@ -17,8 +17,6 @@ package org.springframework.data.elasticsearch.core.index; import java.lang.annotation.Annotation; -import org.jspecify.annotations.NonNull; - /** * Allows to customize {@link org.springframework.data.elasticsearch.core.index.MappingParameters} that are being * emitted for each supported annotation. Needed by dependent projects like Spring-Data-Opensearch. @@ -33,6 +31,6 @@ public interface MappingParametersCustomizer { * @param annotation supported annotation * @return customized @link org.springframework.data.elasticsearch.core.index.MappingParameters} */ - @NonNull - MappingParameters from(@NonNull Annotation annotation); + + MappingParameters from(Annotation annotation); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/PutTemplateRequest.java b/src/main/java/org/springframework/data/elasticsearch/core/index/PutTemplateRequest.java index 6d6ee8e04..aae3c8ade 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/PutTemplateRequest.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/PutTemplateRequest.java @@ -102,7 +102,7 @@ public class PutTemplateRequest { this.indexPatterns = indexPatterns; } - public TemplateRequestBuilder withSettings(Map settings) { + public TemplateRequestBuilder withSettings(Map settings) { this.settings = new Settings(settings); return this; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/Settings.java b/src/main/java/org/springframework/data/elasticsearch/core/index/Settings.java index a03cd0c1b..883b77aee 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/Settings.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/Settings.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; import org.springframework.data.elasticsearch.support.DefaultStringObjectMap; import org.springframework.util.Assert; @@ -34,7 +35,7 @@ public class Settings extends DefaultStringObjectMap { public Settings() {} - public Settings(Map map) { + public Settings(Map map) { super(map); } @@ -54,7 +55,7 @@ public class Settings extends DefaultStringObjectMap { } @Override - public Object get(Object key) { + public Object get(@Nullable Object key) { return containsKey(key) ? super.get(key) : path(key.toString()); } @@ -75,11 +76,11 @@ public class Settings extends DefaultStringObjectMap { * taken from https://stackoverflow.com/a/29698326/4393565 */ @SuppressWarnings("unchecked") - private static Map deepMerge(Map original, Map newMap) { + private static Map deepMerge(Map original, Map newMap) { for (Object key : newMap.keySet()) { if (newMap.get(key) instanceof Map && original.get(key) instanceof Map) { - Map originalChild = (Map) original.get(key); - Map newChild = (Map) newMap.get(key); + Map originalChild = (Map) original.get(key); + Map newChild = (Map) newMap.get(key); original.put(key.toString(), deepMerge(originalChild, newChild)); } else if (newMap.get(key) instanceof List && original.get(key) instanceof List) { List originalChild = (List) original.get(key); @@ -112,9 +113,9 @@ public class Settings extends DefaultStringObjectMap { * flattens a Map to a stream of Map.Entry objects where the keys are the dot separated concatenated * keys of sub map entries */ - static private Stream> doFlatten(Map.Entry entry) { + static private Stream> doFlatten(Map.Entry entry) { - if (entry.getValue()instanceof Map nested) { + if (entry.getValue() instanceof Map nested) { // noinspection unchecked return nested.entrySet().stream() // diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/TemplateData.java b/src/main/java/org/springframework/data/elasticsearch/core/index/TemplateData.java index 034ab648c..0b2036dd8 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/TemplateData.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/TemplateData.java @@ -91,7 +91,7 @@ public class TemplateData { return this; } - public TemplateDataBuilder withSettings(Map settings) { + public TemplateDataBuilder withSettings(Map settings) { this.settings = new Settings(settings); return this; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/index/package-info.java index 8317bc819..b76bec24a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/package-info.java @@ -1,5 +1,18 @@ -/** - * Classes related to Elasticsearch index management. +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.index; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/join/JoinField.java b/src/main/java/org/springframework/data/elasticsearch/core/join/JoinField.java index 918d3bd53..5ec375fd8 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/join/JoinField.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/join/JoinField.java @@ -64,7 +64,7 @@ public class JoinField { } @Override - public boolean equals(Object obj) { + public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/join/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/join/package-info.java new file mode 100644 index 000000000..040b3238c --- /dev/null +++ b/src/main/java/org/springframework/data/elasticsearch/core/join/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.join; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/Alias.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/Alias.java index dc93279c1..02f458d87 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/Alias.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/Alias.java @@ -115,7 +115,7 @@ public class Alias { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof Alias that)) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/CreateIndexSettings.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/CreateIndexSettings.java index 669104cfb..689cf2368 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/CreateIndexSettings.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/CreateIndexSettings.java @@ -33,7 +33,7 @@ public class CreateIndexSettings { private final IndexCoordinates indexCoordinates; private final Set aliases; - @Nullable private final Map settings; + @Nullable private final Map settings; @Nullable private final Document mapping; @@ -58,7 +58,7 @@ public class CreateIndexSettings { } @Nullable - public Map getSettings() { + public Map getSettings() { return settings; } @@ -71,7 +71,7 @@ public class CreateIndexSettings { private final IndexCoordinates indexCoordinates; private final Set aliases = new HashSet<>(); - @Nullable private Map settings; + @Nullable private Map settings; @Nullable private Document mapping; @@ -94,7 +94,7 @@ public class CreateIndexSettings { return this; } - public Builder withSettings(Map settings) { + public Builder withSettings(Map settings) { Assert.notNull(settings, "settings must not be null"); this.settings = settings; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/IndexCoordinates.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/IndexCoordinates.java index 0998712a9..0febc9d65 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/IndexCoordinates.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/IndexCoordinates.java @@ -17,6 +17,7 @@ package org.springframework.data.elasticsearch.core.mapping; import java.util.Arrays; +import org.jspecify.annotations.Nullable; import org.springframework.util.Assert; /** @@ -55,7 +56,7 @@ public class IndexCoordinates { * @since 4.2 */ @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java index 0ee0b9b72..8a05a69e1 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java @@ -23,9 +23,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; - import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.core.TypeInformation; @@ -263,6 +261,7 @@ public class SimpleElasticsearchPersistentEntity extends BasicPersistentEntit throw new MappingException("@IndexedIndexName annotation must be put on String property"); } + // noinspection VariableNotUsedInsideIf if (indexedIndexNameProperty != null) { throw new MappingException( "@IndexedIndexName annotation can only be put on one property in an entity"); @@ -301,7 +300,7 @@ public class SimpleElasticsearchPersistentEntity extends BasicPersistentEntit return fieldNamePropertyCache.computeIfAbsent(fieldName, key -> { AtomicReference<@Nullable ElasticsearchPersistentProperty> propertyRef = new AtomicReference<>(); - doWithProperties((PropertyHandler<@NonNull ElasticsearchPersistentProperty>) property -> { + doWithProperties((PropertyHandler) property -> { if (key.equals(property.getFieldName())) { propertyRef.set(property); } @@ -425,8 +424,7 @@ public class SimpleElasticsearchPersistentEntity extends BasicPersistentEntit try { Expression expression = routingExpressions.computeIfAbsent(routing, PARSER::parseExpression); - ExpressionDependencies expressionDependencies = expression != null ? ExpressionDependencies.discover(expression) - : ExpressionDependencies.none(); + ExpressionDependencies expressionDependencies = ExpressionDependencies.discover(expression); EvaluationContext context = getEvaluationContext(null, expressionDependencies); context.setVariable("entity", bean); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/package-info.java index d9e576366..606ccfe24 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.mapping; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/package-info.java index bc7d9b994..fb11eb508 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/BaseQuery.java b/src/main/java/org/springframework/data/elasticsearch/core/query/BaseQuery.java index 849365e63..2ab5bef43 100755 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/BaseQuery.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/BaseQuery.java @@ -602,6 +602,7 @@ public class BaseQuery implements Query { // searchForStream to work correctly (#3098) as there the page size defines what is // returned in a single request, and the max result determines the total number of // documents returned. + // noinspection DataFlowIssue maxResults is not null here, this is checked with isLimiting() requestSize = Math.min(pageable.getPageSize(), getMaxResults()); } } else if (pageable == UNSET_PAGE) { @@ -622,6 +623,7 @@ public class BaseQuery implements Query { // searchForStream to work correctly (#3098) as there the page size defines what is // returned in a single request, and the max result determines the total number of // documents returned. + // noinspection DataFlowIssue maxResults is not null here, this is checked with isLimiting() requestSize = Math.min(INDEX_MAX_RESULT_WINDOW, getMaxResults()); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/BaseQueryBuilder.java b/src/main/java/org/springframework/data/elasticsearch/core/query/BaseQueryBuilder.java index 8fd8117dd..851c59fce 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/BaseQueryBuilder.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/BaseQueryBuilder.java @@ -97,7 +97,6 @@ public abstract class BaseQueryBuilder getIds() { return ids; } @@ -182,7 +181,7 @@ public abstract class BaseQueryBuilder queryCriteriaEntries = new LinkedHashSet<>(); - private final Set filterCriteriaEntries = new LinkedHashSet<>(); - private final Set subCriteria = new LinkedHashSet<>(); + private final CriteriaChain criteriaChain = new CriteriaChain(); + private final Set queryCriteriaEntries = new LinkedHashSet<>(); + private final Set filterCriteriaEntries = new LinkedHashSet<>(); + private final Set subCriteria = new LinkedHashSet<>(); - // region criteria creation + // region criteria creation /** * @return factory method to create an and-Criteria that is not bound to a field @@ -89,8 +89,8 @@ public class Criteria { } public Criteria() { - recalculateHashCode(); - } + recalculateHashCode(); + } /** * Creates a new Criteria with provided field name @@ -113,7 +113,7 @@ public class Criteria { this.field = field; this.criteriaChain.add(this); - recalculateHashCode(); + recalculateHashCode(); } /** @@ -143,7 +143,7 @@ public class Criteria { this.field = field; this.criteriaChain.addAll(criteriaChain); this.criteriaChain.add(this); - recalculateHashCode(); + recalculateHashCode(); } /** @@ -197,7 +197,7 @@ public class Criteria { */ public Criteria not() { this.negating = true; - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -216,7 +216,7 @@ public class Criteria { Assert.isTrue(boost >= 0, "boost must not be negative"); this.boost = boost; - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -274,7 +274,7 @@ public class Criteria { Assert.notNull(criteria, "Cannot chain 'null' criteria."); this.criteriaChain.add(criteria); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -289,7 +289,7 @@ public class Criteria { Assert.notNull(criterias, "Cannot chain 'null' criterias."); this.criteriaChain.addAll(Arrays.asList(criterias)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -332,7 +332,7 @@ public class Criteria { orCriteria.subCriteria.addAll(criteria.subCriteria); orCriteria.boost = criteria.boost; orCriteria.negating = criteria.isNegating(); - orCriteria.recalculateHashCode(); + orCriteria.recalculateHashCode(); return orCriteria; } @@ -348,7 +348,7 @@ public class Criteria { Assert.notNull(criteria, "criteria must not be null"); subCriteria.add(criteria); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -363,7 +363,7 @@ public class Criteria { */ public Criteria is(Object o) { queryCriteriaEntries.add(new CriteriaEntry(OperationKey.EQUALS, o)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -375,7 +375,7 @@ public class Criteria { */ public Criteria exists() { queryCriteriaEntries.add(new CriteriaEntry(OperationKey.EXISTS)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -394,7 +394,7 @@ public class Criteria { } queryCriteriaEntries.add(new CriteriaEntry(OperationKey.BETWEEN, new Object[] { lowerBound, upperBound })); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -410,7 +410,7 @@ public class Criteria { assertNoBlankInWildcardQuery(s, false, true); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.STARTS_WITH, s)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -427,7 +427,7 @@ public class Criteria { assertNoBlankInWildcardQuery(s, true, true); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.CONTAINS, s)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -444,7 +444,7 @@ public class Criteria { assertNoBlankInWildcardQuery(s, true, false); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.ENDS_WITH, s)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -472,7 +472,7 @@ public class Criteria { Assert.notNull(values, "Collection of 'in' values must not be null"); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.IN, values)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -499,7 +499,7 @@ public class Criteria { Assert.notNull(values, "Collection of 'NotIn' values must not be null"); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.NOT_IN, values)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -512,7 +512,7 @@ public class Criteria { */ public Criteria expression(String s) { queryCriteriaEntries.add(new CriteriaEntry(OperationKey.EXPRESSION, s)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -524,7 +524,7 @@ public class Criteria { */ public Criteria fuzzy(String s) { queryCriteriaEntries.add(new CriteriaEntry(OperationKey.FUZZY, s)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -539,7 +539,7 @@ public class Criteria { Assert.notNull(upperBound, "upperBound must not be null"); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.LESS_EQUAL, upperBound)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -554,7 +554,7 @@ public class Criteria { Assert.notNull(upperBound, "upperBound must not be null"); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.LESS, upperBound)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -569,7 +569,7 @@ public class Criteria { Assert.notNull(lowerBound, "lowerBound must not be null"); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.GREATER_EQUAL, lowerBound)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -584,7 +584,7 @@ public class Criteria { Assert.notNull(lowerBound, "lowerBound must not be null"); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.GREATER, lowerBound)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -601,7 +601,7 @@ public class Criteria { Assert.notNull(value, "value must not be null"); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.MATCHES, value)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -618,7 +618,7 @@ public class Criteria { Assert.notNull(value, "value must not be null"); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.MATCHES_ALL, value)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -631,7 +631,7 @@ public class Criteria { public Criteria empty() { queryCriteriaEntries.add(new CriteriaEntry(OperationKey.EMPTY)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -644,7 +644,7 @@ public class Criteria { public Criteria notEmpty() { queryCriteriaEntries.add(new CriteriaEntry(OperationKey.NOT_EMPTY)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -660,7 +660,7 @@ public class Criteria { Assert.notNull(value, "value must not be null"); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.REGEXP, value)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -679,7 +679,7 @@ public class Criteria { Assert.notNull(boundingBox, "boundingBox value for boundedBy criteria must not be null"); filterCriteriaEntries.add(new CriteriaEntry(OperationKey.BBOX, new Object[] { boundingBox })); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -696,7 +696,7 @@ public class Criteria { filterCriteriaEntries .add(new CriteriaEntry(OperationKey.BBOX, new Object[] { boundingBox.getFirst(), boundingBox.getSecond() })); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -714,7 +714,7 @@ public class Criteria { filterCriteriaEntries .add(new CriteriaEntry(OperationKey.BBOX, new Object[] { topLeftGeohash, bottomRightGeohash })); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -731,7 +731,7 @@ public class Criteria { Assert.notNull(bottomRightPoint, "bottomRightPoint must not be null"); filterCriteriaEntries.add(new CriteriaEntry(OperationKey.BBOX, new Object[] { topLeftPoint, bottomRightPoint })); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -749,7 +749,7 @@ public class Criteria { filterCriteriaEntries.add(new CriteriaEntry(OperationKey.BBOX, new Object[] { GeoPoint.fromPoint(topLeftPoint), GeoPoint.fromPoint(bottomRightPoint) })); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -767,7 +767,7 @@ public class Criteria { Assert.notNull(location, "Distance value for near criteria must not be null"); filterCriteriaEntries.add(new CriteriaEntry(OperationKey.WITHIN, new Object[] { location, distance })); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -784,7 +784,7 @@ public class Criteria { Assert.notNull(location, "Distance value for near criteria must not be null"); filterCriteriaEntries.add(new CriteriaEntry(OperationKey.WITHIN, new Object[] { location, distance })); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -801,7 +801,7 @@ public class Criteria { Assert.isTrue(StringUtils.hasLength(geoLocation), "geoLocation value must not be null"); filterCriteriaEntries.add(new CriteriaEntry(OperationKey.WITHIN, new Object[] { geoLocation, distance })); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -816,7 +816,7 @@ public class Criteria { Assert.notNull(geoShape, "geoShape must not be null"); filterCriteriaEntries.add(new CriteriaEntry(OperationKey.GEO_INTERSECTS, geoShape)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -831,7 +831,7 @@ public class Criteria { Assert.notNull(geoShape, "geoShape must not be null"); filterCriteriaEntries.add(new CriteriaEntry(OperationKey.GEO_IS_DISJOINT, geoShape)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -845,7 +845,7 @@ public class Criteria { Assert.notNull(geoShape, "geoShape must not be null"); filterCriteriaEntries.add(new CriteriaEntry(OperationKey.GEO_WITHIN, geoShape)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -859,7 +859,7 @@ public class Criteria { Assert.notNull(geoShape, "geoShape must not be null"); filterCriteriaEntries.add(new CriteriaEntry(OperationKey.GEO_CONTAINS, geoShape)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -873,7 +873,7 @@ public class Criteria { Assert.notNull(query, "has_child query must not be null."); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.HAS_CHILD, query)); - recalculateHashCode(); + recalculateHashCode(); return this; } @@ -887,7 +887,7 @@ public class Criteria { Assert.notNull(query, "has_parent query must not be null."); queryCriteriaEntries.add(new CriteriaEntry(OperationKey.HAS_PARENT, query)); - recalculateHashCode(); + recalculateHashCode(); return this; } // endregion @@ -909,7 +909,7 @@ public class Criteria { // region equals/hashcode @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -937,19 +937,19 @@ public class Criteria { return hashCode; } - private void recalculateHashCode() { - int result = field != null ? field.hashCode() : 0; - result = 31 * result + (boost != +0.0f ? Float.floatToIntBits(boost) : 0); - result = 31 * result + (negating ? 1 : 0); - // the criteriaChain contains "this" object, so we need to filter it out - // to avoid a stackoverflow here, because the hashcode implementation - // uses the element's hashcodes - result = 31 * result + criteriaChain.filter(this).hashCode(); - result = 31 * result + queryCriteriaEntries.hashCode(); - result = 31 * result + filterCriteriaEntries.hashCode(); - result = 31 * result + subCriteria.hashCode(); - this.hashCode = result; - } + private void recalculateHashCode() { + int result = field != null ? field.hashCode() : 0; + result = 31 * result + (boost != +0.0f ? Float.floatToIntBits(boost) : 0); + result = 31 * result + (negating ? 1 : 0); + // the criteriaChain contains "this" object, so we need to filter it out + // to avoid a stackoverflow here, because the hashcode implementation + // uses the element's hashcodes + result = 31 * result + criteriaChain.filter(this).hashCode(); + result = 31 * result + queryCriteriaEntries.hashCode(); + result = 31 * result + filterCriteriaEntries.hashCode(); + result = 31 * result + subCriteria.hashCode(); + this.hashCode = result; + } // endregion @Override @@ -1141,7 +1141,7 @@ public class Criteria { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/DeleteQuery.java b/src/main/java/org/springframework/data/elasticsearch/core/query/DeleteQuery.java index 2b5dd92fb..c53862ce5 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/DeleteQuery.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/DeleteQuery.java @@ -354,7 +354,6 @@ public class DeleteQuery { return version; } - @Nullable public Query getQuery() { return query; } @@ -648,6 +647,7 @@ public class DeleteQuery { return this; } + @SuppressWarnings("VariableNotUsedInsideIf") public DeleteQuery build() { if (luceneQuery == null) { if (defaultField != null) { diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/FetchSourceFilter.java b/src/main/java/org/springframework/data/elasticsearch/core/query/FetchSourceFilter.java index da520414a..e4947098e 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/FetchSourceFilter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/FetchSourceFilter.java @@ -29,14 +29,14 @@ import org.springframework.util.Assert; public class FetchSourceFilter implements SourceFilter { @Nullable private final Boolean fetchSource; - @Nullable private final String[] includes; - @Nullable private final String[] excludes; + private final String @Nullable [] includes; + private final String @Nullable [] excludes; /** * @since 5.2 */ - public static SourceFilter of(@Nullable Boolean fetchSource, @Nullable final String[] includes, - @Nullable final String[] excludes) { + public static SourceFilter of(@Nullable Boolean fetchSource, final String @Nullable [] includes, + final String @Nullable [] excludes) { return new FetchSourceFilter(fetchSource, includes, excludes); } @@ -50,25 +50,25 @@ public class FetchSourceFilter implements SourceFilter { return builderFunction.apply(new FetchSourceFilterBuilder()).build(); } - public FetchSourceFilter(@Nullable Boolean fetchSource, @Nullable final String[] includes, - @Nullable final String[] excludes) { + public FetchSourceFilter(@Nullable Boolean fetchSource, final String @Nullable [] includes, + final String @Nullable [] excludes) { this.fetchSource = fetchSource; this.includes = includes; this.excludes = excludes; } @Override - public Boolean fetchSource() { + public @Nullable Boolean fetchSource() { return fetchSource; } @Override - public @Nullable String[] getIncludes() { + public String @Nullable [] getIncludes() { return includes; } @Override - public @Nullable String[] getExcludes() { + public String @Nullable [] getExcludes() { return excludes; } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/GeoDistanceOrder.java b/src/main/java/org/springframework/data/elasticsearch/core/query/GeoDistanceOrder.java index a09c0d8c4..9a21afad8 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/GeoDistanceOrder.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/GeoDistanceOrder.java @@ -43,7 +43,7 @@ public class GeoDistanceOrder extends Order { } private GeoDistanceOrder(String property, GeoPoint geoPoint, Sort.Direction direction, DistanceType distanceType, - Mode mode, String unit, Boolean ignoreUnmapped) { + @Nullable Mode mode, String unit, Boolean ignoreUnmapped) { super(direction, property, mode); this.geoPoint = geoPoint; this.distanceType = distanceType; @@ -59,7 +59,7 @@ public class GeoDistanceOrder extends Order { return distanceType; } - public Mode getMode() { + public @Nullable Mode getMode() { return mode; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/SimpleField.java b/src/main/java/org/springframework/data/elasticsearch/core/query/SimpleField.java index b01f1c8ea..bc30ab693 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/SimpleField.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/SimpleField.java @@ -83,7 +83,7 @@ public class SimpleField implements Field { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof SimpleField that)) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/query/package-info.java index b75075744..e2e5d6cc6 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.query; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/types/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/query/types/package-info.java index ecade8f8d..663a95f14 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/types/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/types/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.query.types; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/reindex/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/reindex/package-info.java index aceb0f5bb..7159a6ba2 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/reindex/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/reindex/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.reindex; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/routing/DefaultRoutingResolver.java b/src/main/java/org/springframework/data/elasticsearch/core/routing/DefaultRoutingResolver.java index 799b5b963..7500a22e8 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/routing/DefaultRoutingResolver.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/routing/DefaultRoutingResolver.java @@ -37,7 +37,7 @@ public class DefaultRoutingResolver implements RoutingResolver { } @Override - public String getRouting() { + public @Nullable String getRouting() { return null; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/routing/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/routing/package-info.java index f32bab092..736765a48 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/routing/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/routing/package-info.java @@ -1,5 +1,18 @@ -/** - * classes/interfaces for specification and implementation of Elasticsearch routing. +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.routing; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/script/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/script/package-info.java index b16531f37..b48c74cb0 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/script/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/script/package-info.java @@ -1,6 +1,18 @@ -/** - * Classes and interfaces to access to script API of Elasticsearch - * (https://www.elastic.co/guide/en/elasticsearch/reference/8.5/script-apis.html). +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.script; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/sql/SqlResponse.java b/src/main/java/org/springframework/data/elasticsearch/core/sql/SqlResponse.java index 958c45426..4d65a3500 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/sql/SqlResponse.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/sql/SqlResponse.java @@ -25,7 +25,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** @@ -110,7 +109,6 @@ public class SqlResponse { return new Builder(); } - @NonNull @Override public Iterator> iterator() { return row.entrySet().iterator(); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/sql/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/sql/package-info.java index b1af98166..ff7d46416 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/sql/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/sql/package-info.java @@ -1,5 +1,18 @@ -/** - * Classes and interfaces to access to SQL API of Elasticsearch. +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.sql; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/suggest/response/package-info.java b/src/main/java/org/springframework/data/elasticsearch/core/suggest/response/package-info.java index 7507d78a2..c0abdeca4 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/suggest/response/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/suggest/response/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.suggest.response; diff --git a/src/main/java/org/springframework/data/elasticsearch/package-info.java b/src/main/java/org/springframework/data/elasticsearch/package-info.java index 69b12af1f..98e6ed979 100644 --- a/src/main/java/org/springframework/data/elasticsearch/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java index d5032ade0..fe2c86383 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java @@ -44,7 +44,7 @@ public interface ElasticsearchRepository extends PagingAndSortingReposito * @param pageable , must not be {@literal null} * @return */ - Page searchSimilar(T entity, @Nullable String[] fields, Pageable pageable); + Page searchSimilar(T entity, String @Nullable [] fields, Pageable pageable); /** * @since 5.2 diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/aot/package-info.java b/src/main/java/org/springframework/data/elasticsearch/repository/aot/package-info.java index 270425b63..4353f4263 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/aot/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/aot/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repository.aot; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/cdi/package-info.java b/src/main/java/org/springframework/data/elasticsearch/repository/cdi/package-info.java index b307ca973..1da836f06 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/cdi/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/cdi/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repository.cdi; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/config/package-info.java b/src/main/java/org/springframework/data/elasticsearch/repository/config/package-info.java index 2278b3f14..cd26096d9 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/config/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/config/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repository.config; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/package-info.java b/src/main/java/org/springframework/data/elasticsearch/repository/package-info.java index 14c68bac4..aa25e1598 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/package-info.java @@ -1,5 +1,18 @@ -/** - * infrastructure to define the Elasticsearch mapping for an index. +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repository; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/AbstractElasticsearchRepositoryQuery.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/AbstractElasticsearchRepositoryQuery.java index 863c91667..4468af13c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/AbstractElasticsearchRepositoryQuery.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/AbstractElasticsearchRepositoryQuery.java @@ -15,6 +15,8 @@ */ package org.springframework.data.elasticsearch.repository.query; +import java.util.Objects; + import org.jspecify.annotations.Nullable; import org.springframework.data.domain.PageRequest; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; @@ -82,13 +84,17 @@ public abstract class AbstractElasticsearchRepositoryQuery implements Repository protected abstract boolean isExistsQuery(); @Override - public Object execute(Object[] parameters) { + public Object execute(@Nullable Object[] parameters) { - ElasticsearchParametersParameterAccessor parameterAccessor = getParameterAccessor(parameters); + // need this additional var, otherwise the code analysis does not recognize + // that parameters is not null after the check + var parametersNN = Objects.requireNonNull(parameters, "parameters must not be null"); + + ElasticsearchParametersParameterAccessor parameterAccessor = getParameterAccessor(parametersNN); ResultProcessor resultProcessor = queryMethod.getResultProcessor().withDynamicProjection(parameterAccessor); Class clazz = resultProcessor.getReturnedType().getDomainType(); - Query query = createQuery(parameters); + Query query = createQuery(parametersNN); IndexCoordinates index = parameterAccessor .getIndexCoordinates(elasticsearchOperations.getIndexCoordinatesFor(clazz)); diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/AbstractReactiveElasticsearchRepositoryQuery.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/AbstractReactiveElasticsearchRepositoryQuery.java index 830de5315..2e83d5657 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/AbstractReactiveElasticsearchRepositoryQuery.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/AbstractReactiveElasticsearchRepositoryQuery.java @@ -18,6 +18,9 @@ package org.springframework.data.elasticsearch.repository.query; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import java.util.Objects; + +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.springframework.core.convert.converter.Converter; import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations; @@ -72,10 +75,12 @@ abstract class AbstractReactiveElasticsearchRepositoryQuery implements Repositor * @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[]) */ @Override - public Object execute(Object[] parameters) { + public Object execute(@Nullable Object[] parameters) { - Object result = queryMethod.hasReactiveWrapperParameter() ? executeDeferred(parameters) - : execute(new ReactiveElasticsearchParametersParameterAccessor(queryMethod, parameters)); + var parametersNN = Objects.requireNonNull(parameters, "parameters must not be null"); + + Object result = queryMethod.hasReactiveWrapperParameter() ? executeDeferred(parametersNN) + : execute(new ReactiveElasticsearchParametersParameterAccessor(queryMethod, parametersNN)); return queryMethod.isNotSearchHitMethod() ? SearchHitSupport.unwrapSearchHits(result) : result; } @@ -98,7 +103,7 @@ abstract class AbstractReactiveElasticsearchRepositoryQuery implements Repositor Class domainType = returnedType.getDomainType(); Class typeToRead = returnedType.getTypeToRead(); - if (SearchHit.class.isAssignableFrom(typeToRead)) { + if (typeToRead != null && SearchHit.class.isAssignableFrom(typeToRead)) { typeToRead = queryMethod.unwrappedReturnType; } @@ -145,9 +150,10 @@ abstract class AbstractReactiveElasticsearchRepositoryQuery implements Repositor .map(count -> count > 0); } else if (queryMethod.isCollectionQuery()) { return (query, type, targetType, indexCoordinates) -> operations.search(query.setPageable(accessor.getPageable()), - type, targetType, indexCoordinates); + type, Objects.requireNonNull(targetType), indexCoordinates); } else { - return operations::search; + return (query, type, targetType, index) -> operations.search(query, type, Objects.requireNonNull(targetType), + index); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/package-info.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/package-info.java index e903d1ffe..eb6042f72 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repository.query; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/parser/package-info.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/parser/package-info.java index 5f524c1b8..f7179d755 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/parser/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/parser/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repository.query.parser; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/MappingElasticsearchEntityInformation.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/MappingElasticsearchEntityInformation.java index 096dc0737..9c5fe0fa8 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/MappingElasticsearchEntityInformation.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/MappingElasticsearchEntityInformation.java @@ -15,6 +15,7 @@ */ package org.springframework.data.elasticsearch.repository.support; +import org.jspecify.annotations.Nullable; import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty; @@ -58,7 +59,7 @@ public class MappingElasticsearchEntityInformation extends PersistentEnti } @Override - public Long getVersion(T entity) { + public @Nullable Long getVersion(T entity) { ElasticsearchPersistentProperty versionProperty = persistentEntity.getVersionProperty(); try { diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java index 25b8c67a0..e66bf95e0 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java @@ -18,6 +18,7 @@ package org.springframework.data.elasticsearch.repository.support; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; @@ -240,13 +241,13 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi @SuppressWarnings("unchecked") @Override - public Page searchSimilar(T entity, @Nullable String[] fields, Pageable pageable) { + public Page searchSimilar(T entity, String @Nullable [] fields, Pageable pageable) { Assert.notNull(entity, "Cannot search similar records for 'null'."); Assert.notNull(pageable, "'pageable' cannot be 'null'"); MoreLikeThisQuery query = new MoreLikeThisQuery(); - query.setId(stringIdRepresentation(extractIdFromBean(entity))); + query.setId(Objects.requireNonNull(stringIdRepresentation(extractIdFromBean(entity)))); query.setPageable(pageable); if (fields != null) { @@ -254,7 +255,7 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi } SearchHits searchHits = execute(operations -> operations.search(query, entityClass, getIndexCoordinates())); - SearchPage searchPage = SearchHitSupport.searchPageFor(searchHits, pageable); + SearchPage searchPage = SearchHitSupport.searchPageFor(Objects.requireNonNull(searchHits), pageable); return (Page) SearchHitSupport.unwrapSearchHits(searchPage); } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/package-info.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/package-info.java index 7f6a0f13f..7a5ae7805 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repository.support; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/querybyexample/package-info.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/querybyexample/package-info.java index c2b3be5cc..13f306560 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/querybyexample/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/querybyexample/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repository.support.querybyexample; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/spel/package-info.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/spel/package-info.java index 0388eba7c..f92606974 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/spel/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/spel/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repository.support.spel; diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/value/package-info.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/value/package-info.java index 18e794112..3403b59bf 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/value/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/value/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repository.support.value; diff --git a/src/main/java/org/springframework/data/elasticsearch/support/DefaultStringObjectMap.java b/src/main/java/org/springframework/data/elasticsearch/support/DefaultStringObjectMap.java index 30a3d8fd9..04b97da4c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/support/DefaultStringObjectMap.java +++ b/src/main/java/org/springframework/data/elasticsearch/support/DefaultStringObjectMap.java @@ -77,33 +77,33 @@ public class DefaultStringObjectMap> implements Str } @Override - public boolean containsKey(Object key) { + public boolean containsKey(@Nullable Object key) { return delegate.containsKey(key); } @Override - public boolean containsValue(Object value) { + public boolean containsValue(@Nullable Object value) { return delegate.containsValue(value); } @Override @Nullable - public Object get(Object key) { + public Object get(@Nullable Object key) { return delegate.get(key); } @Override - public Object getOrDefault(Object key, Object defaultValue) { + public Object getOrDefault(@Nullable Object key, @Nullable Object defaultValue) { return delegate.getOrDefault(key, defaultValue); } @Override - public Object put(String key, Object value) { + public @Nullable Object put(String key, @Nullable Object value) { return delegate.put(key, value); } @Override - public Object remove(Object key) { + public Object remove(@Nullable Object key) { return delegate.remove(key); } @@ -133,7 +133,7 @@ public class DefaultStringObjectMap> implements Str } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { return delegate.equals(o); } @@ -143,7 +143,8 @@ public class DefaultStringObjectMap> implements Str } @Override - public void forEach(BiConsumer action) { + public void forEach( + @SuppressWarnings("NullableProblems") BiConsumer action) { delegate.forEach(action); } @@ -163,7 +164,7 @@ public class DefaultStringObjectMap> implements Str Assert.notNull(path, "path must not be null"); - Map current = this; + Map current = this; String[] segments = path.split("\\."); for (int i = 0; i < segments.length; i++) { diff --git a/src/main/java/org/springframework/data/elasticsearch/support/HttpHeaders.java b/src/main/java/org/springframework/data/elasticsearch/support/HttpHeaders.java index 176e271db..dd6aac302 100644 --- a/src/main/java/org/springframework/data/elasticsearch/support/HttpHeaders.java +++ b/src/main/java/org/springframework/data/elasticsearch/support/HttpHeaders.java @@ -99,18 +99,18 @@ public class HttpHeaders implements MultiValueMap { } @Override - public boolean containsKey(Object key) { + public boolean containsKey(@Nullable Object key) { return delegate.containsKey(key); } @Override - public boolean containsValue(Object value) { + public boolean containsValue(@Nullable Object value) { return delegate.containsValue(value); } @Override @Nullable - public List<@Nullable String> get(Object key) { + public List<@Nullable String> get(@Nullable Object key) { return delegate.get(key); } @@ -121,7 +121,7 @@ public class HttpHeaders implements MultiValueMap { } @Override - public List<@Nullable String> remove(Object key) { + public List<@Nullable String> remove(@Nullable Object key) { return delegate.remove(key); } @@ -130,6 +130,7 @@ public class HttpHeaders implements MultiValueMap { Assert.notNull(m, "m must not be null"); + // noinspection NullableProblems delegate.putAll(m); } @@ -144,18 +145,18 @@ public class HttpHeaders implements MultiValueMap { } @Override - public Collection> values() { + public Collection> values() { return delegate.values(); } @Override - public Set>> entrySet() { + public Set>> entrySet() { return delegate.entrySet(); } @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { return delegate.equals(o); } diff --git a/src/main/java/org/springframework/data/elasticsearch/support/StringObjectMap.java b/src/main/java/org/springframework/data/elasticsearch/support/StringObjectMap.java index 0699830a5..7914cb252 100644 --- a/src/main/java/org/springframework/data/elasticsearch/support/StringObjectMap.java +++ b/src/main/java/org/springframework/data/elasticsearch/support/StringObjectMap.java @@ -38,7 +38,7 @@ import org.springframework.util.Assert; * @author Peter-Josef Meisch * @since 4.2 */ -public interface StringObjectMap> extends Map { +public interface StringObjectMap> extends Map { /** * {@link #put(Object, Object)} the {@code key}/{@code value} tuple and return {@code this} object. * diff --git a/src/main/java/org/springframework/data/elasticsearch/support/package-info.java b/src/main/java/org/springframework/data/elasticsearch/support/package-info.java index 7c65e45ba..ea8a97b69 100644 --- a/src/main/java/org/springframework/data/elasticsearch/support/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/support/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.support; diff --git a/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Geohash.java b/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Geohash.java index 875c13871..e4ed6fdd9 100644 --- a/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Geohash.java +++ b/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Geohash.java @@ -18,7 +18,9 @@ package org.springframework.data.elasticsearch.utils.geohash; import java.util.ArrayList; import java.util.Collection; import java.util.Locale; +import java.util.Objects; +import org.jspecify.annotations.Nullable; import org.springframework.util.Assert; /** @@ -165,18 +167,18 @@ public class Geohash { String south = getNeighbor(geohash, level, 0, -1); String north = getNeighbor(geohash, level, 0, +1); if (north != null) { - neighbors.add(getNeighbor(north, level, -1, 0)); + neighbors.add(Objects.requireNonNull(getNeighbor(north, level, -1, 0))); neighbors.add(north); - neighbors.add(getNeighbor(north, level, +1, 0)); + neighbors.add(Objects.requireNonNull(getNeighbor(north, level, +1, 0))); } - neighbors.add(getNeighbor(geohash, level, -1, 0)); - neighbors.add(getNeighbor(geohash, level, +1, 0)); + neighbors.add(Objects.requireNonNull(getNeighbor(geohash, level, -1, 0))); + neighbors.add(Objects.requireNonNull(getNeighbor(geohash, level, +1, 0))); if (south != null) { - neighbors.add(getNeighbor(south, level, -1, 0)); + neighbors.add(Objects.requireNonNull(getNeighbor(south, level, -1, 0))); neighbors.add(south); - neighbors.add(getNeighbor(south, level, +1, 0)); + neighbors.add(Objects.requireNonNull(getNeighbor(south, level, +1, 0))); } return neighbors; @@ -191,7 +193,7 @@ public class Geohash { * @param dy delta of the second grid coordinate (must be -1, 0 or +1) * @return geohash of the defined cell */ - public static String getNeighbor(String geohash, int level, int dx, int dy) { + public static @Nullable String getNeighbor(String geohash, int level, int dx, int dy) { int cell = BASE_32_STRING.indexOf(geohash.charAt(level - 1)); // Decoding the Geohash bit pattern to determine grid coordinates @@ -231,7 +233,7 @@ public class Geohash { return geohash.substring(0, level - 1) + encodeBase32(nx, ny); } else { String neighbor = getNeighbor(geohash, level - 1, dx, dy); - return (neighbor != null) ? neighbor + encodeBase32(nx, ny) : neighbor; + return (neighbor != null) ? neighbor + encodeBase32(nx, ny) : null; } } } diff --git a/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Point.java b/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Point.java index fec7a22e1..2076b7c9b 100644 --- a/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Point.java +++ b/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Point.java @@ -15,6 +15,8 @@ */ package org.springframework.data.elasticsearch.utils.geohash; +import org.jspecify.annotations.Nullable; + /** * /** Code copied from Elasticsearch 7.10, Apache License V2 * https://github.com/elastic/elasticsearch/blob/7.10/libs/geo/src/main/java/org/elasticsearch/geometry/Point.java
@@ -77,7 +79,7 @@ public class Point implements Geometry { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Rectangle.java b/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Rectangle.java index 62dc944f4..c07988ba2 100644 --- a/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Rectangle.java +++ b/src/main/java/org/springframework/data/elasticsearch/utils/geohash/Rectangle.java @@ -15,6 +15,8 @@ */ package org.springframework.data.elasticsearch.utils.geohash; +import org.jspecify.annotations.Nullable; + /** * Code copied from Elasticsearch 7.10, Apache License V2 * https://github.com/elastic/elasticsearch/blob/7.10/libs/geo/src/main/java/org/elasticsearch/geometry/Rectangle.java @@ -146,7 +148,7 @@ public class Rectangle implements Geometry { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/main/java/org/springframework/data/elasticsearch/utils/geohash/package-info.java b/src/main/java/org/springframework/data/elasticsearch/utils/geohash/package-info.java index bfdc44b26..73f517350 100644 --- a/src/main/java/org/springframework/data/elasticsearch/utils/geohash/package-info.java +++ b/src/main/java/org/springframework/data/elasticsearch/utils/geohash/package-info.java @@ -21,4 +21,5 @@ * @author Peter-Josef Meisch * @since 4.4 */ +@org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.utils.geohash; diff --git a/src/test/java/org/elasticsearch/bootstrap/package-info.java b/src/test/java/org/elasticsearch/bootstrap/package-info.java new file mode 100644 index 000000000..9149417c8 --- /dev/null +++ b/src/test/java/org/elasticsearch/bootstrap/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.elasticsearch.bootstrap; diff --git a/src/test/java/org/springframework/data/elasticsearch/NestedObjectELCIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/NestedObjectELCIntegrationTests.java index 80e21e60f..f0e787fd4 100644 --- a/src/test/java/org/springframework/data/elasticsearch/NestedObjectELCIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/NestedObjectELCIntegrationTests.java @@ -20,8 +20,6 @@ import static org.springframework.data.elasticsearch.client.elc.Queries.*; import co.elastic.clients.elasticsearch._types.query_dsl.ChildScoreMode; -import org.jspecify.annotations.NonNull; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -47,7 +45,7 @@ public class NestedObjectELCIntegrationTests extends NestedObjectIntegrationTest } @Override - protected @NonNull Query getNestedQuery1() { + protected Query getNestedQuery1() { return NativeQuery.builder().withQuery( // nested(n -> n // .path("car") // diff --git a/src/test/java/org/springframework/data/elasticsearch/NestedObjectIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/NestedObjectIntegrationTests.java index 890cce9e5..181fb5a42 100644 --- a/src/test/java/org/springframework/data/elasticsearch/NestedObjectIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/NestedObjectIntegrationTests.java @@ -160,7 +160,7 @@ public abstract class NestedObjectIntegrationTests { operations.bulkIndex(indexQueries, PersonMultipleLevelNested.class); // then - Map mapping = operations.indexOps(PersonMultipleLevelNested.class).getMapping(); + Map mapping = operations.indexOps(PersonMultipleLevelNested.class).getMapping(); assertThat(mapping).isNotNull(); Map propertyMap = (Map) mapping.get("properties"); diff --git a/src/test/java/org/springframework/data/elasticsearch/annotations/package-info.java b/src/test/java/org/springframework/data/elasticsearch/annotations/package-info.java new file mode 100644 index 000000000..cf00c624a --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/annotations/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.annotations; diff --git a/src/test/java/org/springframework/data/elasticsearch/client/elc/CriteriaQueryMappingUnitTests.java b/src/test/java/org/springframework/data/elasticsearch/client/elc/CriteriaQueryMappingUnitTests.java index 37862d900..74c6ca975 100644 --- a/src/test/java/org/springframework/data/elasticsearch/client/elc/CriteriaQueryMappingUnitTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/client/elc/CriteriaQueryMappingUnitTests.java @@ -28,7 +28,6 @@ import java.util.Collections; import java.util.Date; import java.util.List; -import org.assertj.core.api.SoftAssertions; import org.json.JSONException; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; @@ -422,13 +421,11 @@ public class CriteriaQueryMappingUnitTests { mappingElasticsearchConverter.updateQuery(query, Person.class); - SoftAssertions softly = new SoftAssertions(); - softly.assertThat(query.getFields()).containsExactly("first-name", "last-name"); + assertThat(query.getFields()).containsExactly("first-name", "last-name"); SourceFilter sourceFilter = query.getSourceFilter(); - softly.assertThat(sourceFilter).isNotNull(); - softly.assertThat(sourceFilter.getIncludes()).containsExactly("first-name"); - softly.assertThat(sourceFilter.getExcludes()).containsExactly("last-name"); - softly.assertAll(); + assertThat(sourceFilter).isNotNull(); + assertThat(sourceFilter.getIncludes()).containsExactly("first-name"); + assertThat(sourceFilter.getExcludes()).containsExactly("last-name"); } @Test @@ -440,11 +437,9 @@ public class CriteriaQueryMappingUnitTests { mappingElasticsearchConverter.updateQuery(query, Person.class); - SoftAssertions softly = new SoftAssertions(); List storedFields = query.getStoredFields(); - softly.assertThat(storedFields).isNotNull(); - softly.assertThat(storedFields).containsExactly("first-name", "last-name"); - softly.assertAll(); + assertThat(storedFields).isNotNull(); + assertThat(storedFields).containsExactly("first-name", "last-name"); } // the following test failed because of a wrong implementation in Criteria @@ -476,73 +471,73 @@ public class CriteriaQueryMappingUnitTests { CriteriaQuery criteriaQuery = new CriteriaQuery(criteria); String expected = """ - { - "bool": { - "must": [ - { - "query_string": { - "default_operator": "and", - "fields": [ - "first" - ], - "query": "hello" - } - }, - { - "bool": { - "should": [ - { - "exists": { - "field": "second" - } - }, - { - "bool": { - "must": [ - { - "exists": { - "field": "third" - } - }, - { - "query_string": { - "default_operator": "and", - "fields": [ - "fourth" - ], - "query": "ciao" - } - } - ] - } - }, - { - "bool": { - "must": [ - { - "exists": { - "field": "third" - } - }, - { - "query_string": { - "default_operator": "and", - "fields": [ - "fourth" - ], - "query": "hi" - } - } - ] - } - } - ] - } - } - ] - } - } - """; + { + "bool": { + "must": [ + { + "query_string": { + "default_operator": "and", + "fields": [ + "first" + ], + "query": "hello" + } + }, + { + "bool": { + "should": [ + { + "exists": { + "field": "second" + } + }, + { + "bool": { + "must": [ + { + "exists": { + "field": "third" + } + }, + { + "query_string": { + "default_operator": "and", + "fields": [ + "fourth" + ], + "query": "ciao" + } + } + ] + } + }, + { + "bool": { + "must": [ + { + "exists": { + "field": "third" + } + }, + { + "query_string": { + "default_operator": "and", + "fields": [ + "fourth" + ], + "query": "hi" + } + } + ] + } + } + ] + } + } + ] + } + } + """; mappingElasticsearchConverter.updateQuery(criteriaQuery, Person.class); var queryString = queryToJson(CriteriaQueryProcessor.createQuery(criteriaQuery.getCriteria()), mapper); diff --git a/src/test/java/org/springframework/data/elasticsearch/client/elc/package-info.java b/src/test/java/org/springframework/data/elasticsearch/client/elc/package-info.java new file mode 100644 index 000000000..42a424653 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/client/elc/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.client.elc; diff --git a/src/test/java/org/springframework/data/elasticsearch/client/elc/rest5_client/package-info.java b/src/test/java/org/springframework/data/elasticsearch/client/elc/rest5_client/package-info.java new file mode 100644 index 000000000..82ae5db38 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/client/elc/rest5_client/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.client.elc.rest5_client; diff --git a/src/test/java/org/springframework/data/elasticsearch/client/elc/rest_client/package-info.java b/src/test/java/org/springframework/data/elasticsearch/client/elc/rest_client/package-info.java index 98699f58e..11a4fe92d 100644 --- a/src/test/java/org/springframework/data/elasticsearch/client/elc/rest_client/package-info.java +++ b/src/test/java/org/springframework/data/elasticsearch/client/elc/rest_client/package-info.java @@ -1,2 +1,18 @@ -@Deprecated(since = "6.0", forRemoval=true) +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.client.elc.rest_client; diff --git a/src/test/java/org/springframework/data/elasticsearch/client/package-info.java b/src/test/java/org/springframework/data/elasticsearch/client/package-info.java new file mode 100644 index 000000000..ca07916ad --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/client/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.client; diff --git a/src/test/java/org/springframework/data/elasticsearch/client/util/package-info.java b/src/test/java/org/springframework/data/elasticsearch/client/util/package-info.java index 3e0be8092..b2bf31c86 100644 --- a/src/test/java/org/springframework/data/elasticsearch/client/util/package-info.java +++ b/src/test/java/org/springframework/data/elasticsearch/client/util/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.client.util; diff --git a/src/test/java/org/springframework/data/elasticsearch/config/AuditingReactiveIntegrationTest.java b/src/test/java/org/springframework/data/elasticsearch/config/AuditingReactiveIntegrationTest.java index 9a2058275..059e8f2e4 100644 --- a/src/test/java/org/springframework/data/elasticsearch/config/AuditingReactiveIntegrationTest.java +++ b/src/test/java/org/springframework/data/elasticsearch/config/AuditingReactiveIntegrationTest.java @@ -82,6 +82,7 @@ public abstract class AuditingReactiveIntegrationTest { entity.setId("1"); entity = callbacks.callback(ReactiveBeforeConvertCallback.class, entity, IndexCoordinates.of("index")).block(); + assertThat(entity).isNotNull(); assertThat(entity.getCreated()).isNotNull(); assertThat(entity.getModified()).isEqualTo(entity.created); assertThat(entity.getCreatedBy()).isEqualTo("Auditor 1"); @@ -91,6 +92,7 @@ public abstract class AuditingReactiveIntegrationTest { entity = callbacks.callback(ReactiveBeforeConvertCallback.class, entity, IndexCoordinates.of("index")).block(); + assertThat(entity).isNotNull(); assertThat(entity.getCreated()).isNotNull(); assertThat(entity.getModified()).isNotEqualTo(entity.created); assertThat(entity.getCreatedBy()).isEqualTo("Auditor 1"); diff --git a/src/test/java/org/springframework/data/elasticsearch/config/configuration/ElasticsearchConfigurationELCTests.java b/src/test/java/org/springframework/data/elasticsearch/config/configuration/ElasticsearchConfigurationELCTests.java index b443f5c99..8a8fe08d2 100644 --- a/src/test/java/org/springframework/data/elasticsearch/config/configuration/ElasticsearchConfigurationELCTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/config/configuration/ElasticsearchConfigurationELCTests.java @@ -18,9 +18,8 @@ package org.springframework.data.elasticsearch.config.configuration; import static org.assertj.core.api.Assertions.*; import co.elastic.clients.elasticsearch.ElasticsearchClient; - import co.elastic.clients.transport.rest5_client.low_level.Rest5Client; -import org.jspecify.annotations.NonNull; + import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -51,7 +50,7 @@ public class ElasticsearchConfigurationELCTests { considerNestedRepositories = true) static class Config extends ElasticsearchConfiguration { @Override - public @NonNull ClientConfiguration clientConfiguration() { + public ClientConfiguration clientConfiguration() { return ClientConfiguration.builder() // .connectedTo("localhost:9200") // .build(); diff --git a/src/test/java/org/springframework/data/elasticsearch/config/configuration/ElasticsearchLegacyRestClientConfigurationELCTests.java b/src/test/java/org/springframework/data/elasticsearch/config/configuration/ElasticsearchLegacyRestClientConfigurationELCTests.java index 0fb9ef54b..988fb6771 100644 --- a/src/test/java/org/springframework/data/elasticsearch/config/configuration/ElasticsearchLegacyRestClientConfigurationELCTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/config/configuration/ElasticsearchLegacyRestClientConfigurationELCTests.java @@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.*; import co.elastic.clients.elasticsearch.ElasticsearchClient; import org.elasticsearch.client.RestClient; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -52,7 +51,7 @@ public class ElasticsearchLegacyRestClientConfigurationELCTests { considerNestedRepositories = true) static class Config extends ElasticsearchLegacyRestClientConfiguration { @Override - public @NonNull ClientConfiguration clientConfiguration() { + public ClientConfiguration clientConfiguration() { return ClientConfiguration.builder() // .connectedTo("localhost:9200") // .build(); diff --git a/src/test/java/org/springframework/data/elasticsearch/config/configuration/ReactiveElasticsearchConfigurationELCTests.java b/src/test/java/org/springframework/data/elasticsearch/config/configuration/ReactiveElasticsearchConfigurationELCTests.java index 40283a018..297dbf660 100644 --- a/src/test/java/org/springframework/data/elasticsearch/config/configuration/ReactiveElasticsearchConfigurationELCTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/config/configuration/ReactiveElasticsearchConfigurationELCTests.java @@ -17,7 +17,6 @@ package org.springframework.data.elasticsearch.config.configuration; import static org.assertj.core.api.Assertions.*; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -50,7 +49,7 @@ public class ReactiveElasticsearchConfigurationELCTests { static class Config extends ReactiveElasticsearchConfiguration { @Override - public @NonNull ClientConfiguration clientConfiguration() { + public ClientConfiguration clientConfiguration() { return ClientConfiguration.builder() // .connectedTo("localhost:9200") // .build(); diff --git a/src/test/java/org/springframework/data/elasticsearch/config/configuration/ReactiveElasticsearchLegacyRestClientConfigurationELCTests.java b/src/test/java/org/springframework/data/elasticsearch/config/configuration/ReactiveElasticsearchLegacyRestClientConfigurationELCTests.java index 25d465ff8..292fc297c 100644 --- a/src/test/java/org/springframework/data/elasticsearch/config/configuration/ReactiveElasticsearchLegacyRestClientConfigurationELCTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/config/configuration/ReactiveElasticsearchLegacyRestClientConfigurationELCTests.java @@ -17,7 +17,6 @@ package org.springframework.data.elasticsearch.config.configuration; import static org.assertj.core.api.Assertions.*; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -27,7 +26,6 @@ import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.client.ClientConfiguration; import org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchClient; -import org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchConfiguration; import org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchLegacyRestClientConfiguration; import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations; import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository; @@ -51,7 +49,7 @@ public class ReactiveElasticsearchLegacyRestClientConfigurationELCTests { static class Config extends ReactiveElasticsearchLegacyRestClientConfiguration { @Override - public @NonNull ClientConfiguration clientConfiguration() { + public ClientConfiguration clientConfiguration() { return ClientConfiguration.builder() // .connectedTo("localhost:9200") // .build(); diff --git a/src/test/java/org/springframework/data/elasticsearch/config/configuration/package-info.java b/src/test/java/org/springframework/data/elasticsearch/config/configuration/package-info.java new file mode 100644 index 000000000..6ba64a626 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/config/configuration/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.config.configuration; diff --git a/src/test/java/org/springframework/data/elasticsearch/config/namespace/package-info.java b/src/test/java/org/springframework/data/elasticsearch/config/namespace/package-info.java new file mode 100644 index 000000000..4a0cdbeca --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/config/namespace/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.config.namespace; diff --git a/src/test/java/org/springframework/data/elasticsearch/config/nested/package-info.java b/src/test/java/org/springframework/data/elasticsearch/config/nested/package-info.java new file mode 100644 index 000000000..a5a86e9e5 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/config/nested/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.config.nested; diff --git a/src/test/java/org/springframework/data/elasticsearch/config/notnested/package-info.java b/src/test/java/org/springframework/data/elasticsearch/config/notnested/package-info.java index c32f6a26e..aeab5069e 100644 --- a/src/test/java/org/springframework/data/elasticsearch/config/notnested/package-info.java +++ b/src/test/java/org/springframework/data/elasticsearch/config/notnested/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.config.notnested; diff --git a/src/test/java/org/springframework/data/elasticsearch/config/package-info.java b/src/test/java/org/springframework/data/elasticsearch/config/package-info.java new file mode 100644 index 000000000..13583609a --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/config/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.config; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java index cf992b07b..bbaf0383d 100755 --- a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java @@ -1145,7 +1145,7 @@ public abstract class ElasticsearchIntegrationTests { assertThat(searchHits.getTotalHits()).isEqualTo(10); assertThat(searchHits.getSearchHits()).hasSize(5); - Collection returnedIds = searchHits.getSearchHits().stream().map(SearchHit::getId) + Collection<@Nullable String> returnedIds = searchHits.getSearchHits().stream().map(SearchHit::getId) .collect(Collectors.toList()); moreLikeThisQuery.setPageable(PageRequest.of(1, 5)); @@ -1159,6 +1159,7 @@ public abstract class ElasticsearchIntegrationTests { searchHits.getSearchHits().stream().map(SearchHit::getId).forEach(returnedIds::add); assertThat(returnedIds).hasSize(10); + // noinspection NullableProblems assertThat(ids).containsAll(returnedIds); } @@ -1180,10 +1181,11 @@ public abstract class ElasticsearchIntegrationTests { List> sampleEntities = new ArrayList<>(); while (scroll.hasSearchHits()) { sampleEntities.addAll(scroll.getSearchHits()); - scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(scroll.getScrollId(), 1000, + scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue( + Objects.requireNonNull(scroll.getScrollId()), 1000, SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); } - ((AbstractElasticsearchTemplate) operations).searchScrollClear(scroll.getScrollId()); + ((AbstractElasticsearchTemplate) operations).searchScrollClear(Objects.requireNonNull(scroll.getScrollId())); assertThat(sampleEntities).hasSize(30); } @@ -1206,10 +1208,11 @@ public abstract class ElasticsearchIntegrationTests { List> sampleEntities = new ArrayList<>(); while (scroll.hasSearchHits()) { sampleEntities.addAll(scroll.getSearchHits()); - scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(scroll.getScrollId(), 1000, + scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue( + Objects.requireNonNull(scroll.getScrollId()), 1000, SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); } - ((AbstractElasticsearchTemplate) operations).searchScrollClear(scroll.getScrollId()); + ((AbstractElasticsearchTemplate) operations).searchScrollClear(Objects.requireNonNull(scroll.getScrollId())); assertThat(sampleEntities).hasSize(30); } @@ -1234,10 +1237,11 @@ public abstract class ElasticsearchIntegrationTests { while (scroll.hasSearchHits()) { sampleEntities.addAll(scroll.getSearchHits()); scrollId = scroll.getScrollId(); - scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(scrollId, 1000, SampleEntity.class, + scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(Objects.requireNonNull(scrollId), 1000, + SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); } - ((AbstractElasticsearchTemplate) operations).searchScrollClear(scrollId); + ((AbstractElasticsearchTemplate) operations).searchScrollClear(Objects.requireNonNull(scrollId)); assertThat(sampleEntities).hasSize(30); } @@ -1260,10 +1264,11 @@ public abstract class ElasticsearchIntegrationTests { while (scroll.hasSearchHits()) { sampleEntities.addAll(scroll.getSearchHits()); scrollId = scroll.getScrollId(); - scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(scrollId, 1000, SampleEntity.class, + scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(Objects.requireNonNull(scrollId), 1000, + SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); } - ((AbstractElasticsearchTemplate) operations).searchScrollClear(scrollId); + ((AbstractElasticsearchTemplate) operations).searchScrollClear(Objects.requireNonNull(scrollId)); assertThat(sampleEntities).hasSize(30); } @@ -1287,10 +1292,11 @@ public abstract class ElasticsearchIntegrationTests { while (scroll.hasSearchHits()) { sampleEntities.addAll(scroll.getSearchHits()); scrollId = scroll.getScrollId(); - scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(scrollId, 1000, SampleEntity.class, + scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(Objects.requireNonNull(scrollId), 1000, + SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); } - ((AbstractElasticsearchTemplate) operations).searchScrollClear(scrollId); + ((AbstractElasticsearchTemplate) operations).searchScrollClear(Objects.requireNonNull(scrollId)); assertThat(sampleEntities).hasSize(30); } @@ -1313,10 +1319,11 @@ public abstract class ElasticsearchIntegrationTests { while (scroll.hasSearchHits()) { sampleEntities.addAll(scroll.getSearchHits()); scrollId = scroll.getScrollId(); - scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(scrollId, 1000, SampleEntity.class, + scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(Objects.requireNonNull(scrollId), 1000, + SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); } - ((AbstractElasticsearchTemplate) operations).searchScrollClear(scrollId); + ((AbstractElasticsearchTemplate) operations).searchScrollClear(Objects.requireNonNull(scrollId)); assertThat(sampleEntities).hasSize(30); } @@ -1340,10 +1347,11 @@ public abstract class ElasticsearchIntegrationTests { while (scroll.hasSearchHits()) { sampleEntities.addAll(scroll.getSearchHits()); scrollId = scroll.getScrollId(); - scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(scrollId, 1000, SampleEntity.class, + scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(Objects.requireNonNull(scrollId), 1000, + SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); } - ((AbstractElasticsearchTemplate) operations).searchScrollClear(scrollId); + ((AbstractElasticsearchTemplate) operations).searchScrollClear(Objects.requireNonNull(scrollId)); assertThat(sampleEntities).hasSize(30); } @@ -1366,7 +1374,8 @@ public abstract class ElasticsearchIntegrationTests { while (scroll.hasSearchHits()) { sampleEntities.addAll(scroll.getSearchHits()); scrollId = scroll.getScrollId(); - scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(scrollId, 1000, SampleEntity.class, + scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(Objects.requireNonNull(scrollId), 1000, + SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); } ((AbstractElasticsearchTemplate) operations).searchScrollClear(scrollId); @@ -1516,7 +1525,7 @@ public abstract class ElasticsearchIntegrationTests { indexOperations1.putMapping(entity); // then - Map mapping = indexOperations.getMapping(); + Map mapping = indexOperations.getMapping(); assertThat(mapping.get("properties")).isNotNull(); } @@ -1538,7 +1547,7 @@ public abstract class ElasticsearchIntegrationTests { ); IndexOperations aliasIndexOps = operations.indexOps(IndexCoordinates.of(aliasName)); - Map mappingFromAlias = aliasIndexOps.getMapping(); + Map mappingFromAlias = aliasIndexOps.getMapping(); assertThat(mappingFromAlias).isNotNull(); assertThat( @@ -1576,6 +1585,7 @@ public abstract class ElasticsearchIntegrationTests { // then SampleEntity indexedEntity = operations.get(documentId, SampleEntity.class); + assertThat(indexedEntity).isNotNull(); assertThat(indexedEntity.getType()).isEqualTo(originalTypeInfo); assertThat(indexedEntity.getMessage()).isEqualTo(messageAfterUpdate); } @@ -1608,6 +1618,7 @@ public abstract class ElasticsearchIntegrationTests { // then SampleEntity indexedEntity = operations.get(documentId, SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); + assertThat(indexedEntity).isNotNull(); assertThat(indexedEntity.getMessage()).isEqualTo(messageAfterUpdate); } @@ -1638,6 +1649,7 @@ public abstract class ElasticsearchIntegrationTests { SampleEntity indexedEntity = operations.get(documentId, SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); + assertThat(indexedEntity).isNotNull(); assertThat(indexedEntity.getMessage()).isEqualTo(messageAfterUpdate); } @@ -1660,6 +1672,7 @@ public abstract class ElasticsearchIntegrationTests { // then SampleEntity indexedEntity = operations.get(documentId, SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName())); + assertThat(indexedEntity).isNotNull(); assertThat(indexedEntity.getMessage()).isEqualTo("test message"); } @@ -1672,7 +1685,8 @@ public abstract class ElasticsearchIntegrationTests { SampleEntity sampleEntity = SampleEntity.builder().id(documentId).message("some message") .version(System.currentTimeMillis()).build(); - IndexQuery idxQuery = new IndexQueryBuilder().withId(sampleEntity.getId()).withObject(sampleEntity).build(); + IndexQuery idxQuery = new IndexQueryBuilder().withId(Objects.requireNonNull(sampleEntity.getId())) + .withObject(sampleEntity).build(); IndexCoordinates index = IndexCoordinates.of(MULTI_INDEX_1_NAME); operations.index(idxQuery, index); @@ -1686,7 +1700,8 @@ public abstract class ElasticsearchIntegrationTests { List> entities = new ArrayList<>(scroll.getSearchHits()); while (scroll.hasSearchHits()) { - scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue(scroll.getScrollId(), + scroll = ((AbstractElasticsearchTemplate) operations).searchScrollContinue( + Objects.requireNonNull(scroll.getScrollId()), scrollTimeInMillis, SampleEntity.class, index); entities.addAll(scroll.getSearchHits()); @@ -1795,7 +1810,7 @@ public abstract class ElasticsearchIntegrationTests { IndexCoordinates index = IndexCoordinates.of(indexNameProvider.indexName()); operations.index(indexQuery, index); - Query searchQuery = getTermQuery("id", indexQuery.getId()); + Query searchQuery = getTermQuery("id", Objects.requireNonNull(indexQuery.getId())); // then SearchHits searchHits = operations.search(searchQuery, SampleEntity.class, index); @@ -2471,7 +2486,7 @@ public abstract class ElasticsearchIntegrationTests { // given // when - Map mapping = indexOperations.getMapping(); + Map mapping = indexOperations.getMapping(); // then assertThat(mapping).isNotNull(); @@ -3436,7 +3451,10 @@ public abstract class ElasticsearchIntegrationTests { Query query = getQueryForParentId("answer", qId1, null); SearchHits hits = operations.search(query, SampleJoinEntity.class); - List hitIds = hits.getSearchHits().stream().map(SearchHit::getId).collect(Collectors.toList()); + List hitIds = hits.getSearchHits() + .stream() + .map(hit -> (String) (Objects.requireNonNull(hit.getId()))) + .collect(Collectors.toList()); assertThat(hitIds.size()).isEqualTo(2); assertThat(hitIds.containsAll(Arrays.asList(aId1, aId2))).isTrue(); @@ -3461,13 +3479,17 @@ public abstract class ElasticsearchIntegrationTests { SearchHits updatedHits = operations.search(getQueryForParentId("answer", qId2, null), SampleJoinEntity.class); - List hitIds = updatedHits.getSearchHits().stream().map(SearchHit::getId).collect(Collectors.toList()); + List hitIds = updatedHits.getSearchHits().stream() + .map(hit -> (String) (Objects.requireNonNull(hit.getId()))) + .collect(Collectors.toList()); assertThat(hitIds.size()).isEqualTo(1); assertThat(hitIds.get(0)).isEqualTo(aId2); updatedHits = operations.search(getQueryForParentId("answer", qId1, null), SampleJoinEntity.class); - hitIds = updatedHits.getSearchHits().stream().map(SearchHit::getId).collect(Collectors.toList()); + hitIds = updatedHits.getSearchHits().stream() + .map(hit -> (String) (Objects.requireNonNull(hit.getId()))) + .collect(Collectors.toList()); assertThat(hitIds.size()).isEqualTo(1); assertThat(hitIds.get(0)).isEqualTo(aId1); } @@ -3480,7 +3502,9 @@ public abstract class ElasticsearchIntegrationTests { SearchHits deletedHits = operations.search(getQueryForParentId("answer", qId2, null), SampleJoinEntity.class); - List hitIds = deletedHits.getSearchHits().stream().map(SearchHit::getId).collect(Collectors.toList()); + List hitIds = deletedHits.getSearchHits().stream() + .map(hit -> (String) (Objects.requireNonNull(hit.getId()))) + .collect(Collectors.toList()); assertThat(hitIds.size()).isEqualTo(0); } @@ -4034,7 +4058,7 @@ public abstract class ElasticsearchIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -4773,7 +4797,7 @@ public abstract class ElasticsearchIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -4830,7 +4854,7 @@ public abstract class ElasticsearchIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -4942,7 +4966,7 @@ public abstract class ElasticsearchIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchIntegrationTests.java index b274f90fe..2e6139eab 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchIntegrationTests.java @@ -1121,7 +1121,7 @@ public abstract class ReactiveElasticsearchIntegrationTests { void shouldWorkWithImmutableClasses() { ImmutableEntity entity = new ImmutableEntity(null, "some text", null); - AtomicReference savedEntity = new AtomicReference<>(); + AtomicReference<@Nullable ImmutableEntity> savedEntity = new AtomicReference<>(); operations.save(entity).as(StepVerifier::create).consumeNextWith(saved -> { assertThat(saved).isNotNull(); @@ -1295,7 +1295,7 @@ public abstract class ReactiveElasticsearchIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; } @@ -1366,7 +1366,7 @@ public abstract class ReactiveElasticsearchIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; } @@ -1554,7 +1554,7 @@ public abstract class ReactiveElasticsearchIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/SearchAsYouTypeIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/SearchAsYouTypeIntegrationTests.java index 71b465a41..16921cc3b 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/SearchAsYouTypeIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/SearchAsYouTypeIntegrationTests.java @@ -90,7 +90,7 @@ public abstract class SearchAsYouTypeIntegrationTests { .collect(Collectors.toList()); // then - List ids = result.stream().map(SearchAsYouTypeEntity::getId).collect(Collectors.toList()); + List<@Nullable String> ids = result.stream().map(SearchAsYouTypeEntity::getId).collect(Collectors.toList()); assertThat(ids).containsExactlyInAnyOrder("1", "2"); } @@ -112,7 +112,7 @@ public abstract class SearchAsYouTypeIntegrationTests { .collect(Collectors.toList()); // then - List ids = result.stream().map(SearchAsYouTypeEntity::getId).collect(Collectors.toList()); + List<@Nullable String> ids = result.stream().map(SearchAsYouTypeEntity::getId).collect(Collectors.toList()); assertThat(ids).containsExactlyInAnyOrder("2", "3"); } @@ -191,7 +191,7 @@ public abstract class SearchAsYouTypeIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/aggregation/AggregationIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/aggregation/AggregationIntegrationTests.java index 6a2f61beb..4440a2f14 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/aggregation/AggregationIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/aggregation/AggregationIntegrationTests.java @@ -148,34 +148,30 @@ public abstract class AggregationIntegrationTests { @Document(indexName = "#{@indexNameProvider.indexName()}-article") static class ArticleEntity { - @Nullable @Id private String id; @Nullable private String title; @Nullable @Field(type = Text, fielddata = true) private String subject; - @Nullable @MultiField(mainField = @Field(type = Text), otherFields = { @InnerField(suffix = "untouched", type = Text, store = true, fielddata = true, analyzer = "keyword"), @InnerField(suffix = "sort", type = Text, store = true, analyzer = "keyword") }) private List authors = new ArrayList<>(); - @Nullable @Field(type = Integer, store = true) private List publishedYears = new ArrayList<>(); private int score; - public ArticleEntity(@Nullable String id) { + public ArticleEntity(String id) { this.id = id; } - @Nullable public String getId() { return id; } - public void setId(@Nullable String id) { + public void setId(String id) { this.id = id; } @@ -197,21 +193,19 @@ public abstract class AggregationIntegrationTests { this.subject = subject; } - @Nullable public List getAuthors() { return authors; } - public void setAuthors(@Nullable List authors) { + public void setAuthors(List authors) { this.authors = authors; } - @Nullable public List getPublishedYears() { return publishedYears; } - public void setPublishedYears(@Nullable List publishedYears) { + public void setPublishedYears(List publishedYears) { this.publishedYears = publishedYears; } @@ -278,7 +272,7 @@ public abstract class AggregationIntegrationTests { @Document(indexName = "#{@indexNameProvider.indexName()}-pipeline") static class PipelineAggsEntity { @Id private String id; - @Field(type = Keyword) private String keyword; + @Field(type = Keyword) private @Nullable String keyword; public PipelineAggsEntity() {} @@ -295,7 +289,7 @@ public abstract class AggregationIntegrationTests { this.id = id; } - public String getKeyword() { + public @Nullable String getKeyword() { return keyword; } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/aggregation/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/aggregation/package-info.java new file mode 100644 index 000000000..4756e29cd --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/aggregation/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.aggregation; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/cluster/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/cluster/package-info.java new file mode 100644 index 000000000..cc821667c --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/cluster/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.cluster; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverterUnitTests.java b/src/test/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverterUnitTests.java index 0b04ab9e0..9925baa88 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverterUnitTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverterUnitTests.java @@ -231,7 +231,7 @@ public class MappingElasticsearchConverterUnitTests { notificationAsMap.put("id", 1L); notificationAsMap.put("fromEmail", "from@email.com"); notificationAsMap.put("toEmail", "to@email.com"); - Map data = new HashMap<>(); + Map data = new HashMap<>(); data.put("documentType", "abc"); data.put("content", null); notificationAsMap.put("params", data); @@ -239,7 +239,7 @@ public class MappingElasticsearchConverterUnitTests { "org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverterUnitTests$Notification"); } - private Map writeToMap(Object source) { + private Map writeToMap(Object source) { Document sink = Document.create(); mappingElasticsearchConverter.write(source, sink); @@ -249,6 +249,7 @@ public class MappingElasticsearchConverterUnitTests { @Test public void shouldFailToInitializeGivenMappingContextIsNull() { + // noinspection DataFlowIssue assertThatThrownBy(() -> new MappingElasticsearchConverter(null)).isInstanceOf(IllegalArgumentException.class); } @@ -356,7 +357,7 @@ public class MappingElasticsearchConverterUnitTests { person.gender = Gender.MAN; person.address = observatoryRoad; - Map sink = writeToMap(person); + Map sink = writeToMap(person); assertThat(sink.get("address")).isEqualTo(gratiotAveAsMap); } @@ -370,7 +371,7 @@ public class MappingElasticsearchConverterUnitTests { sarahConnor.coWorkers = Arrays.asList(kyleReese, ginger); - Map target = writeToMap(sarahConnor); + Map target = writeToMap(sarahConnor); assertThat((List) target.get("coWorkers")).hasSize(2).contains(kyleAsMap); } @@ -382,7 +383,7 @@ public class MappingElasticsearchConverterUnitTests { sarahConnor.inventoryList = Arrays.asList(gun, grenade); - Map target = writeToMap(sarahConnor); + Map target = writeToMap(sarahConnor); assertThat((List) target.get("inventoryList")).containsExactly(gunAsMap, grenadeAsMap); } @@ -420,7 +421,7 @@ public class MappingElasticsearchConverterUnitTests { sarahConnor.shippingAddresses = new LinkedHashMap<>(); sarahConnor.shippingAddresses.put("home", observatoryRoad); - Map target = writeToMap(sarahConnor); + Map target = writeToMap(sarahConnor); assertThat(target.get("shippingAddresses")).isInstanceOf(Map.class); assertThat(target.get("shippingAddresses")).isEqualTo(singletonMap("home", gratiotAveAsMap)); } @@ -432,7 +433,7 @@ public class MappingElasticsearchConverterUnitTests { sarahConnor.inventoryMap.put("glock19", gun); sarahConnor.inventoryMap.put("40 mm grenade", grenade); - Map target = writeToMap(sarahConnor); + Map target = writeToMap(sarahConnor); assertThat(target.get("inventoryMap")).isInstanceOf(Map.class); assertThat((Map) target.get("inventoryMap")).containsEntry("glock19", gunAsMap) .containsEntry("40 mm grenade", grenadeAsMap); @@ -466,7 +467,7 @@ public class MappingElasticsearchConverterUnitTests { skynet.objectList.add(t800); skynet.objectList.add(gun); - Map target = writeToMap(skynet); + Map target = writeToMap(skynet); assertThat((List) target.get("objectList")).containsExactly(t800AsMap, gunAsMap); } @@ -489,7 +490,7 @@ public class MappingElasticsearchConverterUnitTests { skynet.objectList = new ArrayList<>(); skynet.objectList.add(Arrays.asList(t800, gun)); - Map target = writeToMap(skynet); + Map target = writeToMap(skynet); assertThat((List) target.get("objectList")).containsExactly(Arrays.asList(t800AsMap, gunAsMap)); } @@ -513,9 +514,10 @@ public class MappingElasticsearchConverterUnitTests { skynet.objectMap.put("gun", gun); skynet.objectMap.put("grenade", grenade); - Map target = writeToMap(skynet); + Map target = writeToMap(skynet); - assertThat((Map) target.get("objectMap")).containsEntry("gun", gunAsMap).containsEntry("grenade", + assertThat((Map) target.get("objectMap")).containsEntry("gun", gunAsMap).containsEntry( + "grenade", grenadeAsMap); } @@ -537,9 +539,9 @@ public class MappingElasticsearchConverterUnitTests { skynet.objectMap = new LinkedHashMap<>(); skynet.objectMap.put("inventory", singletonMap("glock19", gun)); - Map target = writeToMap(skynet); + Map target = writeToMap(skynet); - assertThat((Map) target.get("objectMap")).containsEntry("inventory", + assertThat((Map) target.get("objectMap")).containsEntry("inventory", singletonMap("glock19", gunAsMap)); } @@ -584,7 +586,7 @@ public class MappingElasticsearchConverterUnitTests { public void writesNestedAliased() { t800.inventoryList = singletonList(rifle); - Map target = writeToMap(t800); + Map target = writeToMap(t800); assertThat((List) target.get("inventoryList")).contains(rifleAsMap); } @@ -617,7 +619,7 @@ public class MappingElasticsearchConverterUnitTests { sarahConnor.address = bigBunsCafe; - Map target = writeToMap(sarahConnor); + Map target = writeToMap(sarahConnor); assertThat(target.get("address")).isEqualTo(bigBunsCafeAsMap); } @@ -714,7 +716,7 @@ public class MappingElasticsearchConverterUnitTests { Notification notification = new Notification(); notification.setFromEmail("from@email.com"); notification.setToEmail("to@email.com"); - Map data = new HashMap<>(); + Map data = new HashMap<>(); data.put("documentType", "abc"); data.put("content", null); notification.params = data; @@ -732,7 +734,7 @@ public class MappingElasticsearchConverterUnitTests { document.put("id", 1L); document.put("fromEmail", "from@email.com"); document.put("toEmail", "to@email.com"); - Map data = new HashMap<>(); + Map data = new HashMap<>(); data.put("documentType", "abc"); data.put("content", null); document.put("params", data); @@ -744,7 +746,7 @@ public class MappingElasticsearchConverterUnitTests { @Test // DATAES-795 void readGenericMapWithSimpleTypes() { - Map mapWithSimpleValues = new HashMap<>(); + Map mapWithSimpleValues = new HashMap<>(); mapWithSimpleValues.put("int", 1); mapWithSimpleValues.put("string", "string"); mapWithSimpleValues.put("boolean", true); @@ -758,13 +760,13 @@ public class MappingElasticsearchConverterUnitTests { @Test // DATAES-797 void readGenericListWithMaps() { - Map simpleMap = new HashMap<>(); + Map simpleMap = new HashMap<>(); simpleMap.put("int", 1); - List> listWithSimpleMap = new ArrayList<>(); + List> listWithSimpleMap = new ArrayList<>(); listWithSimpleMap.add(simpleMap); - Map>> mapWithSimpleList = new HashMap<>(); + Map>> mapWithSimpleList = new HashMap<>(); mapWithSimpleList.put("someKey", listWithSimpleMap); Document document = Document.create(); @@ -870,7 +872,7 @@ public class MappingElasticsearchConverterUnitTests { @Test // DATAES-865 void shouldWriteEntityWithMapAsObject() throws JSONException { - Map map = new LinkedHashMap<>(); + Map map = new LinkedHashMap<>(); map.put("foo", "bar"); EntityWithObject entity = new EntityWithObject(); @@ -919,7 +921,7 @@ public class MappingElasticsearchConverterUnitTests { void shouldWriteMapContainingCollectionContainingMap() throws JSONException { class EntityWithMapCollectionMap { - Map map = Map.of(); + Map map = new LinkedHashMap(); } class InnerEntity { @Nullable String prop1; @@ -1801,7 +1803,7 @@ public class MappingElasticsearchConverterUnitTests { var entity = mappingElasticsearchConverter.read(EntityWithCollections.class, source); assertThat(entity.getChildrenSet()).hasSize(2); - List names = entity.getChildrenSet().stream().map(EntityWithCollections.Child::getName) + List<@Nullable String> names = entity.getChildrenSet().stream().map(EntityWithCollections.Child::getName) .collect(Collectors.toList()); assertThat(names).containsExactlyInAnyOrder("child1", "child2"); } @@ -1825,12 +1827,17 @@ public class MappingElasticsearchConverterUnitTests { @Test void shouldPopulateScriptedFields() { + Map> fields = new LinkedHashMap<>(); + var scriptedFieldList = new ArrayList<@Nullable Object>(); + scriptedFieldList.add("scriptedField"); + fields.put("scriptedField", scriptedFieldList); + var customScriptedFieldList = new ArrayList<@Nullable Object>(); + customScriptedFieldList.add("custom-name-scripted-field"); + fields.put("custom-name-scripted-field", customScriptedFieldList); SearchDocumentAdapter document = new SearchDocumentAdapter(Document.create(), 0.0f, new Object[] {}, - Map.of( - "scriptedField", List.of("scriptedField"), - "custom-name-scripted-field", List.of("custom-name-scripted-field")), + fields, emptyMap(), emptyMap(), null, @@ -1869,7 +1876,7 @@ public class MappingElasticsearchConverterUnitTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (o == null || getClass() != o.getClass()) return false; ScriptedEntity that = (ScriptedEntity) o; @@ -2022,7 +2029,7 @@ public class MappingElasticsearchConverterUnitTests { var entity = mappingElasticsearchConverter.read(ImmutableEntityWithCollections.class, source); assertThat(entity.getChildrenSet()).hasSize(2); - List names = entity.getChildrenSet().stream().map(ImmutableEntityWithCollections.Child::getName) + List<@Nullable String> names = entity.getChildrenSet().stream().map(ImmutableEntityWithCollections.Child::getName) .collect(Collectors.toList()); assertThat(names).containsExactlyInAnyOrder("child1", "child2"); } @@ -2336,7 +2343,7 @@ public class MappingElasticsearchConverterUnitTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -2474,7 +2481,7 @@ public class MappingElasticsearchConverterUnitTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof Address address)) @@ -2509,7 +2516,7 @@ public class MappingElasticsearchConverterUnitTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof Place place)) @@ -2527,7 +2534,7 @@ public class MappingElasticsearchConverterUnitTests { static class Skynet { @Nullable private Object object; @Nullable private List objectList; - @Nullable private Map objectMap; + @Nullable private Map objectMap; @Nullable public Object getObject() { @@ -2548,11 +2555,11 @@ public class MappingElasticsearchConverterUnitTests { } @Nullable - public Map getObjectMap() { + public Map getObjectMap() { return objectMap; } - public void setObjectMap(@Nullable Map objectMap) { + public void setObjectMap(@Nullable Map objectMap) { this.objectMap = objectMap; } } @@ -2561,7 +2568,7 @@ public class MappingElasticsearchConverterUnitTests { @Nullable private Long id; @Nullable private String fromEmail; @Nullable private String toEmail; - @Nullable private Map params; + @Nullable private Map params; @Nullable public Long getId() { @@ -2591,22 +2598,22 @@ public class MappingElasticsearchConverterUnitTests { } @Nullable - public Map getParams() { + public Map getParams() { return params; } - public void setParams(@Nullable Map params) { + public void setParams(@Nullable Map params) { this.params = params; } } @WritingConverter - static class ShotGunToMapConverter implements Converter> { + static class ShotGunToMapConverter implements Converter> { @Override - public Map convert(ShotGun source) { + public Map convert(ShotGun source) { - LinkedHashMap target = new LinkedHashMap<>(); + LinkedHashMap target = new LinkedHashMap<>(); target.put("model", source.label()); target.put("_class", ShotGun.class.getName()); return target; @@ -2614,10 +2621,10 @@ public class MappingElasticsearchConverterUnitTests { } @ReadingConverter - static class MapToShotGunConverter implements Converter, ShotGun> { + static class MapToShotGunConverter implements Converter, ShotGun> { @Override - public ShotGun convert(Map source) { + public ShotGun convert(Map source) { return new ShotGun(source.get("model").toString()); } } @@ -2734,14 +2741,14 @@ public class MappingElasticsearchConverterUnitTests { } static class SchemaLessObjectWrapper { - @Nullable private Map schemaLessObject; + @Nullable private Map schemaLessObject; @Nullable - public Map getSchemaLessObject() { + public Map getSchemaLessObject() { return schemaLessObject; } - public void setSchemaLessObject(@Nullable Map schemaLessObject) { + public void setSchemaLessObject(@Nullable Map schemaLessObject) { this.schemaLessObject = schemaLessObject; } } @@ -2764,7 +2771,7 @@ public class MappingElasticsearchConverterUnitTests { static class EntityWithListProperty { @Nullable @Id private String id; - @Nullable private List values; + private @Nullable List<@Nullable String> values; @Nullable public String getId() { @@ -2776,11 +2783,11 @@ public class MappingElasticsearchConverterUnitTests { } @Nullable - public List getValues() { + public List<@Nullable String> getValues() { return values; } - public void setValues(@Nullable List values) { + public void setValues(@Nullable List<@Nullable String> values) { this.values = values; } } @@ -3322,6 +3329,7 @@ public class MappingElasticsearchConverterUnitTests { this.keyWord = keyWord; } } + } // endregion diff --git a/src/test/java/org/springframework/data/elasticsearch/core/convert/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/convert/package-info.java new file mode 100644 index 000000000..828d7bd33 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/convert/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.convert; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/event/AuditingEntityCallbackTests.java b/src/test/java/org/springframework/data/elasticsearch/core/event/AuditingEntityCallbackTests.java index b07fdaa4c..b31690280 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/event/AuditingEntityCallbackTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/event/AuditingEntityCallbackTests.java @@ -56,6 +56,7 @@ class AuditingEntityCallbackTests { @Test // DATAES-68 void shouldThrowExceptionOnNullFactory() { + // noinspection DataFlowIssue assertThatIllegalArgumentException().isThrownBy(() -> new AuditingEntityCallback(null)); } @@ -135,7 +136,7 @@ class AuditingEntityCallbackTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/test/java/org/springframework/data/elasticsearch/core/event/CallbackIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/event/CallbackIntegrationTests.java index aa5266152..d01fd9192 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/event/CallbackIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/event/CallbackIntegrationTests.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.*; import java.util.Collections; import java.util.List; +import java.util.Objects; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; @@ -131,11 +132,13 @@ abstract class CallbackIntegrationTests { final IndexQuery capturedIndexQuery = indexQueryCaptor.getValue(); SampleEntity convertedEntity = (SampleEntity) capturedIndexQuery.getObject(); + assertThat(convertedEntity).isNotNull(); final JoinField joinField = convertedEntity.getJoinField(); + assertThat(joinField).isNotNull(); assertThat(joinField.getName()).isEqualTo("answer"); assertThat(joinField.getParent()).isEqualTo("42"); assertThat(capturedIndexQuery.getRouting()).isEqualTo("42"); - assertThat(capturedIndexQuery.getSeqNo()).isEqualTo(seqNoPrimaryTerm.sequenceNumber()); + assertThat(capturedIndexQuery.getSeqNo()).isEqualTo(Objects.requireNonNull(seqNoPrimaryTerm).sequenceNumber()); assertThat(capturedIndexQuery.getPrimaryTerm()).isEqualTo(seqNoPrimaryTerm.primaryTerm()); } @@ -152,12 +155,13 @@ abstract class CallbackIntegrationTests { final IndexQuery capturedIndexQuery = indexQueryCaptor.getValue(); SampleEntity convertedEntity = (SampleEntity) capturedIndexQuery.getObject(); - + assertThat(convertedEntity).isNotNull(); final JoinField joinField = convertedEntity.getJoinField(); + assertThat(joinField).isNotNull(); assertThat(joinField.getName()).isEqualTo("answer"); assertThat(joinField.getParent()).isEqualTo("42"); assertThat(capturedIndexQuery.getRouting()).isEqualTo("42"); - assertThat(capturedIndexQuery.getSeqNo()).isEqualTo(seqNoPrimaryTerm.sequenceNumber()); + assertThat(capturedIndexQuery.getSeqNo()).isEqualTo(Objects.requireNonNull(seqNoPrimaryTerm).sequenceNumber()); assertThat(capturedIndexQuery.getPrimaryTerm()).isEqualTo(seqNoPrimaryTerm.primaryTerm()); } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/event/ReactiveAuditingEntityCallbackTests.java b/src/test/java/org/springframework/data/elasticsearch/core/event/ReactiveAuditingEntityCallbackTests.java index 07f8f61fa..2b408571f 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/event/ReactiveAuditingEntityCallbackTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/event/ReactiveAuditingEntityCallbackTests.java @@ -137,7 +137,7 @@ class ReactiveAuditingEntityCallbackTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/test/java/org/springframework/data/elasticsearch/core/event/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/event/package-info.java new file mode 100644 index 000000000..0c762df1e --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/event/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.event; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/geo/GeoJsonEntity.java b/src/test/java/org/springframework/data/elasticsearch/core/geo/GeoJsonEntity.java index 41b8c6181..7087e33fe 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/geo/GeoJsonEntity.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/geo/GeoJsonEntity.java @@ -17,7 +17,6 @@ package org.springframework.data.elasticsearch.core.geo; import java.util.Objects; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.annotations.Document; @@ -31,31 +30,31 @@ public class GeoJsonEntity { @Nullable @Id private String id; @Nullable private GeoJsonPoint point1; - @Nullable private GeoJson> point2; + @Nullable private GeoJson> point2; @Nullable private GeoJsonMultiPoint multiPoint1; - @Nullable private GeoJson<@NonNull Iterable> multiPoint2; + @Nullable private GeoJson> multiPoint2; @Nullable private GeoJsonLineString lineString1; - @Nullable private GeoJson<@NonNull Iterable> lineString2; + @Nullable private GeoJson> lineString2; @Nullable private GeoJsonMultiLineString multiLineString1; - @Nullable private GeoJson<@NonNull Iterable> multiLineString2; + @Nullable private GeoJson> multiLineString2; @Nullable private GeoJsonPolygon polygon1; - @Nullable private GeoJson<@NonNull Iterable> polygon2; + @Nullable private GeoJson> polygon2; @Nullable private GeoJsonMultiPolygon multiPolygon1; - @Nullable private GeoJson<@NonNull Iterable> multiPolygon2; + @Nullable private GeoJson> multiPolygon2; @Nullable private GeoJsonGeometryCollection geometryCollection1; - @Nullable private GeoJson<@NonNull Iterable>> geometryCollection2; + @Nullable private GeoJson>> geometryCollection2; public GeoJsonEntity() {} public GeoJsonEntity(@Nullable String id, @Nullable GeoJsonPoint point1, - @Nullable GeoJson> point2, @Nullable GeoJsonMultiPoint multiPoint1, - @Nullable GeoJson<@NonNull Iterable> multiPoint2, @Nullable GeoJsonLineString lineString1, - @Nullable GeoJson<@NonNull Iterable> lineString2, @Nullable GeoJsonMultiLineString multiLineString1, - @Nullable GeoJson<@NonNull Iterable> multiLineString2, @Nullable GeoJsonPolygon polygon1, - @Nullable GeoJson<@NonNull Iterable> polygon2, @Nullable GeoJsonMultiPolygon multiPolygon1, - @Nullable GeoJson<@NonNull Iterable> multiPolygon2, - @Nullable GeoJsonGeometryCollection geometryCollection1, - @Nullable GeoJson<@NonNull Iterable>> geometryCollection2) { + @Nullable GeoJson> point2, @Nullable GeoJsonMultiPoint multiPoint1, + @Nullable GeoJson> multiPoint2, @Nullable GeoJsonLineString lineString1, + @Nullable GeoJson> lineString2, @Nullable GeoJsonMultiLineString multiLineString1, + @Nullable GeoJson> multiLineString2, @Nullable GeoJsonPolygon polygon1, + @Nullable GeoJson> polygon2, @Nullable GeoJsonMultiPolygon multiPolygon1, + @Nullable GeoJson> multiPolygon2, + @Nullable GeoJsonGeometryCollection geometryCollection1, + @Nullable GeoJson>> geometryCollection2) { this.id = id; this.point1 = point1; this.point2 = point2; @@ -92,11 +91,11 @@ public class GeoJsonEntity { } @Nullable - public GeoJson> getPoint2() { + public GeoJson> getPoint2() { return point2; } - public void setPoint2(@Nullable GeoJson> point2) { + public void setPoint2(@Nullable GeoJson> point2) { this.point2 = point2; } @@ -110,11 +109,11 @@ public class GeoJsonEntity { } @Nullable - public GeoJson<@NonNull Iterable> getMultiPoint2() { + public GeoJson> getMultiPoint2() { return multiPoint2; } - public void setMultiPoint2(@Nullable GeoJson<@NonNull Iterable> multiPoint2) { + public void setMultiPoint2(@Nullable GeoJson> multiPoint2) { this.multiPoint2 = multiPoint2; } @@ -128,11 +127,11 @@ public class GeoJsonEntity { } @Nullable - public GeoJson<@NonNull Iterable> getLineString2() { + public GeoJson> getLineString2() { return lineString2; } - public void setLineString2(@Nullable GeoJson<@NonNull Iterable> lineString2) { + public void setLineString2(@Nullable GeoJson> lineString2) { this.lineString2 = lineString2; } @@ -146,11 +145,11 @@ public class GeoJsonEntity { } @Nullable - public GeoJson<@NonNull Iterable> getMultiLineString2() { + public GeoJson> getMultiLineString2() { return multiLineString2; } - public void setMultiLineString2(@Nullable GeoJson<@NonNull Iterable> multiLineString2) { + public void setMultiLineString2(@Nullable GeoJson> multiLineString2) { this.multiLineString2 = multiLineString2; } @@ -164,11 +163,11 @@ public class GeoJsonEntity { } @Nullable - public GeoJson<@NonNull Iterable> getPolygon2() { + public GeoJson> getPolygon2() { return polygon2; } - public void setPolygon2(@Nullable GeoJson<@NonNull Iterable> polygon2) { + public void setPolygon2(@Nullable GeoJson> polygon2) { this.polygon2 = polygon2; } @@ -182,11 +181,11 @@ public class GeoJsonEntity { } @Nullable - public GeoJson<@NonNull Iterable> getMultiPolygon2() { + public GeoJson> getMultiPolygon2() { return multiPolygon2; } - public void setMultiPolygon2(@Nullable GeoJson<@NonNull Iterable> multiPolygon2) { + public void setMultiPolygon2(@Nullable GeoJson> multiPolygon2) { this.multiPolygon2 = multiPolygon2; } @@ -200,16 +199,16 @@ public class GeoJsonEntity { } @Nullable - public GeoJson<@NonNull Iterable>> getGeometryCollection2() { + public GeoJson>> getGeometryCollection2() { return geometryCollection2; } - public void setGeometryCollection2(@Nullable GeoJson<@NonNull Iterable>> geometryCollection2) { + public void setGeometryCollection2(@Nullable GeoJson>> geometryCollection2) { this.geometryCollection2 = geometryCollection2; } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof GeoJsonEntity that)) diff --git a/src/test/java/org/springframework/data/elasticsearch/core/geo/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/geo/package-info.java new file mode 100644 index 000000000..45ca34e66 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/geo/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.geo; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/index/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/index/package-info.java new file mode 100644 index 000000000..b76bec24a --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/index/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.index; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/mapping/EntityCustomConversionIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/mapping/EntityCustomConversionIntegrationTests.java index 2ff388dfe..4bf731cfc 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/mapping/EntityCustomConversionIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/mapping/EntityCustomConversionIntegrationTests.java @@ -127,7 +127,7 @@ public abstract class EntityCustomConversionIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof Entity entity)) diff --git a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java index 676ee81f2..33a967e9f 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java @@ -19,13 +19,11 @@ import static org.assertj.core.api.Assertions.*; import static org.skyscreamer.jsonassert.JSONAssert.*; import org.json.JSONException; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -68,9 +66,9 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase @Test public void shouldThrowExceptionGivenVersionPropertyIsNotLong() { - TypeInformation<@NonNull EntityWithWrongVersionType> typeInformation = TypeInformation + TypeInformation typeInformation = TypeInformation .of(EntityWithWrongVersionType.class); - SimpleElasticsearchPersistentEntity<@NonNull EntityWithWrongVersionType> entity = new SimpleElasticsearchPersistentEntity<>( + SimpleElasticsearchPersistentEntity entity = new SimpleElasticsearchPersistentEntity<>( typeInformation, contextConfiguration); assertThatThrownBy(() -> createProperty(entity, "version")).isInstanceOf(MappingException.class); @@ -79,9 +77,9 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase @Test public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent() { - TypeInformation<@NonNull EntityWithMultipleVersionField> typeInformation = TypeInformation + TypeInformation typeInformation = TypeInformation .of(EntityWithMultipleVersionField.class); - SimpleElasticsearchPersistentEntity<@NonNull EntityWithMultipleVersionField> entity = new SimpleElasticsearchPersistentEntity<>( + SimpleElasticsearchPersistentEntity entity = new SimpleElasticsearchPersistentEntity<>( typeInformation, contextConfiguration); SimpleElasticsearchPersistentProperty persistentProperty1 = createProperty(entity, "version1"); SimpleElasticsearchPersistentProperty persistentProperty2 = createProperty(entity, "version2"); @@ -108,9 +106,9 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase @Test // DATAES-799 void shouldReportThatThereIsNoSeqNoPrimaryTermPropertyWhenThereIsNoSuchProperty() { - TypeInformation<@NonNull EntityWithoutSeqNoPrimaryTerm> typeInformation = TypeInformation + TypeInformation typeInformation = TypeInformation .of(EntityWithoutSeqNoPrimaryTerm.class); - SimpleElasticsearchPersistentEntity<@NonNull EntityWithoutSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>( + SimpleElasticsearchPersistentEntity entity = new SimpleElasticsearchPersistentEntity<>( typeInformation, contextConfiguration); assertThat(entity.hasSeqNoPrimaryTermProperty()).isFalse(); @@ -119,9 +117,9 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase @Test // DATAES-799 void shouldReportThatThereIsSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() { - TypeInformation<@NonNull EntityWithSeqNoPrimaryTerm> typeInformation = TypeInformation + TypeInformation typeInformation = TypeInformation .of(EntityWithSeqNoPrimaryTerm.class); - SimpleElasticsearchPersistentEntity<@NonNull EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>( + SimpleElasticsearchPersistentEntity entity = new SimpleElasticsearchPersistentEntity<>( typeInformation, contextConfiguration); entity.addPersistentProperty(createProperty(entity, "seqNoPrimaryTerm")); @@ -133,9 +131,9 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase // DATAES-799 void shouldReturnSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() { - TypeInformation<@NonNull EntityWithSeqNoPrimaryTerm> typeInformation = TypeInformation + TypeInformation typeInformation = TypeInformation .of(EntityWithSeqNoPrimaryTerm.class); - SimpleElasticsearchPersistentEntity<@NonNull EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>( + SimpleElasticsearchPersistentEntity entity = new SimpleElasticsearchPersistentEntity<>( typeInformation, contextConfiguration); entity.addPersistentProperty(createProperty(entity, "seqNoPrimaryTerm")); EntityWithSeqNoPrimaryTerm instance = new EntityWithSeqNoPrimaryTerm(); @@ -152,9 +150,9 @@ public class SimpleElasticsearchPersistentEntityTests extends MappingContextBase @Test // DATAES-799 void shouldNotAllowMoreThanOneSeqNoPrimaryTermProperties() { - TypeInformation<@NonNull EntityWithSeqNoPrimaryTerm> typeInformation = TypeInformation + TypeInformation typeInformation = TypeInformation .of(EntityWithSeqNoPrimaryTerm.class); - SimpleElasticsearchPersistentEntity<@NonNull EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>( + SimpleElasticsearchPersistentEntity entity = new SimpleElasticsearchPersistentEntity<>( typeInformation, contextConfiguration); entity.addPersistentProperty(createProperty(entity, "seqNoPrimaryTerm")); diff --git a/src/test/java/org/springframework/data/elasticsearch/core/mapping/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/mapping/package-info.java new file mode 100644 index 000000000..606ccfe24 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/mapping/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.mapping; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/package-info.java new file mode 100644 index 000000000..fb11eb508 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/paginating/ReactiveSearchAfterIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/paginating/ReactiveSearchAfterIntegrationTests.java index 00b0d20a9..175897ad1 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/paginating/ReactiveSearchAfterIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/paginating/ReactiveSearchAfterIntegrationTests.java @@ -132,7 +132,7 @@ public abstract class ReactiveSearchAfterIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof Entity entity)) diff --git a/src/test/java/org/springframework/data/elasticsearch/core/paginating/SearchAfterIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/paginating/SearchAfterIntegrationTests.java index 763ce6164..68acbd4c1 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/paginating/SearchAfterIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/paginating/SearchAfterIntegrationTests.java @@ -192,7 +192,7 @@ public abstract class SearchAfterIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/test/java/org/springframework/data/elasticsearch/core/paginating/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/paginating/package-info.java index d82a51c47..dde4e4d74 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/paginating/package-info.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/paginating/package-info.java @@ -1,5 +1,18 @@ -/** - * Test for paginating support with search_after and point_in_time API +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.core.paginating; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/query/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/query/package-info.java new file mode 100644 index 000000000..e2e5d6cc6 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/query/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.query; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/routing/ReactiveRoutingTests.java b/src/test/java/org/springframework/data/elasticsearch/core/routing/ReactiveRoutingTests.java index f80111f8d..16a521a24 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/routing/ReactiveRoutingTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/routing/ReactiveRoutingTests.java @@ -152,7 +152,7 @@ public abstract class ReactiveRoutingTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof RoutingEntity that)) diff --git a/src/test/java/org/springframework/data/elasticsearch/core/routing/RoutingIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/routing/RoutingIntegrationTests.java index 901af03ca..cebdbcb6a 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/routing/RoutingIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/routing/RoutingIntegrationTests.java @@ -212,7 +212,7 @@ public abstract class RoutingIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof RoutingEntity that)) diff --git a/src/test/java/org/springframework/data/elasticsearch/core/routing/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/routing/package-info.java new file mode 100644 index 000000000..736765a48 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/routing/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.routing; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/sql/ReactiveSqlOperationsIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/sql/ReactiveSqlOperationsIntegrationTests.java index df4793178..449cda0f2 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/sql/ReactiveSqlOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/sql/ReactiveSqlOperationsIntegrationTests.java @@ -21,7 +21,6 @@ import reactor.test.StepVerifier; import java.util.List; -import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -93,7 +92,6 @@ public class ReactiveSqlOperationsIntegrationTests { this.views = builder.views; } - @Nullable public String getId() { return id; } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/sql/SqlOperationsIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/sql/SqlOperationsIntegrationTests.java index 6153402fa..6e571f21d 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/sql/SqlOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/sql/SqlOperationsIntegrationTests.java @@ -109,7 +109,6 @@ class SqlOperationsIntegrationTests { this.views = builder.views; } - @Nullable public String getId() { return id; } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/sql/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/sql/package-info.java new file mode 100644 index 000000000..ff7d46416 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/sql/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.sql; diff --git a/src/test/java/org/springframework/data/elasticsearch/core/suggest/package-info.java b/src/test/java/org/springframework/data/elasticsearch/core/suggest/package-info.java new file mode 100644 index 000000000..62bd1d474 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/core/suggest/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.core.suggest; diff --git a/src/test/java/org/springframework/data/elasticsearch/immutable/package-info.java b/src/test/java/org/springframework/data/elasticsearch/immutable/package-info.java new file mode 100644 index 000000000..2ee65107e --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/immutable/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.immutable; diff --git a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java index 40f232df8..c1086badd 100644 --- a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java +++ b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java @@ -51,7 +51,7 @@ public class ClusterConnection implements AutoCloseable { private static final String SDE_TESTCONTAINER_IMAGE_VERSION = "sde.testcontainers.image-version"; private static final int ELASTICSEARCH_DEFAULT_PORT = 9200; - private static final ThreadLocal clusterConnectionInfoThreadLocal = new ThreadLocal<>(); + private static final ThreadLocal clusterConnectionInfoThreadLocal = new ThreadLocal(); @Nullable private final ClusterConnectionInfo clusterConnectionInfo; @@ -76,6 +76,7 @@ public class ClusterConnection implements AutoCloseable { /** * @return the {@link ClusterConnectionInfo} from the ThreadLocal storage. */ + @SuppressWarnings("DataFlowIssue") // can return null when no value was set @Nullable public static ClusterConnectionInfo clusterConnectionInfo() { return clusterConnectionInfoThreadLocal.get(); diff --git a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/package-info.java b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/package-info.java index bf18bbf1e..b102b226c 100644 --- a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/package-info.java +++ b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/package-info.java @@ -1,5 +1,18 @@ -/** - * interfaces, annotations and classes related to JUnit 5 test handling. +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.junit.jupiter; diff --git a/src/test/java/org/springframework/data/elasticsearch/package-info.java b/src/test/java/org/springframework/data/elasticsearch/package-info.java new file mode 100644 index 000000000..fecc8f459 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/package-info.java @@ -0,0 +1,17 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/package-info.java index 065343171..0a2f85193 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/package-info.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/package-info.java @@ -1,2 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + @org.jspecify.annotations.NullMarked package org.springframework.data.elasticsearch.repositories.cdi; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/package-info.java new file mode 100644 index 000000000..d5b2bf2b5 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/package-info.java new file mode 100644 index 000000000..4fe7a3c22 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.complex.custommethod.manualwiring; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/package-info.java new file mode 100644 index 000000000..8b5246f90 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.complex.custommethod; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryIntegrationTests.java index 24201e6f6..446d0961e 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryIntegrationTests.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -1591,7 +1592,9 @@ public abstract class CustomMethodRepositoryIntegrationTests { repository.saveAll(entities); // when - SearchHits searchHits = repository.queryByCollectionSpEL(List.of("abc")); + Collection<@Nullable String> types = new ArrayList<>(); + types.add("abc"); + SearchHits searchHits = repository.queryByCollectionSpEL(types); assertThat(searchHits.getTotalHits()).isEqualTo(20); } @@ -1614,7 +1617,7 @@ public abstract class CustomMethodRepositoryIntegrationTests { repository.saveAll(entities); // when - SearchHits searchHits = repository.queryByCollectionSpEL(List.of()); + SearchHits searchHits = repository.queryByCollectionSpEL(new ArrayList()); assertThat(searchHits.getTotalHits()).isEqualTo(0); } @@ -1624,7 +1627,7 @@ public abstract class CustomMethodRepositoryIntegrationTests { List entities = createSampleEntities("abc", 20); repository.saveAll(entities); - List params = new ArrayList<>(); + List<@Nullable String> params = new ArrayList<>(); params.add(null); // when SearchHits searchHits = repository.queryByCollectionSpEL(params); @@ -1637,8 +1640,10 @@ public abstract class CustomMethodRepositoryIntegrationTests { List entities = createSampleEntities("abc", 20); repository.saveAll(entities); - // when - SearchHits searchHits = repository.queryByCollectionSpEL(Arrays.asList("abc", null)); + Collection<@Nullable String> types = new ArrayList(); + types.add("abc"); + types.add(null); + SearchHits searchHits = repository.queryByCollectionSpEL(types); assertThat(searchHits.getTotalHits()).isEqualTo(20); } @@ -1903,14 +1908,14 @@ public abstract class CustomMethodRepositoryIntegrationTests { void shouldBeAbleToUseCollectionInQueryAnnotatedMethod() { List entities = createSampleEntities("abc", 20); repository.saveAll(entities); - List ids = entities.stream().map(SampleEntity::getId).limit(7) // Just get subset - .collect(Collectors.toList()); + + List ids = entities.stream().map(SampleEntity::getIdNotNull).limit(7).collect(Collectors.toList()); List sampleEntities = repository.getByIds(ids); assertThat(sampleEntities).hasSize(7); - List returnedIds = sampleEntities.stream().map(SampleEntity::getId).collect(Collectors.toList()); + List returnedIds = sampleEntities.stream().map(SampleEntity::getIdNotNull).collect(Collectors.toList()); assertThat(returnedIds).containsAll(ids); } @@ -2246,7 +2251,7 @@ public abstract class CustomMethodRepositoryIntegrationTests { } } """) - SearchHits queryByCollectionSpEL(@Nullable Collection types); + SearchHits queryByCollectionSpEL(@Nullable Collection<@Nullable String> types); @Query(""" { @@ -2460,6 +2465,10 @@ public abstract class CustomMethodRepositoryIntegrationTests { return id; } + public String getIdNotNull() { + return Objects.requireNonNull(id, "id is required"); + } + public void setId(@Nullable String id) { this.id = id; } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/package-info.java new file mode 100644 index 000000000..38188c31d --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.custommethod; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryIntegrationTests.java index f2e4c647f..1a361ab02 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryIntegrationTests.java @@ -21,6 +21,7 @@ import static org.springframework.data.elasticsearch.utils.IdGenerator.*; import java.util.Arrays; import java.util.Optional; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -110,8 +111,8 @@ public abstract class DoubleIDRepositoryIntegrationTests { static class DoubleIDEntity { @Id private Double id; - private String type; - private String message; + private @Nullable String type; + private @Nullable String message; @Version private Long version; public Double getId() { @@ -122,7 +123,7 @@ public abstract class DoubleIDRepositoryIntegrationTests { this.id = id; } - public String getType() { + public @Nullable String getType() { return type; } @@ -130,7 +131,7 @@ public abstract class DoubleIDRepositoryIntegrationTests { this.type = type; } - public String getMessage() { + public @Nullable String getMessage() { return message; } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/package-info.java new file mode 100644 index 000000000..a85cc37dc --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.doubleid; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityIntegrationTests.java index b45095bf4..9dfd27d95 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityIntegrationTests.java @@ -100,7 +100,7 @@ public abstract class DynamicIndexEntityIntegrationTests { static class IndexNameProvider { - private String indexName; + private String indexName = "index-dynamic-test"; private int callsCount; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/package-info.java new file mode 100644 index 000000000..0125c796c --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.dynamicindex; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/geo/GeoRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/geo/GeoRepositoryIntegrationTests.java index 58e658966..c404e7d10 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/geo/GeoRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/geo/GeoRepositoryIntegrationTests.java @@ -29,7 +29,6 @@ import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.GeoPointField; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; -import org.springframework.data.elasticsearch.core.IndexOperations; import org.springframework.data.elasticsearch.core.geo.GeoPoint; import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest; @@ -49,7 +48,6 @@ import org.springframework.data.geo.Polygon; public abstract class GeoRepositoryIntegrationTests { @Autowired ElasticsearchOperations operations; - private IndexOperations indexOperations; @Autowired IndexNameProvider indexNameProvider; @Autowired SpringDataGeoRepository repository; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/geo/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/geo/package-info.java new file mode 100644 index 000000000..0551deb28 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/geo/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.geo; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryIntegrationTests.java index 1fe05a6ec..51134b848 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryIntegrationTests.java @@ -21,6 +21,7 @@ import static org.springframework.data.elasticsearch.utils.IdGenerator.*; import java.util.Arrays; import java.util.Optional; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -110,8 +111,8 @@ public abstract class IntegerIDRepositoryIntegrationTests { static class IntegerIDEntity { @Id private Integer id; - private String type; - private String message; + private @Nullable String type; + private @Nullable String message; @Version private Long version; public Integer getId() { @@ -122,7 +123,7 @@ public abstract class IntegerIDRepositoryIntegrationTests { this.id = id; } - public String getType() { + public @Nullable String getType() { return type; } @@ -130,7 +131,7 @@ public abstract class IntegerIDRepositoryIntegrationTests { this.type = type; } - public String getMessage() { + public @Nullable String getMessage() { return message; } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/integer/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/integer/package-info.java new file mode 100644 index 000000000..ff00f799e --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/integer/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.integer; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/knn/KnnSearchIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/knn/KnnSearchIntegrationTests.java index 9d1a68cb6..d0b2467ab 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/knn/KnnSearchIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/knn/KnnSearchIntegrationTests.java @@ -145,7 +145,7 @@ public abstract class KnnSearchIntegrationTests { @Field(type = FieldType.Dense_Vector, dims = 2, elementType = FieldElementType.FLOAT, knnIndexOptions = @KnnIndexOptions(type = KnnAlgorithmType.HNSW, m = 16, efConstruction = 100), - knnSimilarity = KnnSimilarity.COSINE) private float[] vector; + knnSimilarity = KnnSimilarity.COSINE) private float @Nullable [] vector; @Nullable public String getId() { diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/knn/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/knn/package-info.java new file mode 100644 index 000000000..71ab1a929 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/knn/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.knn; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectIntegrationTests.java index 5a574dd5f..895a61056 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectIntegrationTests.java @@ -153,10 +153,10 @@ public abstract class InnerObjectIntegrationTests { */ static class Author { - private String id; - private String name; + private @Nullable String id; + private @Nullable String name; - public String getId() { + public @Nullable String getId() { return id; } @@ -164,7 +164,7 @@ public abstract class InnerObjectIntegrationTests { this.id = id; } - public String getName() { + public @Nullable String getName() { return name; } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/package-info.java new file mode 100644 index 000000000..a319b501c --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.nestedobject; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/package-info.java new file mode 100644 index 000000000..6dd8293ed --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/setting/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/package-info.java new file mode 100644 index 000000000..cd47c5816 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.setting; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/spel/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/spel/package-info.java new file mode 100644 index 000000000..d9d08f458 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/spel/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.spel; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/synonym/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/synonym/package-info.java new file mode 100644 index 000000000..0cac28113 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/synonym/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.synonym; diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryIntegrationTests.java index f33b7e97b..2aa7855de 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryIntegrationTests.java @@ -535,10 +535,10 @@ public abstract class UUIDElasticsearchRepositoryIntegrationTests { @Nullable private String type; @Nullable @Field(type = FieldType.Text, fielddata = true) private String message; - @Nullable private int rate; + private int rate; @Nullable @ScriptedField private Long scriptedRate; - @Nullable private boolean available; + private boolean available; @Nullable private String highlightedMessage; @Nullable private GeoPoint location; @Nullable @@ -624,7 +624,7 @@ public abstract class UUIDElasticsearchRepositoryIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof SampleEntityUUIDKeyed that)) diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/package-info.java new file mode 100644 index 000000000..7d44ca20f --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repositories.uuidkeyed; diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/config/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repository/config/package-info.java new file mode 100644 index 000000000..cd26096d9 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repository/config/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repository.config; diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repository/package-info.java new file mode 100644 index 000000000..aa25e1598 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repository/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repository; diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/query/indexcoordinates/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repository/query/indexcoordinates/package-info.java new file mode 100644 index 000000000..5f5ada8f3 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repository/query/indexcoordinates/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repository.query.indexcoordinates; diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsIntegrationTests.java index 47204347c..4079a9b03 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsIntegrationTests.java @@ -129,7 +129,7 @@ abstract class QueryKeywordsIntegrationTests { @Test // DATAES-615 public void shouldSupportSortOnStandardFieldWithCriteria() { - List sortedIds = repository.findAllByNameOrderByText("Salt").stream() // + List<@Nullable String> sortedIds = repository.findAllByNameOrderByText("Salt").stream() // .map(it -> it.id).collect(Collectors.toList()); assertThat(sortedIds).containsExactly("4", "5"); @@ -138,7 +138,7 @@ abstract class QueryKeywordsIntegrationTests { @Test // DATAES-615 public void shouldSupportSortOnFieldWithCustomFieldNameWithCriteria() { - List sortedIds = repository.findAllByNameOrderBySortName("Sugar").stream() // + List<@Nullable String> sortedIds = repository.findAllByNameOrderBySortName("Sugar").stream() // .map(it -> it.id).collect(Collectors.toList()); assertThat(sortedIds).containsExactly("3", "2", "1"); @@ -146,7 +146,7 @@ abstract class QueryKeywordsIntegrationTests { @Test // DATAES-615 public void shouldSupportSortOnStandardFieldWithoutCriteria() { - List sortedIds = repository.findAllByOrderByText().stream() // + List<@Nullable String> sortedIds = repository.findAllByOrderByText().stream() // .map(it -> it.text).collect(Collectors.toList()); assertThat(sortedIds).containsExactly("Beet sugar", "Cane sugar", "Cane sugar", "Rock salt", "Sea salt", @@ -156,7 +156,7 @@ abstract class QueryKeywordsIntegrationTests { @Test // DATAES-615 public void shouldSupportSortOnFieldWithCustomFieldNameWithoutCriteria() { - List sortedIds = repository.findAllByOrderBySortName().stream() // + List<@Nullable String> sortedIds = repository.findAllByOrderBySortName().stream() // .map(it -> it.id).collect(Collectors.toList()); assertThat(sortedIds).containsExactly("5", "4", "3", "2", "1", "6", "7"); diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/package-info.java new file mode 100644 index 000000000..fb85bc05b --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repository.query.keywords; diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/query/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repository/query/package-info.java new file mode 100644 index 000000000..eb6042f72 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repository/query/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repository.query; diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/ReactiveValueConverterIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/ReactiveValueConverterIntegrationTests.java index 9527f90cf..d47624a98 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/ReactiveValueConverterIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/ReactiveValueConverterIntegrationTests.java @@ -15,7 +15,6 @@ */ package org.springframework.data.elasticsearch.repository.query.valueconverter; -import org.jspecify.annotations.NonNull; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -126,12 +125,12 @@ public abstract class ReactiveValueConverterIntegrationTests { public static final String PREFIX = "text-"; @Override - public @NonNull Object write(@NonNull Object value) { + public Object write(Object value) { return PREFIX + value.toString(); } @Override - public @NonNull Object read(@NonNull Object value) { + public Object read(Object value) { String valueString = value.toString(); diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/ValueConverterIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/ValueConverterIntegrationTests.java index 88c159a25..d0ec33cef 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/ValueConverterIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/ValueConverterIntegrationTests.java @@ -17,7 +17,6 @@ package org.springframework.data.elasticsearch.repository.query.valueconverter; import static org.assertj.core.api.Assertions.*; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -122,12 +121,12 @@ abstract class ValueConverterIntegrationTests { public static final String PREFIX = "text-"; @Override - public Object write(@NonNull Object value) { + public Object write(Object value) { return PREFIX + value.toString(); } @Override - public Object read(@NonNull Object value) { + public Object read(Object value) { String valueString = value.toString(); diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/package-info.java new file mode 100644 index 000000000..ebaaac595 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repository/query/valueconverter/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repository.query.valueconverter; diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryIntegrationTests.java index ed0f24c96..c7650e4d8 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryIntegrationTests.java @@ -721,7 +721,7 @@ abstract class ElasticsearchRepositoryIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepositoryIntegrationTests.java index 58c51d68e..0c54509f9 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepositoryIntegrationTests.java @@ -325,7 +325,10 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests { new SampleEntity("id-three", "message")) // .block(); - repository.queryByCollectionSpEL(List.of("message")) + List<@Nullable String> params = new ArrayList<>(); + params.add("message"); + + repository.queryByCollectionSpEL(params) .as(StepVerifier::create) // .expectNextMatches(searchHit -> SearchHit.class.isAssignableFrom(searchHit.getClass()))// .expectNextCount(2) // @@ -353,7 +356,9 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests { new SampleEntity("id-three", "message")) // .block(); - repository.queryByCollectionSpEL(List.of()) + List<@Nullable String> params = new ArrayList<>(); + + repository.queryByCollectionSpEL(params) .as(StepVerifier::create) // .expectNextCount(0) // .verifyComplete(); @@ -366,7 +371,7 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests { new SampleEntity("id-three", "message")) // .block(); - List params = new ArrayList<>(); + List<@Nullable String> params = new ArrayList<>(); params.add(null); repository.queryByCollectionSpEL(params) @@ -382,7 +387,10 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests { new SampleEntity("id-three", "message")) // .block(); - repository.queryByCollectionSpEL(Arrays.asList("message", null)) + Collection<@Nullable String> messages = new ArrayList<>(); + messages.add("message"); + messages.add(null); + repository.queryByCollectionSpEL(messages) .as(StepVerifier::create) // .expectNextMatches(searchHit -> SearchHit.class.isAssignableFrom(searchHit.getClass()))// .expectNextCount(2) // @@ -650,9 +658,14 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests { bulkIndex(new SampleEntity("id-one"), toBeDeleted) // .block(); - repository.deleteAllById(Collections.singletonList(toBeDeleted.getId())).as(StepVerifier::create).verifyComplete(); + var toBeDeletedId = toBeDeleted.getId(); + assertThat(toBeDeletedId).isNotNull(); - assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse(); + repository.deleteAllById(Collections.singletonList(toBeDeletedId)) + .as(StepVerifier::create) + .verifyComplete(); + + assertThat(documentWithIdExistsInIndex(toBeDeletedId).block()).isFalse(); } @Test // DATAES-519 @@ -664,7 +677,9 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests { repository.delete(toBeDeleted).as(StepVerifier::create).verifyComplete(); - assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse(); + var id = toBeDeleted.getId(); + assertThat(id).isNotNull(); + assertThat(documentWithIdExistsInIndex(id).block()).isFalse(); } @Test // DATAES-519 @@ -1202,7 +1217,7 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests { } } """) - Flux> queryByCollectionSpEL(@Nullable Collection messages); + Flux> queryByCollectionSpEL(@Nullable Collection<@Nullable String> messages); @Query(""" { @@ -1294,9 +1309,8 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests { @Field(type = FieldType.Text, store = true, fielddata = true) private String message; @Nullable @Field(type = FieldType.Keyword) private String keyword; - - @Nullable private int rate; - @Nullable private boolean available; + private int rate; + private boolean available; @Nullable @Version private Long version; @Field(name = "custom_field_name", type = FieldType.Text) diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/package-info.java new file mode 100644 index 000000000..7a5ae7805 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repository.support; diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/QueryByExampleElasticsearchExecutorIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/QueryByExampleElasticsearchExecutorIntegrationTests.java index 0944794bf..1bab18bc0 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/QueryByExampleElasticsearchExecutorIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/QueryByExampleElasticsearchExecutorIntegrationTests.java @@ -535,7 +535,7 @@ abstract class QueryByExampleElasticsearchExecutorIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -597,7 +597,7 @@ abstract class QueryByExampleElasticsearchExecutorIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/ReactiveQueryByExampleElasticsearchExecutorIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/ReactiveQueryByExampleElasticsearchExecutorIntegrationTests.java index 96a401545..25b33ea99 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/ReactiveQueryByExampleElasticsearchExecutorIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/ReactiveQueryByExampleElasticsearchExecutorIntegrationTests.java @@ -551,7 +551,7 @@ abstract class ReactiveQueryByExampleElasticsearchExecutorIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -613,7 +613,7 @@ abstract class ReactiveQueryByExampleElasticsearchExecutorIntegrationTests { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/package-info.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/package-info.java new file mode 100644 index 000000000..13f306560 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/querybyexample/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.repository.support.querybyexample; diff --git a/src/test/java/org/springframework/data/elasticsearch/support/package-info.java b/src/test/java/org/springframework/data/elasticsearch/support/package-info.java new file mode 100644 index 000000000..ea8a97b69 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/support/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.support; diff --git a/src/test/java/org/springframework/data/elasticsearch/utils/package-info.java b/src/test/java/org/springframework/data/elasticsearch/utils/package-info.java new file mode 100644 index 000000000..9b9650e90 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/utils/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@org.jspecify.annotations.NullMarked +package org.springframework.data.elasticsearch.utils;