JDK-5003341 : class redefined through Instrumentation.redefineClasses can't use native methods
  • Type: Bug
  • Component: core-svc
  • Sub-Component: tools
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2004-02-25
  • Updated: 2007-04-11
  • Resolved: 2007-04-11
Related Reports
Duplicate :  
Relates :  
Description
Name: rmT116609			Date: 02/25/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
SunOS mary 5.9 Generic_112233-10 sun4u sparc SUNW,Sun-Blade-100


A DESCRIPTION OF THE PROBLEM :
Native methods are not found for java classes that  have been redefined through java.lang.instrument.Instrumentation.redefineClass

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the given program; if you run it with
java -javaagent:MyAgent=java/lang/Thread.class MyAgent
or
java -javaagent:MyAgent=java/lang/Object.class MyAgent
you will see the exception, but no exception is thrown if you run the program with
java -javaagent:MyAgent=java/lang/String.class MyAgent
or
java -javaagent:MyAgent=java/util/ArrayList.class MyAgent

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception should be thrown
ACTUAL -
An exception is thrown about native method hat is not found.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Creating instance of class java.lang.Thread
Exception in thread "main" java.lang.UnsatisfiedLinkError: currentThread
        at java.lang.Thread.currentThread(Native Method)
        at java.lang.Thread.init(Thread.java:287)
        at java.lang.Thread.<init>(Thread.java:339)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
        at java.lang.Class.newInstance0(Class.java:322)
        at java.lang.Class.newInstance(Class.java:275)
        at MyAgent.main(MyAgent.java:29)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.lang.instrument.*;
import java.net.*;
import java.util.*;
import java.io.*;

public class MyAgent {
    static Class clz;

    // just read the original class and redefine it
    public static void premain(String agentArgs, final Instrumentation inst) throws Exception {
        String s = agentArgs.substring(0, agentArgs.indexOf(".class"));
        clz = Class.forName(s.replace('/', '.'));
        URLConnection conn = Agent.class.getClassLoader().getResource(agentArgs).openConnection();
        final byte[] buffer = new byte[conn.getContentLength()];
        conn.getInputStream().read(buffer);
        new Timer(true).schedule(new TimerTask() {
            public void run() {
                try {
                    System.out.println("Instrumenting");
                    ClassDefinition cld = new ClassDefinition(clz, buffer);
                    inst.redefineClasses(new ClassDefinition[] { cld });
                }
                catch (Exception e) { e.printStackTrace(); }
            }
        }, 500);
    }

    public static void main(String[] args) throws Exception {
        Thread.sleep(1000);
        System.out.println("Creating instance of " + clz);
        clz.newInstance();
    }
}

---------- END SOURCE ----------
(Incident Review ID: 240014) 
======================================================================

Comments
EVALUATION The fix for the following bug: 4917140 3/3 RedefineClasses unregisters native methods causing UnsatisfiedLinkError was putback in Tiger-B41 which means the fix made Tiger-Beta2. I was not able to reproduce the failure with Tiger-FCS bits so I'm closing this bug as a duplicate of 4917140.
11-04-2007

EVALUATION 99% sure that this is a dup of the fixed JVMTI bug 4917140, but I need to verify this by testing. ###@###.### 2004-04-29
29-04-2004