Commit 1e83695
committed
[cleanup][client] PIP-478: say what the self-suppression guard actually is
The comment justified the identity guard in closeQuietly as "Identity-guarded, as try-with-resources
generates". It is not. The JLS 14.20.3.1 translation calls addSuppressed unguarded, javac's lowering
emits no identity test, and a self-suppressing resource in a try-with-resources block propagates the
same IllegalArgumentException this guard exists to prevent — confirmed by running one (it prints
"PROPAGATED: java.lang.IllegalArgumentException: Self-suppression not permitted") and by javap:
20: invokevirtual #19 // Method R.close:()V
26: astore_2
27: aload_1
28: aload_2
29: invokevirtual #22 // Method java/lang/Throwable.addSuppressed
no comparison between the two throwables.
That matters because the comment is load-bearing: it is there to stop someone deleting the guard as
redundant, and it justified it by a precedent that would not have caught the bug. The guard is
STRICTER than try-with-resources, which is both true and the useful thing to say.
Two more corrections in the same comment, from cross-review:
- "The probe path could not do this — it always mints a fresh one" was false. probe()'s own throws
are all freshly minted, but it calls TlsHandle.dispose() outside any wrapping catch, so an
unchecked throwable from dispose() propagates by identity and close() could rethrow that same
instance. The probe path is a second route to self-suppression, not an impossibility.
- The javadoc promised to attach "any close failure". It attaches any DISTINCT one; the identical
case is precisely what the guard drops.
Also records that addSuppressed validates its argument even when suppression is disabled, so the
guard is needed regardless of how the propagating throwable was constructed.
Comment-only; no behaviour change. The guard itself and
aFactoryThatFailsInitializeAndCloseWithOneExceptionKeepsTheRealFailure are untouched.1 parent c07157a commit 1e83695
1 file changed
Lines changed: 16 additions & 9 deletions
Lines changed: 16 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
645 | 645 | | |
646 | 646 | | |
647 | 647 | | |
648 | | - | |
649 | | - | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
650 | 651 | | |
651 | 652 | | |
652 | 653 | | |
| |||
655 | 656 | | |
656 | 657 | | |
657 | 658 | | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
665 | 672 | | |
666 | 673 | | |
667 | 674 | | |
| |||
0 commit comments