javamavenantbytecode

Byte code difference in #-values after change Ant to Maven


I changed the compilation of a project from Ant to Maven. We still use Java 1.7.0_80. The ByteCode of all classes stayed the same except for a Comparator class. I disassembled the class with javap -c. The only differences are in #-values, e.g.:

before: invokevirtual #2

after: invokevirtual #29

What do these #-values mean? Is this a functional difference or just a difference in naming?

EDIT: The first method in Bytecode before and after:

  public de.continentale.kvrl.model.comp.KvRLRechBetragEuroComparator();
    Code:
       0: aload_0       
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return        


  public de.continentale.kvrl.model.comp.KvRLRechBetragEuroComparator();
    Code:
       0: aload_0       
       1: invokespecial #21                 // Method java/lang/Object."<init>":()V
       4: return   

Solution

  • The #29 refers to an index in the constant table that describes the method being invoked. It would have been better if you had pasted the full output of javap -c, because the comment at the end of the line indicates the actual method descriptor.

    Example of javap -c on an invocation of an instance method test in class Z:

       7: invokevirtual #19                 // Method snippet/Z.test:()V
    

    You can ignore the # number, as long as the method descriptor in the comment is the same.

    Why

    As to the "why" question, it is very likely caused by the debug in the ant and maven compiler task/plugin settings.

    By default, the maven-compiler-plugin compiles with the debug configuration option set to true, which will attach among other the name of the source file, and thing like line number tables and local variable names.

    https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

    By default, the ant java compiler has this set to false.

    https://ant.apache.org/manual/Tasks/javac.html

    To compare and check, set the debug parameter of the Ant Javac task to true and see if that makes the generated .class files the same.