RFR JDK-8209553: ExceptionInInitializerError can have a default detail message if the cause is given

mandy chung mandy.chung at oracle.com
Thu Aug 16 00:10:22 UTC 2018



On 8/15/18 3:20 PM, Peter Levart wrote:
> Hi Mandy,
> 
> Just a question. Why does "private Throwable exception" field in 
> ExceptionInInitializerError exist? Was it there before there was a 
> "cause" in Throwable and later still remained there because of 
> serialization format? Would it be possible to "simulate" its effect for 
> serialization using "serialPersistentFields" and 
> ObjectOutputStream.PutField?

Thanks for asking.  I meant to mention this and it'd be nice to
follow up this in a separate issue.

The private exception field exists since 1.1 and kept there for
serialization.  getException in existing releases returns the
exception field.  I can't think of any way to remove the exception
field in JDK n to deserialize it with older JDK x unless JDK x was
changed to write the exception field with the cause or getException
to return cause.

I think we should remove the ExceptionInInitializerError::getCause
method and have getException to return getCause().  I think the
simplest is to keep the exception field and make sure it's set
with the cause. Existing version of EIIE always has null cause.
readObject will set the cause to be same as exception.  There may
be other options.

> The main challegne, I think, would be the deserialization of an old 
> ExceptionInInitializerError.exception into new Throwable.cause in case 
> the stream did not have Throwable.cause (which is the case for old 
> ExceptionInInitializerError(s))

Deserializing from an older EIIE to a newer EIIE is feasible.  I was
thinking to separate it as a different issue.

Mandy


More information about the core-libs-dev mailing list