Debug NoClassDefFoundError

Christian Beikov christian.beikov at gmail.com
Mon May 17 16:40:49 UTC 2021


Am 17.05.2021 um 18:27 schrieb Remi Forax:
> ----- Mail original -----
>> De: "Christian Beikov" <christian.beikov at gmail.com>
>> À: "hotspot-dev" <hotspot-dev at openjdk.java.net>
>> Envoyé: Lundi 17 Mai 2021 18:19:19
>> Objet: Debug NoClassDefFoundError
>> Hi,
>>
>> not sure if this is the right place to ask, so if I am wrong, please let
>> me know where to ask this.
>>
>> I have a very strange problem with a generated class defined dynamically
>> into a module through `MethodHandles.Lookup.defineClass`. When I try to
>> instantiate it, I get a `java.lang.NoClassDefFoundError: Could not
>> initialize class ...` without any further context:
>>
>>
>>      at
>> java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native
>> Method)
>>      at
>> java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>>      at
>> java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>>      at
>> java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
>>
>> Does anyone know how to further debug this? I was trying to find
>> instructions for debugging the JVM itself but couldn't so far.
> Usually is an exception inside the static block by example the block static itself not being able to load a class, that is swallowed,
> putting a giant try/catch(Throwable) around the static block may help.

I just tried throwing an exception in a static initializer and that 
looks different. In that case, I see where the exception comes from in 
the stack trace.

Pseudo-Code:

public class Test {
     public static void main(String[] args) {
         Init.b();
     }
}

class Init {
     static {
         boolean a = true;
         if (a) {
             throw new RuntimeException("Test");
         }
     }
     static void b() {}
}

Like I wrote, this is generated code. Apart from that, it works in 
classpath mode, which is why I suspect an issue in the VM and would like 
to understand what the reasons for that exception could be on the VM 
side or instructions on how to debug the VM.


More information about the hotspot-dev mailing list