RFR: 8048190: NoClassDefFoundError omits original ExceptionInInitializerError [v5]
Coleen Phillimore
coleenp at openjdk.java.net
Mon Aug 9 23:18:33 UTC 2021
On Mon, 9 Aug 2021 22:13:48 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> Coleen Phillimore has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Fix java.base/bootstrap class loader comment.
>
> src/hotspot/share/classfile/javaClasses.cpp line 2694:
>
>> 2692: vmSymbols::java_lang_ExceptionInInitializerError();
>> 2693:
>> 2694: // Now create a the same exception with this stacktrace and thread name.
>
> Typo: a the
fixed.
> test/hotspot/jtreg/runtime/ClassInitErrors/InitExceptionTest.java line 43:
>
>> 41: class InitOOM {
>> 42: static {
>> 43: if (true) foo();
>
> I would just throw new OutOfmemoryError. Trying to force an actually OOME is too fragile, depends on heap size and GC etc. and we don't care that it is a real OOME.
For this test, I did want to see what happened with a real OOM and whether this condition would get an OOM when creating the stack trace. In my test, GC collects the allocated array. If the array is static, the OOM would terminate the program so it wasn't much of a test that way. I could change it back now that I wasn't able to make it get an OOM in while allocating the stack trace and new exception object.
> test/hotspot/jtreg/runtime/ClassInitErrors/InitExceptionUnloadTest.java line 53:
>
>> 51: }
>> 52: // Has to be in jasm to throw special exception in class initializer.
>> 53: // static public class ThrowsSpecialException
>
> The reason it has to be jasm is because you've made it a checked exception by extending Throwable directly. If you make it an unchecked exception (extend Error or RuntimeException) then you can use the same javac `if (true) throw` trick. Static initializers can never be declared to throw checked exceptions.
Oh, that's handy.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4996
More information about the hotspot-dev
mailing list