RFR: 8302491: NoClassDefFoundError omits the original cause of an error

Coleen Phillimore coleenp at openjdk.org
Wed Feb 15 00:49:50 UTC 2023


On Tue, 14 Feb 2023 21:58:01 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.

This seems like a reasonable fix for this feature.

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

> 2781: }
> 2782: 
> 2783: Handle java_lang_Throwable::get_cause_simple(Handle throwable, TRAPS) {

If the function doesn't throw an exception, don't pass TRAPS.  Instead make the first argument JavaThread* current.

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

> 2798: 
> 2799:   Symbol* exception_name =  throwable()->klass()->name();
> 2800:   CLEAR_PENDING_EXCEPTION;

Is an exception possible here?  I don't see one and this should clear the exception before calling this.

src/hotspot/share/oops/instanceKlass.cpp line 987:

> 985:     // Retry with the simple method
> 986:     cause = java_lang_Throwable::get_cause_simple(exception, THREAD);
> 987:     CLEAR_PENDING_EXCEPTION;

Reverse this: clear the pending exception first.

test/hotspot/jtreg/runtime/ClassInitErrors/TestNoClassDefFoundCause.java line 26:

> 24: /**
> 25:  * @test
> 26:  * @bug 1234567

Fix the bug number.
Do you need a @requires to run with -Xcomp?

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

Changes requested by coleenp (Reviewer).

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


More information about the hotspot-dev mailing list