I have a Kitchen.jar
file. I need to modify a class inside it. I decompile it with JD. Then I modify the Toster.java
file and compile it with:
javac -classpath . Toster.java
And then I take it back into the Kitchen.jar
with:
jar -uf Kitchen.jar Toster.class
All works except for one problem. When I open updated Kitchen.jar
in JD I see that local variables inside all methods are renamed to something like localLongVar
. Why?
The reason I ask is because Kitchen.jar
refuses to work after the modification. And I suspect it has to be the compilation problem. Maybe I've misused some flags or anything. Not sure. I have no knowledge of Java whatsoever, except for the basic syntax.
My guess is that I compile it with latest 1.7 version and original jar is compiled with older JDK. That may explain failure of operation, but that doesn't explain the renaming of locals.
The random line from the original jar:
BigInteger[] result = new BigInteger[bis.length / 2];
And the very same line of my class:
BigInteger[] arrayOfBigInteger1 = new BigInteger[paramArrayOfBigInteger.length * 2];
So its result
vs arrayOfBigInteger1
.
Answer: Yes — the scopes will not overlap so there will be two local variables, one per method, each with the same name.
Variables that are declared inside a method are called local variables because they can only be utilized and referenced in the method itself. Take a look at the code below showing the add() method with a local variable inside.
Variables in method declarations—these are called parameters.
No variable name should not has same name with **any** class name.
By default javac removes debugging information other than source file and line number. Compile with javac -g
or javac -g:vars
.
From the documentation of javac
-g
Generate all debugging information, including local variables. By default, only line number and source file information is generated.
-g:none
Do not generate any debugging information.
-g:{keyword list}
Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:
source
Source file debugging information
lines
Line number debugging information
vars
Local variable debugging information
The names of the variables are not preserved in compiled code. Most obvious to reduce the size of the compiled class. The compiler will replace them by shorter names. Doing this is also good for obfuscating the code so that someone who decompiles the code has problems to understand the logic. The localLongVar
you see in JD is what the compiler makes of the replaced variable names.
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