I am trying to get an ASMified version of an inner class in java. My command looks something like this java -classpath "asm-all-3.3.1.jar:myjar.jar" org.objectweb.asm.util.ASMifierClassVisitor path/to/my/class$inner.class
But it seems to only return the ASMified version of the outer class, what am I doing wrong here?
2 Answers
You get to the problem when you try
echo path/to/my/outer$inner.class
which will print
path/to/my/outer.class
Your shell interprets $inner
as as variable reference and since you likely have no such variable defined in your environment, it will substitute it with an empty text, which in this case leads to the path and name of the outer class.
Which demonstrates why silently doing the wrong thing is worse than failing with an error message (or exception).
When you prepend the dollar sign with a backslash, i.e. path/to/my/outer\$inner.class
, it will be interpreted as a literal $
and work. Or lead to other errors, as the other answer mentions, your ASM version is really old and may have problems parsing newer class files.

- 285,553
- 42
- 434
- 765
-
Isn't that what I showed in my previous answer already? The syntax variants for Bash-like and Windows-like shells are clearly visible, even though I did not explicitly mention them, which arguably I should have done. I assumed, the code sections would speak for themselves. So thanks for making this part more explicit. I added the _bash_ and _ash_ tags to the question in order to hint at the fact that the actual problem is not mainly about ASM. – kriegaex Dec 14 '21 at 04:11
-
2@kriegaex yes, you’ve shown the right syntax (and got my upvote). But the OP indeed needed an explicit explanation of what went wrong. I also found it interesting how the variable substitution led to the path of the other existing class file, to end up at a confusing behavior. It’s a great demonstration how dealing with an erroneous situation (variable not found) by silently fixing it (treat it like empty string) can lead to bigger problems. That’s for all users of utility classes which silently treat `null` like an empty string and such alike… – Holger Dec 14 '21 at 08:38
-
I agree with you. – kriegaex Dec 14 '21 at 12:10
How about using an ASM version more recent than from 2008, maybe one which can also handle classes more recent than Java 6? I am suggesting these:
- https://search.maven.org/artifact/org.ow2.asm/asm/9.2/jar
- https://search.maven.org/artifact/org.ow2.asm/asm-util/9.2/jar
I quickly tried something like this (Git Bash on Windows 10):
java -cp "asm-9.2.jar;asm-util-9.2.jar" org.objectweb.asm.util.ASMifier MyClass\$MyInnerClass.class
In Cmd.exe it would be:
java -cp asm-9.2.jar;asm-util-9.2.jar org.objectweb.asm.util.ASMifier MyClass$MyInnerClass.class
Both variants work nicely.

- 63,017
- 15
- 111
- 202