What it is?

Suppose I have this class:

public class class1 extends Applet implements Runnable { private String s; private URL u; ... } 

And the second class:

 class TS extends Thread { private final class1 _$97913; public TS(class1 paramclass1) { this._$97913 = paramclass1; } ... public void PostData() { ... class1.access$16(this._$97913, new Socket(class1.access$17(this._$97913), 80); ... } ... } 

Can someone explain how class1.access$16(this._$97913, new Socket(class1.access$17(this._$97913), 80); refers to private URL u; to class1?

Where does access$16 come from? What is it called and where can I find out more about it?

Well, this is the result of decompiled code, is there a way to associate numbers ( access$16 , access$17 , etc.) with the source variable or class? From what I see, the only way would be to do it manually (i.e. see what it refers to, where to guess that, since the class 'this' got the URL, then 'this' should be associated with the variable "this")?

+4
source share
2 answers

Well, this is the result of decompiled code, is there a way to bind numbers ( access$16 , access$17 , etc.) to the source variable or class? From what I see, the only way to do this manually is (that is, see what is referenced, where and suppose that since the class 'this' received the URL, then 'this' should be associated with the variable 'this' )?

access$x methods are created if you access private methods or variables from a nested class (or vice versa, or from one nested class to another). They are created by the compiler because the virtual machine does not allow direct access to private variables.

If the decompiler allows these method calls to remain in the restored source code for the used class, it should also allow the definitions of synthetic methods to remain in the restored source code for the used class. If so, look at the class that is the recipient of the method in question ( class1 in your case), there should be such a method ( access$17 ). In the code of this method, you can see which real method (or variable) is available here.

If the decompiler removed the synthetic methods, this is either an error or it can be configurable. It may also be that you need to pass all the classes at once, and then it can put the necessary methods / fields everywhere - see its documentation.


If you have classes before the method call point (and their superclasses, if any), you must have methods.

From the scanned fragment there should be the access$16 and access$17 class1 in class1 (or is class1 local variable class1 here?).

If this is not the case, your decompiler may have tried to be smarter than necessary. You could look at the output of javap class1 to see if methods exist, and javap -c class1 for the entire bytecode. Or use another decompiler.

+4
source

Is this the result of java decompilation?

It looks like a synthetic method that allows external and internal classes to access other private fields or methods.

The Java compiler must create synthetic methods for nested classes when their attributes specified using a private modifier gain access to the wrapper class. The following code example points to this situation.

...

As you can see from the screenshot above, the synthesized method with the access name $ 100 was created on the NestedClass nested class to provide its private string for the enclosing class. Note that the synthetic method is added only for the individual private attribute NestedClass accessed by the closing class.

+5
source

Source: https://habr.com/ru/post/1346366/


All Articles