java.lang.reflect.InvocationTargetException

JIRA | Andres Kalle | 4 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Liquibase has some logic that deals with classloaders, but doesn't handle the case where Class.getClassLoader() returns null. From the Javadoc of getClassLoader(): "Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader." Attached is a simple Maven project to reproduce the issue. Unzip it and run mvn clean package java -javaagent:target\testagent-1.0.jar Which in my case gives this result: {noformat} Running premain Classloader of premain: null Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source) at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source) Caused by: java.lang.ExceptionInInitializerError at com.example.Premain.premain(Premain.java:13) ... 6 more Caused by: java.lang.NullPointerException at liquibase.servicelocator.WebSpherePackageScanClassResolver.isWebSphereClassLoader(WebSpherePackageScanClassResolver.java:30) at liquibase.servicelocator.ServiceLocator.defaultClassLoader(ServiceLocator.java:67) at liquibase.servicelocator.ServiceLocator.<init>(ServiceLocator.java:39) at liquibase.servicelocator.ServiceLocator.<clinit>(ServiceLocator.java:27) ... 7 more FATAL ERROR in native method: processing of -javaagent failed {noformat} WebSpherePackageScanClassResolver.isWebSphereClassLoader() is the first point of failure, but this becomes an issue elsewhere as well, for example in ClassLoaderResourceAccessor. Note: The example is based on a real case where Liquibase was executed from code that runs in a Java agent. Our current workaround is to load Liquibase in a custom classloader, but this makes the application a lot more complex.

    JIRA | 4 years ago | Andres Kalle
    java.lang.reflect.InvocationTargetException
  2. 0

    Liquibase has some logic that deals with classloaders, but doesn't handle the case where Class.getClassLoader() returns null. From the Javadoc of getClassLoader(): "Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader." Attached is a simple Maven project to reproduce the issue. Unzip it and run mvn clean package java -javaagent:target\testagent-1.0.jar Which in my case gives this result: {noformat} Running premain Classloader of premain: null Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source) at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source) Caused by: java.lang.ExceptionInInitializerError at com.example.Premain.premain(Premain.java:13) ... 6 more Caused by: java.lang.NullPointerException at liquibase.servicelocator.WebSpherePackageScanClassResolver.isWebSphereClassLoader(WebSpherePackageScanClassResolver.java:30) at liquibase.servicelocator.ServiceLocator.defaultClassLoader(ServiceLocator.java:67) at liquibase.servicelocator.ServiceLocator.<init>(ServiceLocator.java:39) at liquibase.servicelocator.ServiceLocator.<clinit>(ServiceLocator.java:27) ... 7 more FATAL ERROR in native method: processing of -javaagent failed {noformat} WebSpherePackageScanClassResolver.isWebSphereClassLoader() is the first point of failure, but this becomes an issue elsewhere as well, for example in ClassLoaderResourceAccessor. Note: The example is based on a real case where Liquibase was executed from code that runs in a Java agent. Our current workaround is to load Liquibase in a custom classloader, but this makes the application a lot more complex.

    JIRA | 4 years ago | Andres Kalle
    java.lang.reflect.InvocationTargetException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at liquibase.servicelocator.WebSpherePackageScanClassResolver.isWebSphereClassLoader()
    2. Liquibase Core
      ServiceLocator.<clinit>
      1. liquibase.servicelocator.WebSpherePackageScanClassResolver.isWebSphereClassLoader(WebSpherePackageScanClassResolver.java:30)
      2. liquibase.servicelocator.ServiceLocator.defaultClassLoader(ServiceLocator.java:67)
      3. liquibase.servicelocator.ServiceLocator.<init>(ServiceLocator.java:39)
      4. liquibase.servicelocator.ServiceLocator.<clinit>(ServiceLocator.java:27)
      4 frames
    3. com.example
      Premain.premain
      1. com.example.Premain.premain(Premain.java:13)
      1 frame
    4. Java RT
      InstrumentationImpl.loadClassAndCallPremain
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      4. java.lang.reflect.Method.invoke(Unknown Source)
      5. sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source)
      6. sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source)
      6 frames