0

I'm using ASM to inject code to methods:

    @Override
    public void visitCode() {
        visitMethodInsn(Opcodes.INVOKESTATIC, "sssss/CopyOfsss", "foo", "()V");

        super.visitCode();
    }


Exception in thread "main" java.lang.NoClassDefFoundError: sssss/CopyOfsss
    at java.util.regex.Pattern$Node.match(Pattern.java)
    at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
    at java.util.regex.Pattern$Curly.match0(Pattern.java:3760)
    at java.util.regex.Pattern$Curly.match(Pattern.java:3744)
    at java.util.regex.Matcher.match(Matcher.java:1127)
    at java.util.regex.Matcher.matches(Matcher.java:502)
    at sssss.CopyOfsss.main(CopyOfsss.java:26)

please help~

5
  • Please read the documentation or manual, first. Commented Oct 18, 2012 at 8:32
  • This doesn't help man! Would you please figure out where and which chapter to read? If I changed the class to "java.land.System" and call the nanoTime, it works. Commented Oct 18, 2012 at 8:37
  • The NoClassDefFoundError (roughly) means the class was there on compile time, but not on runtime - do you perhaps have a classpath issue or a bungled JAR file here? Commented Oct 18, 2012 at 9:08
  • As you see above the "sssss/CopyOfsss" is the main class. It must be exist~ Commented Oct 18, 2012 at 9:20
  • 1
    Which suggests it may be a classloader issue? If CopyOfssss is loaded by a child classloader, makes a call in to a class loaded by its parent loader, and that class then tries to make a static call back to CopyOfsssss then it will fail (the child CL can see classes loaded by the parent but not vice-versa). Commented Oct 18, 2012 at 10:36

1 Answer 1

1

Well, I got my answer. This is because the injected class is loaded by bootstrap class loader, so the injected code can't call methods in "CopyOfsssss". Refer to this article. The solution is adding "-Xbootclasspath/a:/path/yourclass.lib" to the jvm argument. Note the "/a" after "Xbootclasspath" means appending.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.