Search code examples
javadecompilingdecompiler

Java 8 / Fernflower Decompiler: Bug or Feature


OpenJDK 1.8.0_191

I compiled and decompiled a piece of code below using Fernflower.

public class Decompile {
    public static void main(String[] args) {
        final int VAL = 20;
        System.out.println(VAL);
    }
}

The output is:

public class Decompile {

   public static void main(String[] args) {
      boolean VAL = true;
      System.out.println(20);
   }
}

I'm confused, how did VAL become a boolean?

UPDATE:

In Intellij IDEA decompiled code looks like this:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

public class Decompile {
    public Decompile() {
    }

    public static void main(String[] args) {
        int VAL = true;
        System.out.println(20);
    }
}

Solution

  • The bytecode is

    L0
     LINENUMBER 5 L0
     BIPUSH 20
     ISTORE 1
    L1
     LINENUMBER 6 L1
     GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
     BIPUSH 20
     INVOKEVIRTUAL java/io/PrintStream.println (I)V
    

    As you can see the BIPUSH pushes 20 onto the stack, then ISTORE takes the value and store it into the local variable.

    It's a Fernflower problem.


    For your interest the output for bytecode version 55 is

    int VAL = true;
    System.out.println(20);
    

    You can see decompilers can be wrong :)