Be more defensive when converting subscription id 25/115725/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 3 Mar 2025 13:05:23 +0000 (14:05 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 3 Mar 2025 13:05:58 +0000 (14:05 +0100)
Uint32.valueOf() can throw an IAE, make sure we intercept it.

JIRA: NETCONF-714
Change-Id: I49da217e3139e2ff53d620a274c81e545a807c11
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-notifications/src/main/java/org/opendaylight/restconf/notifications/SubscriptionResourceInstance.java

index 6b1da20adf88433cd73b10fbcf09270ab9467469..0af7614f9cd8d338252a1ef793de56d9065bbb76 100644 (file)
@@ -102,8 +102,15 @@ final class SubscriptionResourceInstance extends WebHostResourceInstance {
         if (!headers.contains(HttpHeaderNames.ACCEPT, HttpHeaderValues.TEXT_EVENT_STREAM, false)) {
             return new EmptyResponse(HttpResponseStatus.NOT_ACCEPTABLE);
         }
-        // FIXME: check Uin32.valueOf() exception
-        final var subscriptionState = machine.lookupSubscriptionState(Uint32.valueOf(subscriptionId));
+
+        final Uint32 id;
+        try {
+            id = Uint32.valueOf(subscriptionId);
+        } catch (IllegalArgumentException e) {
+            LOG.debug("Invalid subscription id {}", subscriptionId, e);
+            return new EmptyResponse(HttpResponseStatus.BAD_REQUEST);
+        }
+        final var subscriptionState = machine.lookupSubscriptionState(id);
         if (subscriptionState == null) {
             LOG.debug("Subscription for id {} not found", subscriptionId);
             return EmptyResponse.NOT_FOUND;
@@ -113,7 +120,7 @@ final class SubscriptionResourceInstance extends WebHostResourceInstance {
             return new EmptyResponse(HttpResponseStatus.CONFLICT);
         }
 
-        final var subscription = streamRegistry.lookupSubscription(Uint32.valueOf(subscriptionId));
+        final var subscription = streamRegistry.lookupSubscription(id);
         if (subscription == null) {
             LOG.warn("Could not send event stream response: could not read subscription");
             return EmptyResponse.NOT_FOUND;