-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected use of final in emitted class #8
Comments
Simple test from Peter Nagy: ^:public
(jise/defclass IsFinal
^:public ^:static ^long
(defm test [^int y]
(let [x 100]
(set! x (+ x y))
(.println System/out x)
(set! x (+ x y))
(+ x x)))) // Decompiling class: phoenix/flake/IsFinal
package phoenix.flake;
public class IsFinal
{
public static long test(final int y) {
final int x = 100 + y;
System.out.println(x);
final int n = x + y;
return n + n;
}
} |
clj-decompiler may be wrong |
Thank you for the feedback! After some investigation, I'm figuring out what is going on. Finality information for local variables is not retained in the JVM bytecode and it only exists at compile time (as contrasted with fields’ finality, which is embedded as an access flag in the bytecode). So, nobody knows which local variable was declared final from the generated bytecode. Probably, clj-java-decompiler (or its dependant library) infers a local variable to be declared final unless the decompiler witnesses an assignment for it. In fact, another Java decompiler JD doesn't seem to emit package example.aobench;
class IsFinal {
public static long test(int paramInt) {
int i = 100;
i += paramInt;
System.out
.println(i);
i += paramInt;
return (i + i);
}
} |
Original java:
Corresponding JiSE:
Inspected with clj-decompiler, using (decompile ...), gives:
long variable in
let
is set to final. Is there a way to allow it to mutate?The text was updated successfully, but these errors were encountered: