Skip to content

Commit c6d711a

Browse files
committed
Reactivating JSpecify
Signed-off-by: Emmanuel Hugonnet <[email protected]>
1 parent 24772ec commit c6d711a

File tree

7 files changed

+16
-23
lines changed

7 files changed

+16
-23
lines changed

http-client/src/main/java/io/a2a/client/http/A2ACardResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public AgentCard getAgentCard() throws A2AClientError, A2AClientJSONError {
135135

136136
try {
137137
io.a2a.grpc.AgentCard.Builder agentCardBuilder = io.a2a.grpc.AgentCard.newBuilder();
138-
JSONRPCUtils.parseJsonString(body, agentCardBuilder, null);
138+
JSONRPCUtils.parseJsonString(body, agentCardBuilder, "");
139139
return ProtoUtils.FromProto.agentCard(agentCardBuilder);
140140
} catch (A2AError | JsonProcessingException e) {
141141
throw new A2AClientJSONError("Could not unmarshal agent card response", e);

http-client/src/test/java/io/a2a/client/http/A2ACardResolverTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void testGetAgentCardSuccess() throws Exception {
8282

8383
private AgentCard unmarshalFrom(String body) throws JsonProcessingException {
8484
io.a2a.grpc.AgentCard.Builder agentCardBuilder = io.a2a.grpc.AgentCard.newBuilder();
85-
JSONRPCUtils.parseJsonString(body, agentCardBuilder, null);
85+
JSONRPCUtils.parseJsonString(body, agentCardBuilder, "");
8686
return ProtoUtils.FromProto.agentCard(agentCardBuilder);
8787
}
8888

internal/src/main/java/io/a2a/internal/json/IdJsonMappingException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class IdJsonMappingException extends JsonMappingException {
88
/**
99
* The JSON-RPC request ID associated with this exception.
1010
*/
11-
Object id;
11+
private Object id;
1212

1313
/**
1414
* Constructs exception with message and ID.

pom.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,8 @@
6868
<logback.version>1.5.18</logback.version>
6969
<error-prone.version>2.45.0</error-prone.version>
7070
<nullaway.version>0.12.14</nullaway.version>
71-
<!--
72-
TODO Reenable this!!!!
7371
<error-prone.flag>-XDaddTypeAnnotationsToSymbol=true</error-prone.flag>
7472
<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>
75-
-->
7673

7774
<!-- Redirect test output to file -->
7875
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
@@ -354,8 +351,6 @@ TODO Reenable this!!!!
354351
<arg>${nullaway.args}</arg>
355352
</compilerArgs>
356353
<annotationProcessorPaths>
357-
<!--
358-
TODO Reenable this!!!!!!
359354
<path>
360355
<groupId>com.google.errorprone</groupId>
361356
<artifactId>error_prone_core</artifactId>
@@ -366,7 +361,6 @@ TODO Reenable this!!!!!!
366361
<artifactId>nullaway</artifactId>
367362
<version>${nullaway.version}</version>
368363
</path>
369-
-->
370364
<path>
371365
<groupId>org.mapstruct</groupId>
372366
<artifactId>mapstruct-processor</artifactId>
@@ -567,10 +561,7 @@ TODO Reenable this!!!!!!
567561
<error-prone.version>2.42.0</error-prone.version>
568562
<nullaway.version>0.12.10</nullaway.version>
569563
<error-prone.flag></error-prone.flag>
570-
<!--
571-
TODO Reenable this!!!
572564
<nullaway.args>-Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true -XepOpt:NullAway:JSpecifyMode=true -XepExcludedPaths:.*/src/test/.* -XepDisableWarningsInGeneratedCode</nullaway.args>
573-
-->
574565
<quarkus.jvm.args></quarkus.jvm.args>
575566
</properties>
576567
</profile>

spec-grpc/src/main/java/io/a2a/grpc/utils/JSONRPCUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import static io.a2a.spec.A2AErrorCodes.UNSUPPORTED_OPERATION_ERROR_CODE;
6969

7070
import io.a2a.internal.json.JsonProcessingException;
71+
import io.a2a.util.Utils;
7172
import java.util.regex.Matcher;
7273
import java.util.regex.Pattern;
7374

@@ -176,11 +177,10 @@ public static A2ARequest<?> parseRequestBody(String body) throws JsonMappingExce
176177
Object id = getAndValidateId(jsonRpc);
177178
String method = jsonRpc.get("method").getAsString();
178179
JsonElement paramsNode = jsonRpc.get("params");
179-
180180
try {
181181
return parseMethodRequest(version, id, method, paramsNode);
182182
} catch (InvalidParamsError e) {
183-
throw new InvalidParamsJsonMappingException(e.getMessage(), id);
183+
throw new InvalidParamsJsonMappingException(Utils.defaultIfNull(e.getMessage(), "Invalid parameters"), id);
184184
}
185185
}
186186

@@ -390,7 +390,7 @@ protected static void parseRequestBody(JsonElement jsonRpc, com.google.protobuf.
390390
parseJsonString(jsonRpc.toString(), builder, id);
391391
}
392392

393-
public static void parseJsonString(String body, com.google.protobuf.Message.Builder builder, @Nullable Object id) throws JsonProcessingException {
393+
public static void parseJsonString(String body, com.google.protobuf.Message.Builder builder, Object id) throws JsonProcessingException {
394394
try {
395395
JsonFormat.parser().merge(body, builder);
396396
} catch (InvalidProtocolBufferException e) {
@@ -424,7 +424,7 @@ public static void parseJsonString(String body, com.google.protobuf.Message.Buil
424424
* @param id the request ID if it could be extracted, null otherwise
425425
* @return an appropriate JsonProcessingException subtype based on the error and ID availability
426426
*/
427-
private static JsonProcessingException convertProtoBufExceptionToJsonProcessingException(InvalidProtocolBufferException e, @Nullable Object id) {
427+
private static JsonProcessingException convertProtoBufExceptionToJsonProcessingException(InvalidProtocolBufferException e, Object id) {
428428
// Log the original exception for debugging purposes
429429
log.log(Level.FINE, "Converting protobuf parsing exception to JSON-RPC error. Request ID: {0}", id);
430430
log.log(Level.FINE, "Original proto exception details", e);
@@ -448,12 +448,12 @@ private static JsonProcessingException convertProtoBufExceptionToJsonProcessingE
448448
Matcher matcher = EXTRACT_WRONG_TYPE.matcher(message);
449449
if (matcher.matches() && matcher.group(1) != null) {
450450
// ID is null -> use empty string sentinel value (see javadoc above)
451-
return new InvalidParamsJsonMappingException(ERROR_MESSAGE.formatted(matcher.group(1)), id == null ? "" : id);
451+
return new InvalidParamsJsonMappingException(ERROR_MESSAGE.formatted(matcher.group(1)), Utils.defaultIfNull(id, ""));
452452
}
453453
matcher = EXTRACT_WRONG_VALUE.matcher(message);
454454
if (matcher.matches() && matcher.group(1) != null) {
455455
// ID is null -> use empty string sentinel value (see javadoc above)
456-
return new InvalidParamsJsonMappingException(ERROR_MESSAGE.formatted(matcher.group(1)), id == null ? "" : id);
456+
return new InvalidParamsJsonMappingException(ERROR_MESSAGE.formatted(matcher.group(1)), Utils.defaultIfNull(id, ""));
457457
}
458458

459459
// Generic error - couldn't match specific patterns

spec/src/main/java/io/a2a/util/Utils.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,8 @@ public class Utils {
5454
* @param defaultValue the default value to return if value is null
5555
* @return value if non-null, otherwise defaultValue
5656
*/
57-
public static <T> T defaultIfNull(T value, T defaultValue) {
58-
if (value == null) {
59-
return defaultValue;
60-
}
61-
return value;
57+
public static <T> T defaultIfNull(@Nullable T value, T defaultValue) {
58+
return value == null ? defaultValue : value;
6259
}
6360

6461
/**
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+

0 commit comments

Comments
 (0)