Skip to content

Commit 95e646e

Browse files
nficanoclaude
andcommitted
refactor(runtime): wrap malformed list_jobs cursors in a stable error
Integer.parseInt on a valid-Base64 but non-numeric cursor threw a raw NumberFormatException whose parser message was echoed to the client in INVALID_REQUEST. Both decode failures now surface as a uniform "invalid cursor" IllegalArgumentException. Addresses the code-quality review finding on decodeCursor. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent c3d7235 commit 95e646e

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

arcp-runtime/src/main/java/dev/arcp/runtime/session/JobListing.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@ private static int decodeCursor(@Nullable String cursor) {
6565
if (cursor == null || cursor.isBlank()) {
6666
return 0;
6767
}
68-
byte[] decoded = Base64.getUrlDecoder().decode(cursor);
69-
int startIndex = Integer.parseInt(new String(decoded, StandardCharsets.UTF_8));
70-
return Math.max(0, startIndex);
68+
try {
69+
byte[] decoded = Base64.getUrlDecoder().decode(cursor);
70+
return Math.max(0, Integer.parseInt(new String(decoded, StandardCharsets.UTF_8)));
71+
} catch (IllegalArgumentException e) {
72+
// Covers malformed Base64 and non-numeric content (NumberFormatException): surface a stable
73+
// message instead of the parser's, since the caller echoes it in INVALID_REQUEST.
74+
throw new IllegalArgumentException("invalid cursor", e);
75+
}
7176
}
7277

7378
private static String encodeCursor(int index) {

0 commit comments

Comments
 (0)