RFR: 8302491: NoClassDefFoundError omits the original cause of an error [v3]

Coleen Phillimore coleenp at openjdk.org
Tue Feb 21 15:09:27 UTC 2023


On Tue, 21 Feb 2023 12:12:56 GMT, Ilarion Nakonechnyy <inakonechnyy at openjdk.org> wrote:

>> The proposed approach added a new function for getting the cause of an exception -`java_lang_Throwable::get_cause_simple `, that gets called within `InstanceKlass::add_initialization_error`  if an old one `java_lang_Throwable::get_cause_with_stack_trace` didn't succeed because of an exception during the VM call. The simple function doesn't call the VM for getting a stack trace but fills in any other information about an exception.
>> 
>> Besides that, the discovering information about an exception was added to `ConstantPoolCacheEntry::save_and_throw_indy_exc` function. 
>> 
>> Jtreg for reproducing the issue also was added to the commit. 
>> The commit was tested with tier1 tests.
>
> Ilarion Nakonechnyy has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Get rid of redundant code -
>    merge get_cause_with_stack_trace and get_cause_simple
>  - Review corrections

Changes requested by coleenp (Reviewer).

src/hotspot/share/classfile/javaClasses.cpp line 2738:

> 2736: }
> 2737: 
> 2738: Handle java_lang_Throwable::get_cause(Handle throwable, bool with_stack_trace, TRAPS) {

I see, you just reversed the code so it creates the message first, then calls getStackTrace.
If you change it to not have TRAPS, and use JavaThread* current as the first parameter, then have as the first line to show that the exception isn't propagated out of this function.
JavaThread* THREAD = current;
create the message
{ call getStackTrace();
  if (PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION;
  else set_stacktrace(); clear_backtrace();
}
return h_cause;

Something like that.  Then the caller doesn't need to check for null or pending exception.

-------------

PR: https://git.openjdk.org/jdk/pull/12566


More information about the hotspot-dev mailing list