Skip to content

Commit 18c7277

Browse files
authored
chore: Updating JSpecify coverage (#534)
Adding more JSpecify coverage Signed-off-by: Emmanuel Hugonnet <[email protected]>
1 parent 46b1b0a commit 18c7277

36 files changed

+335
-159
lines changed

boms/test-utils/src/main/java/io/a2a/bom/test/DynamicBomVerifier.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.regex.Matcher;
99
import java.util.regex.Pattern;
1010
import java.util.stream.Stream;
11+
import org.jspecify.annotations.Nullable;
1112

1213
/**
1314
* Base class for dynamically discovering and verifying all classes in a BOM can be loaded.
@@ -180,7 +181,7 @@ private boolean isForbidden(String relativePath) {
180181
return forbiddenPaths.stream().anyMatch(relativePath::startsWith);
181182
}
182183

183-
private static String extractClassName(Path javaFile) throws IOException {
184+
private static @Nullable String extractClassName(Path javaFile) throws IOException {
184185
// Extract simple class name from filename
185186
String fileName = javaFile.getFileName().toString();
186187
if (!fileName.endsWith(".java")) {
@@ -198,11 +199,9 @@ private static String extractClassName(Path javaFile) throws IOException {
198199
.findFirst()
199200
.orElse(null);
200201
}
201-
202202
if (packageName != null) {
203203
return packageName + "." + simpleClassName;
204204
}
205-
206205
return null;
207206
}
208207
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@NullMarked
2+
package io.a2a.bom.test;
3+
4+
import org.jspecify.annotations.NullMarked;
5+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@NullMarked
2+
package io.a2a.common;
3+
4+
import org.jspecify.annotations.NullMarked;
5+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@NullMarked
2+
package io.a2a.util;
3+
4+
import org.jspecify.annotations.NullMarked;
5+

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<error-prone.version>2.45.0</error-prone.version>
7070
<nullaway.version>0.12.14</nullaway.version>
7171
<error-prone.flag>-XDaddTypeAnnotationsToSymbol=true</error-prone.flag>
72+
<nullaway.args>-Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -Xep:RequireExplicitNullMarking:WARN -XepOpt:NullAway:ExhaustiveOverride=true -XepOpt:NullAway:OnlyNullMarked=true -XepOpt:NullAway:JSpecifyMode=true -XepExcludedPaths:.*/src/test/.* -XepDisableWarningsInGeneratedCode</nullaway.args>
7273

7374
<!-- Redirect test output to file -->
7475
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
@@ -342,7 +343,7 @@
342343
<arg>--should-stop=ifError=FLOW</arg>
343344
<arg>-parameters</arg>
344345
<arg>${error-prone.flag}</arg>
345-
<arg>-Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true -XepOpt:NullAway:JSpecifyMode=true -XepExcludedPaths:.*/src/test/.* -XepDisableWarningsInGeneratedCode</arg>
346+
<arg>${nullaway.args}</arg>
346347
</compilerArgs>
347348
<annotationProcessorPaths>
348349
<path>
@@ -554,6 +555,7 @@
554555
<error-prone.version>2.42.0</error-prone.version>
555556
<nullaway.version>0.12.10</nullaway.version>
556557
<error-prone.flag></error-prone.flag>
558+
<nullaway.args>-Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true -XepOpt:NullAway:JSpecifyMode=true -XepExcludedPaths:.*/src/test/.* -XepDisableWarningsInGeneratedCode</nullaway.args>
557559
<quarkus.jvm.args></quarkus.jvm.args>
558560
</properties>
559561
</profile>

reference/rest/src/main/java/io/a2a/server/rest/quarkus/A2AServerRoutes.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,11 @@ public boolean isAuthenticated() {
369369
}
370370

371371
@Override
372-
public @Nullable
373-
String getUsername() {
374-
if (rc.user() != null) {
372+
public String getUsername() {
373+
if (rc.user() != null && rc.user().subject() != null) {
375374
return rc.user().subject();
376375
}
377-
return null;
376+
return "";
378377
}
379378
};
380379
}

server-common/src/main/java/io/a2a/server/agentexecution/RequestContext.java

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.UUID;
77
import java.util.stream.Collectors;
88

9+
import org.jspecify.annotations.Nullable;
10+
911
import io.a2a.server.ServerCallContext;
1012
import io.a2a.spec.InvalidParamsError;
1113
import io.a2a.spec.Message;
@@ -17,20 +19,20 @@
1719

1820
public class RequestContext {
1921

20-
private MessageSendParams params;
21-
private String taskId;
22-
private String contextId;
23-
private Task task;
22+
private @Nullable MessageSendParams params;
23+
private @Nullable String taskId;
24+
private @Nullable String contextId;
25+
private @Nullable Task task;
2426
private List<Task> relatedTasks;
25-
private final ServerCallContext callContext;
27+
private final @Nullable ServerCallContext callContext;
2628

2729
public RequestContext(
28-
MessageSendParams params,
29-
String taskId,
30-
String contextId,
31-
Task task,
32-
List<Task> relatedTasks,
33-
ServerCallContext callContext) throws InvalidParamsError {
30+
@Nullable MessageSendParams params,
31+
@Nullable String taskId,
32+
@Nullable String contextId,
33+
@Nullable Task task,
34+
@Nullable List<Task> relatedTasks,
35+
@Nullable ServerCallContext callContext) throws InvalidParamsError {
3436
this.params = params;
3537
this.taskId = taskId;
3638
this.contextId = contextId;
@@ -53,35 +55,35 @@ public RequestContext(
5355
}
5456
}
5557

56-
public MessageSendParams getParams() {
58+
public @Nullable MessageSendParams getParams() {
5759
return params;
5860
}
5961

60-
public String getTaskId() {
62+
public @Nullable String getTaskId() {
6163
return taskId;
6264
}
6365

64-
public String getContextId() {
66+
public @Nullable String getContextId() {
6567
return contextId;
6668
}
6769

68-
public Task getTask() {
70+
public @Nullable Task getTask() {
6971
return task;
7072
}
7173

7274
public List<Task> getRelatedTasks() {
7375
return Collections.unmodifiableList(relatedTasks);
7476
}
7577

76-
public Message getMessage() {
78+
public @Nullable Message getMessage() {
7779
return params != null ? params.message() : null;
7880
}
7981

80-
public MessageSendConfiguration getConfiguration() {
82+
public @Nullable MessageSendConfiguration getConfiguration() {
8183
return params != null ? params.configuration() : null;
8284
}
8385

84-
public ServerCallContext getCallContext() {
86+
public @Nullable ServerCallContext getCallContext() {
8587
return callContext;
8688
}
8789

@@ -137,64 +139,64 @@ private List<String> getTextParts(List<Part<?>> parts) {
137139
}
138140

139141
public static class Builder {
140-
private MessageSendParams params;
141-
private String taskId;
142-
private String contextId;
143-
private Task task;
144-
private List<Task> relatedTasks;
145-
private ServerCallContext serverCallContext;
146-
147-
public Builder setParams(MessageSendParams params) {
142+
private @Nullable MessageSendParams params;
143+
private @Nullable String taskId;
144+
private @Nullable String contextId;
145+
private @Nullable Task task;
146+
private @Nullable List<Task> relatedTasks;
147+
private @Nullable ServerCallContext serverCallContext;
148+
149+
public Builder setParams(@Nullable MessageSendParams params) {
148150
this.params = params;
149151
return this;
150152
}
151153

152-
public Builder setTaskId(String taskId) {
154+
public Builder setTaskId(@Nullable String taskId) {
153155
this.taskId = taskId;
154156
return this;
155157
}
156158

157-
public Builder setContextId(String contextId) {
159+
public Builder setContextId(@Nullable String contextId) {
158160
this.contextId = contextId;
159161
return this;
160162
}
161163

162-
public Builder setTask(Task task) {
164+
public Builder setTask(@Nullable Task task) {
163165
this.task = task;
164166
return this;
165167
}
166168

167-
public Builder setRelatedTasks(List<Task> relatedTasks) {
169+
public Builder setRelatedTasks(@Nullable List<Task> relatedTasks) {
168170
this.relatedTasks = relatedTasks;
169171
return this;
170172
}
171173

172-
public Builder setServerCallContext(ServerCallContext serverCallContext) {
174+
public Builder setServerCallContext(@Nullable ServerCallContext serverCallContext) {
173175
this.serverCallContext = serverCallContext;
174176
return this;
175177
}
176178

177-
public MessageSendParams getParams() {
179+
public @Nullable MessageSendParams getParams() {
178180
return params;
179181
}
180182

181-
public String getTaskId() {
183+
public @Nullable String getTaskId() {
182184
return taskId;
183185
}
184186

185-
public String getContextId() {
187+
public @Nullable String getContextId() {
186188
return contextId;
187189
}
188190

189-
public Task getTask() {
191+
public @Nullable Task getTask() {
190192
return task;
191193
}
192194

193-
public List<Task> getRelatedTasks() {
195+
public @Nullable List<Task> getRelatedTasks() {
194196
return relatedTasks;
195197
}
196198

197-
public ServerCallContext getServerCallContext() {
199+
public @Nullable ServerCallContext getServerCallContext() {
198200
return serverCallContext;
199201
}
200202

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package io.a2a.server.agentexecution;
3+
4+
import org.jspecify.annotations.NullMarked;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package io.a2a.server.auth;
3+
4+
import org.jspecify.annotations.NullMarked;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package io.a2a.server.config;
3+
4+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)