Commit 2a3e7a5
committed
Centralize
Prompted by github-code-quality review comments on PR #185
(#185 (comment)).
The bot flagged four instances of uncaught `NumberFormatException` from
`Long.parseLong(requestId)` in the new `handleExitPlanModeRequest` and
`handleAutoModeSwitchRequest` handlers. The recommended fix was to parse
`requestId` once, catch `NumberFormatException`, and reuse the parsed `long`.
Assessment: The `NumberFormatException` comments (r3221146107, r3221146111,
r3221146120, r3221146133) are fully addressed and exceeded — the fix
applies the pattern to ALL seven handlers in the class, not just the two
new ones. A shared `parseRequestId(String, String)` utility method replaces
both the flagged inline calls and an existing ad-hoc try/catch in
`handleSystemMessageTransform`.
Two additional comments (r3221146142, r3221146149) flagged the `invocation`
parameter as unused in `AutoModeSwitchHandler` and `ExitPlanModeHandler`. These
are intentionally not addressed: the parameter is part of the consistent
two-arg handler API contract shared by all handler functional interfaces
in the SDK.
--- Per-file manifest ---
`src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java`
- Add `private static parseRequestId(String, String)` utility that wraps
`Long.parseLong` in a try/catch for `NumberFormatException`, logs on
failure, and returns `-1` as a sentinel.
- `handleToolCall`: parse `requestId` upfront via `parseRequestId`; replace
five `Long.parseLong(requestId)` call sites with `requestIdLong`.
- `handlePermissionRequest`: same pattern; replace three call sites.
- `handleUserInputRequest`: same pattern; replace three call sites.
- `handleExitPlanModeRequest`: same pattern; replace three call sites.
(Directly addresses the linked review comment.)
- `handleAutoModeSwitchRequest`: same pattern; replace three call sites.
- `handleHooksInvoke`: same pattern; replace three call sites.
- `handleSystemMessageTransform`: replace existing inline try/catch NFE
block with the shared `parseRequestId` call, removing duplicated logic.
`src/site/markdown/advanced.md`
- Add `.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)` to the
exit-plan-mode and auto-mode-switch code examples so they compile
and run without a missing-handler error.
`src/test/java/com/github/copilot/sdk/ModeHandlersTest.java`
- Parameterize `configureAuthenticatedUser(String testName)` to call
`ctx.configureForTest("mode_handlers", testName)` with per-test
snapshot names.
- `shouldInvokeAutoModeSwitchHandlerWhenRateLimited`: switch from
`sendAndWait` to `send`, add assertions on the returned `messageId`.
`src/test/java/com/github/copilot/sdk/SessionEventHandlingTest.java`
- Update `SessionStartEventData` constructor calls (arity 10 -> 11) for
new `detachedFromSpawningParentSessionId` field.
- Update `AssistantMessageEventData` constructor calls (arity 12 -> 15)
for new `anthropicAdvisorModel`, `turnId`, `parentToolCallId` fields;
adjust positional `null` arguments accordingly.
Signed-off-by: Ed Burns <edburns@microsoft.com>requestId parsing to fix NumberFormatException risks across all RPC handlers1 parent a427c7f commit 2a3e7a5
4 files changed
Lines changed: 81 additions & 38 deletions
File tree
- src
- main/java/com/github/copilot/sdk
- site/markdown
- test/java/com/github/copilot/sdk
Lines changed: 67 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
134 | 138 | | |
135 | 139 | | |
136 | 140 | | |
| |||
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
142 | | - | |
| 146 | + | |
143 | 147 | | |
144 | 148 | | |
145 | 149 | | |
146 | 150 | | |
147 | 151 | | |
148 | 152 | | |
149 | 153 | | |
150 | | - | |
| 154 | + | |
151 | 155 | | |
152 | 156 | | |
153 | 157 | | |
| |||
163 | 167 | | |
164 | 168 | | |
165 | 169 | | |
166 | | - | |
| 170 | + | |
167 | 171 | | |
168 | 172 | | |
169 | 173 | | |
| |||
172 | 176 | | |
173 | 177 | | |
174 | 178 | | |
175 | | - | |
| 179 | + | |
176 | 180 | | |
177 | 181 | | |
178 | 182 | | |
| |||
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
184 | | - | |
| 188 | + | |
185 | 189 | | |
186 | 190 | | |
187 | 191 | | |
| |||
191 | 195 | | |
192 | 196 | | |
193 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
194 | 202 | | |
195 | 203 | | |
196 | 204 | | |
| |||
199 | 207 | | |
200 | 208 | | |
201 | 209 | | |
202 | | - | |
| 210 | + | |
203 | 211 | | |
204 | 212 | | |
205 | 213 | | |
| |||
212 | 220 | | |
213 | 221 | | |
214 | 222 | | |
215 | | - | |
| 223 | + | |
216 | 224 | | |
217 | 225 | | |
218 | 226 | | |
219 | 227 | | |
220 | 228 | | |
221 | 229 | | |
222 | 230 | | |
223 | | - | |
| 231 | + | |
224 | 232 | | |
225 | 233 | | |
226 | 234 | | |
| |||
235 | 243 | | |
236 | 244 | | |
237 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
238 | 250 | | |
239 | 251 | | |
240 | 252 | | |
| |||
246 | 258 | | |
247 | 259 | | |
248 | 260 | | |
249 | | - | |
| 261 | + | |
250 | 262 | | |
251 | 263 | | |
252 | 264 | | |
| |||
268 | 280 | | |
269 | 281 | | |
270 | 282 | | |
271 | | - | |
| 283 | + | |
272 | 284 | | |
273 | 285 | | |
274 | 286 | | |
275 | 287 | | |
276 | 288 | | |
277 | 289 | | |
278 | 290 | | |
279 | | - | |
280 | | - | |
| 291 | + | |
281 | 292 | | |
282 | 293 | | |
283 | 294 | | |
| |||
291 | 302 | | |
292 | 303 | | |
293 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
294 | 309 | | |
295 | 310 | | |
296 | 311 | | |
297 | 312 | | |
298 | 313 | | |
299 | | - | |
| 314 | + | |
300 | 315 | | |
301 | 316 | | |
302 | 317 | | |
| |||
320 | 335 | | |
321 | 336 | | |
322 | 337 | | |
323 | | - | |
| 338 | + | |
324 | 339 | | |
325 | 340 | | |
326 | 341 | | |
327 | 342 | | |
328 | 343 | | |
329 | | - | |
| 344 | + | |
330 | 345 | | |
331 | 346 | | |
332 | 347 | | |
| |||
341 | 356 | | |
342 | 357 | | |
343 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
344 | 363 | | |
345 | 364 | | |
346 | 365 | | |
347 | 366 | | |
348 | 367 | | |
349 | | - | |
| 368 | + | |
350 | 369 | | |
351 | 370 | | |
352 | 371 | | |
| |||
360 | 379 | | |
361 | 380 | | |
362 | 381 | | |
363 | | - | |
| 382 | + | |
364 | 383 | | |
365 | 384 | | |
366 | 385 | | |
367 | 386 | | |
368 | 387 | | |
369 | | - | |
| 388 | + | |
370 | 389 | | |
371 | 390 | | |
372 | 391 | | |
| |||
381 | 400 | | |
382 | 401 | | |
383 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
384 | 407 | | |
385 | 408 | | |
386 | 409 | | |
387 | 410 | | |
388 | 411 | | |
389 | 412 | | |
390 | 413 | | |
391 | | - | |
| 414 | + | |
392 | 415 | | |
393 | 416 | | |
394 | 417 | | |
395 | 418 | | |
396 | 419 | | |
397 | | - | |
| 420 | + | |
398 | 421 | | |
399 | 422 | | |
400 | 423 | | |
401 | 424 | | |
402 | 425 | | |
403 | | - | |
404 | | - | |
| 426 | + | |
405 | 427 | | |
406 | 428 | | |
407 | 429 | | |
| |||
424 | 446 | | |
425 | 447 | | |
426 | 448 | | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
427 | 453 | | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | 454 | | |
437 | 455 | | |
438 | 456 | | |
| |||
462 | 480 | | |
463 | 481 | | |
464 | 482 | | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
465 | 502 | | |
466 | 503 | | |
467 | 504 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1280 | 1280 | | |
1281 | 1281 | | |
1282 | 1282 | | |
| 1283 | + | |
1283 | 1284 | | |
1284 | 1285 | | |
1285 | 1286 | | |
| |||
1308 | 1309 | | |
1309 | 1310 | | |
1310 | 1311 | | |
| 1312 | + | |
1311 | 1313 | | |
1312 | 1314 | | |
1313 | 1315 | | |
| |||
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | | - | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | | - | |
| 122 | + | |
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| |||
857 | 857 | | |
858 | 858 | | |
859 | 859 | | |
860 | | - | |
| 860 | + | |
861 | 861 | | |
862 | 862 | | |
863 | 863 | | |
864 | 864 | | |
865 | 865 | | |
866 | 866 | | |
867 | | - | |
868 | | - | |
| 867 | + | |
| 868 | + | |
869 | 869 | | |
870 | 870 | | |
871 | 871 | | |
| |||
0 commit comments