Skip to content

Commit 2122c65

Browse files
Fix annotation package (#3716)
Fixes #3716 Auto-cherry-pick to 1.0.x * Correct NonNull annotation package * Correct Nullable annotation package * Replace jetbrains NotNull * Update copyright headers * Add package-info Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
1 parent 5c9891c commit 2122c65

File tree

8 files changed

+49
-23
lines changed

8 files changed

+49
-23
lines changed

auto-configurations/models/spring-ai-autoconfigure-model-openai/src/main/java/org/springframework/ai/model/openai/autoconfigure/OpenAIAutoConfigurationUtil.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23-
import org.jetbrains.annotations.NotNull;
24-
23+
import org.springframework.lang.NonNull;
2524
import org.springframework.util.Assert;
2625
import org.springframework.util.CollectionUtils;
2726
import org.springframework.util.MultiValueMap;
@@ -33,7 +32,7 @@ private OpenAIAutoConfigurationUtil() {
3332
// Avoids instantiation
3433
}
3534

36-
public static @NotNull ResolvedConnectionProperties resolveConnectionProperties(
35+
public static @NonNull ResolvedConnectionProperties resolveConnectionProperties(
3736
OpenAiParentProperties commonProperties, OpenAiParentProperties modelProperties, String modelType) {
3837

3938
String baseUrl = StringUtils.hasText(modelProperties.getBaseUrl()) ? modelProperties.getBaseUrl()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2025-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@NonNullApi
18+
@NonNullFields
19+
package org.springframework.ai.model.openai.autoconfigure;
20+
21+
import org.springframework.lang.NonNullApi;
22+
import org.springframework.lang.NonNullFields;

models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
2626
import com.google.cloud.vertexai.Transport;
2727
import com.google.cloud.vertexai.VertexAI;
2828
import io.micrometer.observation.ObservationRegistry;
29-
import org.jetbrains.annotations.NotNull;
3029
import org.junit.jupiter.api.Disabled;
3130
import org.junit.jupiter.api.Test;
3231
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
@@ -56,6 +55,7 @@
5655
import org.springframework.core.convert.support.DefaultConversionService;
5756
import org.springframework.core.io.ClassPathResource;
5857
import org.springframework.core.io.Resource;
58+
import org.springframework.lang.NonNull;
5959
import org.springframework.util.MimeType;
6060
import org.springframework.util.MimeTypeUtils;
6161

@@ -130,7 +130,7 @@ void testSafetySettings() {
130130
assertThat(response.getResult().getMetadata().getFinishReason()).isEqualTo("SAFETY");
131131
}
132132

133-
@NotNull
133+
@NonNull
134134
private Prompt createPrompt(VertexAiGeminiChatOptions chatOptions) {
135135
String request = "Tell me about 3 famous pirates from the Golden Age of Piracy and why they did.";
136136
String name = "Bob";

spring-ai-model/src/main/java/org/springframework/ai/model/AbstractResponseMetadata.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,8 +21,8 @@
2121
import java.util.Set;
2222
import java.util.concurrent.ConcurrentHashMap;
2323

24-
import io.micrometer.common.lang.NonNull;
25-
import io.micrometer.common.lang.Nullable;
24+
import org.springframework.lang.NonNull;
25+
import org.springframework.lang.Nullable;
2626

2727
public class AbstractResponseMetadata {
2828

spring-ai-model/src/main/java/org/springframework/ai/model/MutableResponseMetadata.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,8 +22,8 @@
2222
import java.util.concurrent.ConcurrentHashMap;
2323
import java.util.function.Function;
2424

25-
import io.micrometer.common.lang.NonNull;
26-
import io.micrometer.common.lang.Nullable;
25+
import org.springframework.lang.NonNull;
26+
import org.springframework.lang.Nullable;
2727

2828
public class MutableResponseMetadata implements ResponseMetadata {
2929

spring-ai-model/src/main/java/org/springframework/ai/model/ResponseMetadata.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,8 @@
2020
import java.util.Set;
2121
import java.util.function.Supplier;
2222

23-
import io.micrometer.common.lang.NonNull;
24-
import io.micrometer.common.lang.Nullable;
23+
import org.springframework.lang.NonNull;
24+
import org.springframework.lang.Nullable;
2525

2626
/**
2727
* Interface representing metadata associated with an AI model's response.

spring-ai-model/src/main/java/org/springframework/ai/model/package-info.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,4 +25,9 @@
2525
*
2626
*/
2727

28+
@NonNullApi
29+
@NonNullFields
2830
package org.springframework.ai.model;
31+
32+
import org.springframework.lang.NonNullApi;
33+
import org.springframework.lang.NonNullFields;

vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/pgvector/PgVectorStoreWithChatMemoryAdvisorIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 the original author or authors.
2+
* Copyright 2023-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.util.Map;
2121
import java.util.UUID;
2222

23-
import org.jetbrains.annotations.NotNull;
2423
import org.junit.jupiter.api.DisplayName;
2524
import org.junit.jupiter.api.Test;
2625
import org.mockito.ArgumentCaptor;
@@ -45,6 +44,7 @@
4544
import org.springframework.ai.embedding.EmbeddingModel;
4645
import org.springframework.ai.vectorstore.SearchRequest;
4746
import org.springframework.jdbc.core.JdbcTemplate;
47+
import org.springframework.lang.NonNull;
4848

4949
import static org.assertj.core.api.Assertions.assertThat;
5050
import static org.mockito.ArgumentMatchers.any;
@@ -68,7 +68,7 @@ class PgVectorStoreWithChatMemoryAdvisorIT {
6868

6969
float[] embed = { 0.003961659F, -0.0073295482F, 0.02663665F };
7070

71-
private static @NotNull ChatModel chatModelAlwaysReturnsTheSameReply() {
71+
private static @NonNull ChatModel chatModelAlwaysReturnsTheSameReply() {
7272
ChatModel chatModel = mock(ChatModel.class);
7373
ArgumentCaptor<Prompt> argumentCaptor = ArgumentCaptor.forClass(Prompt.class);
7474
ChatResponse chatResponse = new ChatResponse(List.of(new Generation(new AssistantMessage("""
@@ -95,7 +95,7 @@ private static PgVectorStore createPgVectorStoreUsingTestcontainer(EmbeddingMode
9595
.build();
9696
}
9797

98-
private static @NotNull JdbcTemplate createJdbcTemplateWithConnectionToTestcontainer() {
98+
private static @NonNull JdbcTemplate createJdbcTemplateWithConnectionToTestcontainer() {
9999
PGSimpleDataSource ds = new PGSimpleDataSource();
100100
ds.setUrl("jdbc:postgresql://localhost:" + postgresContainer.getMappedPort(5432) + "/postgres");
101101
ds.setUser(postgresContainer.getUsername());
@@ -123,7 +123,7 @@ private static void verifyRequestHasBeenAdvisedWithMessagesFromVectorStore(ChatM
123123
* Create a mock ChatModel that supports streaming responses for testing.
124124
* @return A mock ChatModel that returns a predefined streaming response
125125
*/
126-
private static @NotNull ChatModel chatModelWithStreamingSupport() {
126+
private static @NonNull ChatModel chatModelWithStreamingSupport() {
127127
ChatModel chatModel = mock(ChatModel.class);
128128

129129
// Mock the regular call method
@@ -158,7 +158,7 @@ private static void verifyRequestHasBeenAdvisedWithMessagesFromVectorStore(ChatM
158158
* VectorStoreChatMemoryAdvisor.
159159
* @return A mock ChatModel that returns a problematic streaming response
160160
*/
161-
private static @NotNull ChatModel chatModelWithProblematicStreamingBehavior() {
161+
private static @NonNull ChatModel chatModelWithProblematicStreamingBehavior() {
162162
ChatModel chatModel = mock(ChatModel.class);
163163

164164
// Mock the regular call method
@@ -390,7 +390,7 @@ private Throwable getRootCause(Throwable throwable) {
390390
}
391391

392392
@SuppressWarnings("unchecked")
393-
private @NotNull EmbeddingModel embeddingNModelShouldAlwaysReturnFakedEmbed() {
393+
private @NonNull EmbeddingModel embeddingNModelShouldAlwaysReturnFakedEmbed() {
394394
EmbeddingModel embeddingModel = mock(EmbeddingModel.class);
395395

396396
Mockito.doAnswer(invocationOnMock -> List.of(this.embed, this.embed))

0 commit comments

Comments
 (0)