Skip to content

Commit c08409f

Browse files
committed
Configure ErrorProne + Nullaway
Fix various ErrorProne issues across the codebase. Signed-off-by: Eric Bottard <eric.bottard@broadcom.com>
1 parent fbd8b7f commit c08409f

File tree

24 files changed

+102
-89
lines changed

24 files changed

+102
-89
lines changed

auto-configurations/models/spring-ai-autoconfigure-model-openai/src/test/java/org/springframework/ai/model/openai/autoconfigure/tool/FunctionCallbackWithPlainFunctionBeanIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void streamFunctionCallTest() {
317317
.collect(Collectors.joining());
318318
logger.info("Response: {}", content);
319319

320-
assertThat(content).isNotEmpty().withFailMessage("Content returned from OpenAI model is empty");
320+
assertThat(content).withFailMessage("Content returned from OpenAI model is empty").isNotEmpty();
321321
assertThat(content).contains("30", "10", "15");
322322

323323
});

memory/repository/spring-ai-model-chat-memory-repository-cassandra/src/test/java/org/springframework/ai/chat/memory/repository/cassandra/CassandraChatMemoryRepositoryIT.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void ensureBeansGetsCreated() {
7373
void add_shouldInsertSingleMessage(String content, MessageType messageType) {
7474
this.contextRunner.run(context -> {
7575
var chatMemory = context.getBean(ChatMemoryRepository.class);
76-
assertThat(chatMemory instanceof CassandraChatMemoryRepository);
76+
assertThat(chatMemory).isInstanceOf(CassandraChatMemoryRepository.class);
7777
var sessionId = UUID.randomUUID().toString();
7878
var message = switch (messageType) {
7979
case ASSISTANT -> new AssistantMessage(content);
@@ -109,7 +109,7 @@ void add_shouldInsertSingleMessage(String content, MessageType messageType) {
109109
void add_shouldInsertMessages() {
110110
this.contextRunner.run(context -> {
111111
var chatMemory = context.getBean(ChatMemoryRepository.class);
112-
assertThat(chatMemory instanceof CassandraChatMemoryRepository);
112+
assertThat(chatMemory).isInstanceOf(CassandraChatMemoryRepository.class);
113113
var sessionId = UUID.randomUUID().toString();
114114
var messages = List.<Message>of(new AssistantMessage("Message from assistant"),
115115
new UserMessage("Message from user"));
@@ -147,7 +147,7 @@ void add_shouldInsertMessages() {
147147
void get_shouldReturnMessages() {
148148
this.contextRunner.run(context -> {
149149
var chatMemory = context.getBean(ChatMemoryRepository.class);
150-
assertThat(chatMemory instanceof CassandraChatMemoryRepository);
150+
assertThat(chatMemory).isInstanceOf(CassandraChatMemoryRepository.class);
151151
var sessionId = UUID.randomUUID().toString();
152152

153153
var messages = List.<Message>of(new AssistantMessage("Message from assistant 1 - " + sessionId),
@@ -174,7 +174,7 @@ void get_shouldReturnMessages() {
174174
void get_afterMultipleAdds_shouldReturnMessagesInSameOrder() {
175175
this.contextRunner.run(context -> {
176176
var chatMemory = context.getBean(ChatMemoryRepository.class);
177-
assertThat(chatMemory instanceof CassandraChatMemoryRepository);
177+
assertThat(chatMemory).isInstanceOf(CassandraChatMemoryRepository.class);
178178
var sessionId = UUID.randomUUID().toString();
179179
var userMessage = new UserMessage("Message from user - " + sessionId);
180180
var assistantMessage = new AssistantMessage("Message from assistant - " + sessionId);
@@ -200,7 +200,7 @@ void get_afterMultipleAdds_shouldReturnMessagesInSameOrder() {
200200
void clear_shouldDeleteMessages() {
201201
this.contextRunner.run(context -> {
202202
var chatMemory = context.getBean(ChatMemoryRepository.class);
203-
assertThat(chatMemory instanceof CassandraChatMemoryRepository);
203+
assertThat(chatMemory).isInstanceOf(CassandraChatMemoryRepository.class);
204204
var sessionId = UUID.randomUUID().toString();
205205

206206
var messages = List.<Message>of(new AssistantMessage("Message from assistant - " + sessionId),

memory/repository/spring-ai-model-chat-memory-repository-neo4j/src/test/java/org/springframework/ai/chat/memory/repository/neo4j/Neo4jChatMemoryRepositoryIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ void handleToolResponseMessage() {
306306
}
307307

308308
@Test
309+
@SuppressWarnings("DoubleBraceInitialization")
309310
void saveAndFindSystemMessageWithMetadata() {
310311
var conversationId = UUID.randomUUID().toString();
311312
Map<String, Object> customMetadata = Map.of("priority", "high", "source", "test");

models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicChatOptionsTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ void testCopyDoesNotShareMetadataReference() {
424424
}
425425

426426
@Test
427+
@SuppressWarnings("SelfAssertion")
427428
void testEqualsWithSelf() {
428429
AnthropicChatOptions options = AnthropicChatOptions.builder().model("test").build();
429430

models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicPromptCachingMockTest.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,9 @@ void testFourBreakpointLimitEnforcement() throws Exception {
540540
int cacheControlCount = countCacheControlOccurrences(requestBody);
541541

542542
// Verify we don't exceed Anthropic's 4-breakpoint limit
543-
assertThat(cacheControlCount).isLessThanOrEqualTo(4)
544-
.withFailMessage("Cache breakpoints should not exceed 4, but found %d", cacheControlCount);
543+
assertThat(cacheControlCount)
544+
.withFailMessage("Cache breakpoints should not exceed 4, but found %d", cacheControlCount)
545+
.isLessThanOrEqualTo(4);
545546
}
546547

547548
@Test
@@ -608,8 +609,9 @@ else if (systemNode.isTextual()) {
608609
// Simple text system message should still have cache_control applied at the
609610
// message level
610611
// Check if there's a cache_control field at the system level or in a wrapper
611-
assertThat(requestBody.toString()).contains("cache_control")
612-
.withFailMessage("SYSTEM_ONLY strategy should include cache_control in wire format");
612+
assertThat(requestBody.toString())
613+
.withFailMessage("SYSTEM_ONLY strategy should include cache_control in wire format")
614+
.contains("cache_control");
613615
}
614616
}
615617

@@ -690,8 +692,9 @@ void testComplexMultiBreakpointScenario() throws Exception {
690692

691693
// Verify proper ordering and cache control placement
692694
int cacheControlCount = countCacheControlOccurrences(requestBody);
693-
assertThat(cacheControlCount).isLessThanOrEqualTo(4)
694-
.withFailMessage("Complex scenario should not exceed 4 cache breakpoints, found %d", cacheControlCount);
695+
assertThat(cacheControlCount)
696+
.withFailMessage("Complex scenario should not exceed 4 cache breakpoints, found %d", cacheControlCount)
697+
.isLessThanOrEqualTo(4);
695698

696699
// Verify cache_control is only on the LAST blocks of each section (system, tools)
697700
// This ensures proper breakpoint placement according to Anthropic's requirements
@@ -732,9 +735,9 @@ private void verifyCacheControlPlacement(JsonNode requestBody) {
732735
if (systemNode.isArray()) {
733736
for (int i = 0; i < systemNode.size() - 1; i++) {
734737
JsonNode systemBlock = systemNode.get(i);
735-
assertThat(systemBlock.has("cache_control")).isFalse()
736-
.withFailMessage("Only the last system block should have cache_control, but block %d has it",
737-
i);
738+
assertThat(systemBlock.has("cache_control"))
739+
.withFailMessage("Only the last system block should have cache_control, but block %d has it", i)
740+
.isFalse();
738741
}
739742
}
740743
}
@@ -745,8 +748,9 @@ private void verifyCacheControlPlacement(JsonNode requestBody) {
745748
if (toolsArray.isArray()) {
746749
for (int i = 0; i < toolsArray.size() - 1; i++) {
747750
JsonNode tool = toolsArray.get(i);
748-
assertThat(tool.has("cache_control")).isFalse()
749-
.withFailMessage("Only the last tool should have cache_control, but tool %d has it", i);
751+
assertThat(tool.has("cache_control"))
752+
.withFailMessage("Only the last tool should have cache_control, but tool %d has it", i)
753+
.isFalse();
750754
}
751755
}
752756
}
@@ -767,9 +771,10 @@ private void verifyCacheControlPlacement(JsonNode requestBody) {
767771
if (i != messagesArray.size() - 2 || j != contentArray.size() - 1) {
768772
// Only the last content block of the second-to-last
769773
// message should have cache_control
770-
assertThat(contentBlock.has("cache_control")).isFalse()
774+
assertThat(contentBlock.has("cache_control"))
771775
.withFailMessage(
772-
"Unexpected cache_control placement in message %d, content block %d", i, j);
776+
"Unexpected cache_control placement in message %d, content block %d", i, j)
777+
.isFalse();
773778
}
774779
}
775780
}

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void testStreaming() {
123123
.collect(Collectors.joining());
124124
logger.info("Response: {}", content);
125125

126-
assertThat(counter.get()).isGreaterThan(8).as("More than 8 chuncks because there are 8 planets");
126+
assertThat(counter.get()).withFailMessage("More than 8 chunks because there are 8 planets").isGreaterThan(8);
127127

128128
assertThat(content).contains("Earth", "Mars", "Jupiter");
129129
}

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/function/AzureOpenAiChatModelFunctionCallIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ void streamFunctionCallTest() {
139139
.collect(Collectors.joining());
140140
logger.info("Response: {}", content);
141141

142-
assertThat(counter.get()).isGreaterThan(30).as("The response should be chunked in more than 30 messages");
142+
assertThat(counter.get()).withFailMessage("The response should be chunked in more than 30 messages")
143+
.isGreaterThan(30);
143144

144145
assertThat(content).contains("30", "10", "15");
145146

models/spring-ai-deepseek/src/test/java/org/springframework/ai/deepseek/chat/DeepSeekChatModelFunctionCallingIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,9 @@ public void toolFunctionCallWithUsage() {
155155

156156
ChatResponse chatResponse = this.chatModel.call(prompt);
157157
assertThat(chatResponse).isNotNull();
158-
assertThat(chatResponse.getResult().getOutput());
158+
assertThat(chatResponse.getResult().getOutput()).isNotNull();
159159
assertThat(chatResponse.getResult().getOutput().getText()).contains("San Francisco");
160160
assertThat(chatResponse.getResult().getOutput().getText()).contains("30");
161-
// 这个 total token 是第一次 chat 以及 tool call 之后的两次请求 token 总和
162161

163162
// the total token is first chat and tool call request
164163
assertThat(chatResponse.getMetadata().getUsage().getTotalTokens()).isLessThan(700).isGreaterThan(280);

models/spring-ai-deepseek/src/test/java/org/springframework/ai/deepseek/chat/DeepSeekChatModelIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void prefixCompletionTest() {
229229
.build();
230230
Prompt prompt = new Prompt(List.of(userMessage, assistantMessage));
231231
ChatResponse response = this.chatModel.call(prompt);
232-
assertThat(response.getResult().getOutput().getText().equals(",2,3]}}"));
232+
assertThat(response.getResult().getOutput().getText()).isEqualTo(",2,3]}}");
233233
}
234234

235235
/**

models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/GoogleGenAiChatOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ public boolean equals(Object o) {
441441
if (!(o instanceof GoogleGenAiChatOptions that)) {
442442
return false;
443443
}
444-
return this.googleSearchRetrieval == that.googleSearchRetrieval
444+
return Objects.equals(this.googleSearchRetrieval, that.googleSearchRetrieval)
445445
&& Objects.equals(this.stopSequences, that.stopSequences)
446446
&& Objects.equals(this.temperature, that.temperature) && Objects.equals(this.topP, that.topP)
447447
&& Objects.equals(this.topK, that.topK) && Objects.equals(this.candidateCount, that.candidateCount)

0 commit comments

Comments
 (0)