Skip to content

Commit 590453f

Browse files
committed
fixing spotbugs and adding exclusions
1 parent bb37842 commit 590453f

File tree

6 files changed

+61
-6
lines changed

6 files changed

+61
-6
lines changed

quarkus/runtime/src/main/java/io/quarkiverse/dapr/langchain4j/agent/AgentRunContext.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package io.quarkiverse.dapr.langchain4j.agent;
1515

1616
import java.lang.reflect.Method;
17+
import java.util.Arrays;
1718
import java.util.Map;
1819
import java.util.concurrent.CompletableFuture;
1920
import java.util.concurrent.ConcurrentHashMap;
@@ -32,11 +33,38 @@ public class AgentRunContext {
3233
* Holds all the information needed for {@code ToolCallActivity} to execute the tool
3334
* and unblock the waiting agent thread.
3435
*/
36+
@SuppressWarnings("EI_EXPOSE_REP")
3537
public record PendingCall(
3638
Object target,
3739
Method method,
3840
Object[] args,
3941
CompletableFuture<Object> resultFuture) {
42+
43+
/**
44+
* Creates a PendingCall with a defensive copy of args.
45+
*
46+
* @param target the object instance on which the method will be invoked
47+
* @param method the reflective method handle
48+
* @param args the arguments to pass to the method
49+
* @param resultFuture future to complete when the call finishes
50+
*/
51+
public PendingCall(Object target, Method method, Object[] args,
52+
CompletableFuture<Object> resultFuture) {
53+
this.target = target;
54+
this.method = method;
55+
this.args = args == null ? null : Arrays.copyOf(args, args.length);
56+
this.resultFuture = resultFuture;
57+
}
58+
59+
/**
60+
* Returns a defensive copy of args.
61+
*
62+
* @return copy of args array
63+
*/
64+
@Override
65+
public Object[] args() {
66+
return args == null ? null : Arrays.copyOf(args, args.length);
67+
}
4068
}
4169

4270
private final String agentRunId;

quarkus/runtime/src/main/java/io/quarkiverse/dapr/langchain4j/agent/DaprChatModelDecorator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ private String extractUserMessage(ChatRequest request) {
234234
if ("UserMessage".equals(msg.getClass().getSimpleName())) {
235235
try {
236236
return (String) msg.getClass().getMethod("singleText").invoke(msg);
237-
} catch (Exception ex) {
237+
} catch (ReflectiveOperationException ex) {
238238
return String.valueOf(msg);
239239
}
240240
}
241241
}
242-
} catch (Exception ignored) {
242+
} catch (ReflectiveOperationException ignored) {
243243
// intentionally empty
244244
}
245245
return null;
@@ -259,12 +259,12 @@ private String extractSystemMessage(ChatRequest request) {
259259
if ("SystemMessage".equals(msg.getClass().getSimpleName())) {
260260
try {
261261
return (String) msg.getClass().getMethod("text").invoke(msg);
262-
} catch (Exception ex) {
262+
} catch (ReflectiveOperationException ex) {
263263
return String.valueOf(msg);
264264
}
265265
}
266266
}
267-
} catch (Exception ignored) {
267+
} catch (ReflectiveOperationException ignored) {
268268
// intentionally empty
269269
}
270270
return null;

quarkus/runtime/src/main/java/io/quarkiverse/dapr/langchain4j/agent/activities/LlmCallActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private String extractResponseText(Object result) {
126126
Object text = aiMessage.getClass().getMethod("text").invoke(aiMessage);
127127
return String.valueOf(text);
128128
}
129-
} catch (Exception ignored) {
129+
} catch (ReflectiveOperationException ignored) {
130130
// Not a ChatResponse or missing expected methods — fall through.
131131
}
132132
return String.valueOf(result);

quarkus/runtime/src/main/java/io/quarkiverse/dapr/langchain4j/agent/workflow/AgentRunOutput.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.quarkiverse.dapr.langchain4j.agent.activities.LlmCallOutput;
1717
import io.quarkiverse.dapr.langchain4j.agent.activities.ToolCallOutput;
1818

19+
import java.util.Collections;
1920
import java.util.List;
2021

2122
/**
@@ -33,4 +34,14 @@ public record AgentRunOutput(
3334
String agentName,
3435
List<ToolCallOutput> toolCalls,
3536
List<LlmCallOutput> llmCalls) {
37+
38+
/**
39+
* Creates an AgentRunOutput with unmodifiable defensive copies of the lists.
40+
*/
41+
public AgentRunOutput(String agentName, List<ToolCallOutput> toolCalls,
42+
List<LlmCallOutput> llmCalls) {
43+
this.agentName = agentName;
44+
this.toolCalls = toolCalls == null ? null : Collections.unmodifiableList(List.copyOf(toolCalls));
45+
this.llmCalls = llmCalls == null ? null : Collections.unmodifiableList(List.copyOf(llmCalls));
46+
}
3647
}

quarkus/runtime/src/main/java/io/quarkiverse/dapr/langchain4j/workflow/DaprWorkflowPlanner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public record AgentMetadata(String agentName, String userMessage, String systemM
7272
* The {@code agentRunId} is forwarded to the planner so it can set
7373
* {@link DaprAgentContextHolder} on the executing thread before tool calls begin.
7474
*/
75+
@SuppressWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
7576
public record AgentExchange(AgentInstance agent, CompletableFuture<Void> continuation, String agentRunId) {
7677
}
7778

@@ -353,6 +354,7 @@ public AgentMetadata getAgentMetadata(int index) {
353354
*
354355
* @return the agentic scope
355356
*/
357+
@SuppressWarnings("EI_EXPOSE_REP")
356358
public AgenticScope getAgenticScope() {
357359
return agenticScope;
358360
}
@@ -436,7 +438,7 @@ public void setTestExitAtLoopEnd(boolean testExitAtLoopEnd) {
436438
* @param conditions the conditions map
437439
*/
438440
public void setConditions(Map<Integer, Predicate<AgenticScope>> conditions) {
439-
this.conditions = conditions;
441+
this.conditions = conditions == null ? Collections.emptyMap() : Map.copyOf(conditions);
440442
}
441443

442444
private void cleanup() {

spotbugs-exclude.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,18 @@
6363
<Package name="~io\.dapr.*"/>
6464
<Bug pattern="NP_UNWRITTEN_FIELD"/>
6565
</Match>
66+
67+
<!--Quarkus extension uses io.quarkiverse.dapr.* packages — apply same exclusions-->
68+
<Match>
69+
<Package name="~io\.quarkiverse\.dapr.*"/>
70+
<Bug pattern="EI_EXPOSE_REP"/>
71+
</Match>
72+
<Match>
73+
<Package name="~io\.quarkiverse\.dapr.*"/>
74+
<Bug pattern="EI_EXPOSE_REP2"/>
75+
</Match>
76+
<Match>
77+
<Package name="~io\.quarkiverse\.dapr.*"/>
78+
<Bug pattern="REC_CATCH_EXCEPTION"/>
79+
</Match>
6680
</FindBugsFilter>

0 commit comments

Comments
 (0)