When decompiling a specific jar using java decompiler (http://java.decompiler.free.fr/) I got some strange code I cannot identify what is. can someone help me? the code is something like:
Foo.access$004(Foo.this);
or this
Bar.access$006(Bar.this);
or else
Baz.access$102(Baz.this, true)
What are these methods access$004
, access$006
and access$102
?
If you are writing Java classes and distributing them over the Internet, you should know that people can reverse-engineer, disassemble, or decompile your classes into Java source code. The most widely used decompiler (at least publicly) is Mocha.
A Java Decompiler is a special type of decompiler which takes a class file as input and produces Java source code as output. The decompilation is exactly the reverse process of compilation. Thus, decompiler does not produce a replica of the source code.
In order to decompile class file, just open any of your Java projects and go to Maven dependencies of libraries to see the jar files included in your project. Just expand any jar file for which you don't have the source attached in Eclipse and click on the . class file.
Synthetic methods like this get created to support acessing private methods of inner classes. Since inner classes were not part of the initial jvm version, the access modifiers could not really handle this case. The solution was to create additional package-visible methods that delegate to the private implementation.
public class Example {
private static class Inner {
private void innerMethod() { ... }
}
public void test() {
Inner inner = ...
inner.innerMethod():
}
}
The compile would create a new method of the Inner
class like this:
static void access$000(Inner inner) {
inner.innerMethod();
}
And replace the call in the test
method like this:
Inner.access$000(inner);
The static access$000
is package visible and so accessible from the outer class, and being inside the same Inner
class it can delegate to the private innerMethod
.
These are auto-generated methods which are created by the compiler in some cases (for example when accessing private fields of another class directly, e.g., in case of nested classes).
See also What is the meaning of "static synthetic"? and Synthetic Class in Java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With