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~

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Sefler
  • 2,237
  • 5
  • 19
  • 29
  • Please read the documentation or manual, first. – Damian Leszczyński - Vash Oct 18 '12 at 08: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. – Sefler Oct 18 '12 at 08: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? – Anders R. Bystrup Oct 18 '12 at 09:08
  • As you see above the "sssss/CopyOfsss" is the main class. It must be exist~ – Sefler Oct 18 '12 at 09: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). – Ian Roberts Oct 18 '12 at 10:36

1 Answers1

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.

Laurel
  • 5,965
  • 14
  • 31
  • 57
Sefler
  • 2,237
  • 5
  • 19
  • 29