New protocol for disabling exception suppression

Rémi Forax forax at univ-mlv.fr
Sun Apr 3 02:32:15 PDT 2011


On 04/03/2011 11:31 AM, David Holmes wrote:
> Rémi Forax said the following on 04/03/11 19:09:
>> On 04/03/2011 04:28 AM, David Holmes wrote:
>>> Rémi Forax said the following on 04/03/11 11:52:
>>>> On 04/02/2011 03:21 AM, joe.darcy at oracle.com wrote:
>>>>> As part of the library support for the try-with-resources statement,
>>>>> several API changes were made to Throwable including an addSuppressed
>>>>> method to allow suppressed exceptions to be recorded. As previously
>>>>> discussed on coin-dev [1], to support VM needs for reusable exception
>>>>> objects, a protocol was devised to disable the suppression 
>>>>> mechanism so
>>>>> that a zero-length array would be returned from getSuppressed even if
>>>>> addSuppressed was called with a valid argument. The mechanism was 
>>>>> a bit
>>>>> of a kludge, relying on an initial call to addSuppressed with a null
>>>>> argument, and the design was called out as such. [2] I'm happy to 
>>>>> report
>>>>> the JSR 334 expert group has devised a more elegant protocol to 
>>>>> disable
>>>>> exception suppression: a new constructor is added to Throwable which
>>>>> supports disabling suppression. The existing constructors of 
>>>>> Throwable
>>>>> always enable suppression and addSuppressed(null) now always throws a
>>>>> NullPointerException. A few exception and error types in the platform
>>>>> are allowed by behave as if their objects were created with 
>>>>> suppression
>>>>> disabled.
>>>>>
>>>>> The fix was recently pushed [3] and will appear in a future JDK 7 
>>>>> build.
>>>>>
>>>>> -Joe
>>>>>
>>>>> [1] 
>>>>> http://mail.openjdk.java.net/pipermail/coin-dev/2010-August/002830.html 
>>>>>
>>>>> [2]
>>>>> http://mail.openjdk.java.net/pipermail/coin-dev/2010-October/thread.html#2920 
>>>>>
>>>>> [3] http://hg.openjdk.java.net/jdk7/tl/jdk/rev/856cc9e97aea
>>>>>
>>>>
>>>> So the code of the VM was changed to call the constructor if it 
>>>> exists ?
>>>
>>> No. The VM never calls a constructor it just allocates zeroed memory 
>>> - which has the same affect as calling the new constructor.
>>>
>>
>> So I don't see the improvement ?
>
> The improvement is that you no longer have the "hack" whereby calling 
> addSuppressed(null) is interpreted as meaning "disable addSuppressed". 
> Now suppression is enabled by default, unless this new constructor is 
> used, or it is a VM created exception instance which acts as-if the 
> new constructor had been used. Just makes the semantics for 
> addSuppressed cleaner and simpler.

Ok, got it. Thanks.

>
> David

Rémi




More information about the coin-dev mailing list