Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.reflect.InvocationTargetException gets thrown when bytecode instrumentation is finished with asm.
    text
    copied!<p>I wanted to instrument some methods/classes in Java. For that purpose I wrote an Java agent that instruments only a few classes that I choose. </p> <p>I use the following code to get the loaded classes and filter some of them:</p> <pre><code> instrumentation.addTransformer(myTransformer,true); Class[] loadedClasses=instrumentation.getAllLoadedClasses(); Class[] modifiableClasses=ModifiableClasses(loadedClasses,instrumentation); Class[] filteredClasses=filterClasses(modifiableClasses); if(instrumentation.isRetransformClassesSupported()){ System.out.println("retransformation is Supported"); instrumentation.retransformClasses(filteredClasses); } </code></pre> <p>this should not create any problem filterClasses returns some classes that I want to be instrumented normally I want to instrument these Classes:</p> <ul> <li>Ljava/nio/Buffer;</li> <li>Ljava/util/HashMap$Entry;</li> <li>Ljava/nio/HeapCharBuffer;</li> <li>Ljava/nio/CharBuffer;</li> <li>Ljava/lang/ClassLoader;</li> <li>Ljava/lang/Class;</li> <li>Ljava/util/HashMap;</li> <li>Ljava/nio/ByteBuffer;</li> <li>Ljava/lang/System;</li> <li>Ljava/io/BufferedWriter;</li> <li>Ljava/lang/String;</li> <li>Ljava/io/OutputStreamWriter;</li> <li>Ljava/io/BufferedOutputStream;</li> <li>Ljava/nio/charset/CoderResult;</li> <li>Ljava/io/Writer;</li> <li>Ljava/util/HashSet;</li> <li>Ljava/nio/charset/CharsetEncoder;</li> <li>Ljava/io/FileOutputStream;</li> <li>Ljava/io/PrintStream; </li> </ul> <p>everything works fine I print the instrumented and unistrumented classes in specific folders for debug. I use the asm CoreAPI to add some instructions at the beginning and the end of methods I dont instrument Constructors,native methods, abstract methods and static variables. When I just instrument the new classes that are being loaded everything works fine. I guess I dont understand something with the ClassLoader or something specific here is what I get on the Console: </p> <pre><code> 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.InternalError at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method) at sun.instrument.InstrumentationImpl.retransformClasses(Unknown Source) at my.Agent.Watcher.premain(Watcher.java:88) ... 6 more FATAL ERROR in native method: processing of -javaagent failed </code></pre> <p>I am thankful for any help I can get even a link or a hint in the right direction. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload