<AWT Dev> Proposal: Make JNU_Throw* clear a pending exception

Alan Bateman Alan.Bateman at oracle.com
Tue Feb 25 02:42:33 PST 2014

On 25/02/2014 10:31, Petr Pchelko wrote:
> Hello, Core and AWT teams.
> In AWT we have a lot of pending exception warnings which are now being fixed. A big fraction of this warnings is about a pending JNI exception at a call to JNU_Throw*.
> Why don’t we add an env->ExceptionClear() call in the beginning of each JNU_Throw function? It is absolutely safe because:
> 1. We are rethrowing an exception an loosing the original one anyway.
> 2. In case there’s no pending exception the ExceptionClear is a no-op.
> If we do this the code would become much cleaner, because currently we have to manually clear a pending exception before every call to JNU_Throw*.
> What do you think about this proposal?
I can see how this might be attractive but doesn't it mean you are 
suppressing an important exception? We've fixed many areas in the last 
few weeks and I think a common case was just that whoever wrote the 
original code didn't realize that some JNI functions having a pending 
exception when they fail. In those cases then often it is a simple 
matter of just returning from the JNI function (maybe after some 
clean-up). Are the examples that you are looking at along these lines? I 
guess I'm mostly interested to know whether the JNU_Throw usages are 
needed or not.


More information about the awt-dev mailing list