Code review request for 8012044: Give more information about self-suppression from Throwable.addSuppressed
Joe Darcy
joe.darcy at oracle.com
Fri Apr 12 17:35:40 UTC 2013
Hi Jason,
Hmm. This is the current initCause implementation from JDK 8:
public synchronized Throwable initCause(Throwable cause) {
if (this.cause != this)
throw new IllegalStateException("Can't overwrite cause");
if (cause == this)
throw new IllegalArgumentException("Self-causation not
permitted");
this.cause = cause;
return this;
}
It wouldn't be unreasonable to change the second throw to
if (cause == this)
throw new IllegalArgumentException("Self-causation not
permitted", cause);
but I think there is less motivation to do so than in the addSuppressed
case since addSuppressed gets called in compiler-generated code that
isn't visible in the original sources.
-Joe
On 04/12/2013 05:45 AM, Jason Mehrens wrote:
> Joe,
>
> Should this same logic be applied to the exceptions thrown from
> initCause? Seems like that would be consistent with this change.
>
> Jason
>
> > Date: Thu, 11 Apr 2013 18:19:30 -0700
> > From: joe.darcy at oracle.com
> > To: core-libs-dev at openjdk.java.net
> > Subject: Code review request for 8012044: Give more information
> about self-suppression from Throwable.addSuppressed
> >
> > Hello,
> >
> > Please review the patch below to address
> >
> > 8012044: Give more information about self-suppression from
> > Throwable.addSuppressed
> > http://cr.openjdk.java.net/~darcy/8012044.0/
> >
> > Thanks,
> >
> > -Joe
> >
> > diff -r 006a7a576fe9 src/share/classes/java/lang/Throwable.java
> > --- a/src/share/classes/java/lang/Throwable.java Thu Apr 11 12:22:23
> > 2013 +0900
> > +++ b/src/share/classes/java/lang/Throwable.java Thu Apr 11 18:16:38
> > 2013 -0700
> > @@ -1039,7 +1039,7 @@
> > */
> > public final synchronized void addSuppressed(Throwable exception) {
> > if (exception == this)
> > - throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
> > + throw new
> > IllegalArgumentException(SELF_SUPPRESSION_MESSAGE, exception);
> >
> > if (exception == null)
> > throw new NullPointerException(NULL_CAUSE_MESSAGE);
> > diff -r 006a7a576fe9 test/java/lang/Throwable/SuppressedExceptions.java
> > --- a/test/java/lang/Throwable/SuppressedExceptions.java Thu Apr 11
> > 12:22:23 2013 +0900
> > +++ b/test/java/lang/Throwable/SuppressedExceptions.java Thu Apr 11
> > 18:16:38 2013 -0700
> > @@ -26,7 +26,7 @@
> >
> > /*
> > * @test
> > - * @bug 6911258 6962571 6963622 6991528 7005628
> > + * @bug 6911258 6962571 6963622 6991528 7005628 8012044
> > * @summary Basic tests of suppressed exceptions
> > * @author Joseph D. Darcy
> > */
> > @@ -48,7 +48,9 @@
> > throwable.addSuppressed(throwable);
> > throw new RuntimeException("IllegalArgumentException for
> > self-suppresion not thrown.");
> > } catch (IllegalArgumentException iae) {
> > - ; // Expected
> > + // Expected to be here
> > + if (iae.getCause() != throwable)
> > + throw new RuntimeException("Bad cause after
> > self-suppresion.");
> > }
> > }
> >
> >
> > -Joe
More information about the core-libs-dev
mailing list