Search code examples
javabytecodedecompiling

java decompilation


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?


Solution

  • 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.