Commit f0e4643
Fix GitHub issue #131: Deserialization methods throw exceptions instead of returning null
Changed package-private deserialization helper methods to throw exceptions
instead of returning null, eliminating silent failures and improving error handling.
**Changes to StringUtil.java:**
- fromStream(): Now throws NullPointerException for null input, RuntimeException for deserialization failures
- fromCompressedString(): Now throws NullPointerException for null input, RuntimeException for decompression failures
- Public methods simplified - no longer need null checks since helpers throw exceptions
**Benefits:**
- Consistent exception-based error handling
- Root cause exceptions preserved in wrapped RuntimeException
- No silent null returns that could cause NullPointerExceptions later
- Eliminates dual error handling (log+return null, then check null+throw)
- Better error messages with full stack traces
**Test updates:**
- Updated testFromStream_withNullInputStream() to expect NullPointerException
- Updated testFromCompressedStream_withNullInputStream() to expect NullPointerException
- Updated testFromStream_objectInputFilter_rejectedPath() to expect RuntimeException wrapping InvalidClassException
All 265 tests pass with 100% coverage maintained.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 71c072c commit f0e4643
2 files changed
Lines changed: 24 additions & 31 deletions
File tree
- src
- main/java/org/flossware/jcommons/util
- test/java/org/flossware/jcommons/util
Lines changed: 6 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
| 368 | + | |
373 | 369 | | |
374 | 370 | | |
375 | 371 | | |
| |||
393 | 389 | | |
394 | 390 | | |
395 | 391 | | |
| 392 | + | |
396 | 393 | | |
397 | | - | |
398 | | - | |
399 | 394 | | |
400 | 395 | | |
401 | 396 | | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
| 397 | + | |
407 | 398 | | |
408 | 399 | | |
409 | 400 | | |
410 | 401 | | |
411 | 402 | | |
| 403 | + | |
412 | 404 | | |
413 | | - | |
414 | | - | |
415 | 405 | | |
416 | 406 | | |
417 | 407 | | |
| |||
451 | 441 | | |
452 | 442 | | |
453 | 443 | | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
| 444 | + | |
459 | 445 | | |
460 | 446 | | |
461 | 447 | | |
| |||
495 | 481 | | |
496 | 482 | | |
497 | 483 | | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
| 484 | + | |
503 | 485 | | |
504 | 486 | | |
505 | 487 | | |
| |||
Lines changed: 18 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | | - | |
| 299 | + | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | | - | |
305 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
306 | 308 | | |
307 | 309 | | |
308 | 310 | | |
| |||
312 | 314 | | |
313 | 315 | | |
314 | 316 | | |
315 | | - | |
316 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
317 | 323 | | |
318 | 324 | | |
319 | 325 | | |
| |||
504 | 510 | | |
505 | 511 | | |
506 | 512 | | |
507 | | - | |
508 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
509 | 520 | | |
510 | 521 | | |
511 | 522 | | |
| |||
0 commit comments