2013-05-15 27 views
0

我想用Java來測試一些方法/類。爲此,我編寫了一個Java代理程序,它只能處理我選擇的幾個類。當字節碼使用asm完成時,java.lang.reflect.InvocationTargetException被拋出。

我用下面的代碼來獲取加載的類和過濾其中的一些:

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); 
    } 

這不應該造成任何問題filterClasses返回一些類,我想正常儀表我要儀器這些類:

  • Ljava/nio/Buffer;
  • Ljava/util/HashMap $ Entry;
  • Ljava/nio/HeapCharBuffer;
  • Ljava/nio/CharBuffer;
  • Ljava/lang/ClassLoader;
  • Ljava/lang/Class;
  • Ljava/util/HashMap;
  • Ljava/nio/ByteBuffer;
  • Ljava/lang/System;
  • Ljava/io/BufferedWriter;
  • Ljava/lang/String;
  • Ljava/io/OutputStreamWriter;
  • Ljava/io/BufferedOutputStream;
  • Ljava/nio/charset/CoderResult;
  • Ljava/io/Writer;
  • Ljava/util/HashSet;
  • Ljava/nio/charset/CharsetEncoder;
  • Ljava/io/FileOutputStream;
  • Ljava/io/PrintStream;

一切工作正常我在特定的文件夾打印instrumented和unistrumented類進行調試。我使用asm CoreAPI在方法的開始和結尾添加一些指令,我不使用構造函數,本地方法,抽象方法和靜態變量。當我剛剛裝載正在加載的新類時,一切正常。我想我不明白用的ClassLoader或具體的東西在這裏的東西是我所得到的控制檯:

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 

我感謝所有幫助我能在正確的方向,甚至一個鏈接或提示。

回答

0

對不起,如果我想要這個工作,我會發現錯誤,我將不得不解決後,更精確地在儀器化的類看到我的錯誤。 admin/mod可以關閉這個線程。

+0

你發現了什麼錯誤? – AKS

相關問題