Preserving parameter/argument names in compiled Java classes

To preserve names in the class file for debugging purposes try project properties, Java compiler, then “Add variable attributes to generated class files” (See Eclipse Help).

Compiling the following source:

public class StackOverflowTest {
    public void test(String foo, String bar) {
        // blah
    }
}

Is decompiled into:

// Compiled from StackOverflowTest.java (version 1.5 : 49.0, super bit)
public class StackOverflowTest {

    // Method descriptor #6 ()V
    // Stack: 1, Locals: 1
    public StackOverflowTest();
        0  aload_0 [this]
        1  invokespecial java.lang.Object() [8]
        4  return
        Line numbers:
            [pc: 0, line: 1]
        Local variable table:
            [pc: 0, pc: 5] local: this index: 0 type: StackOverflowTest

    // Method descriptor #15 (Ljava/lang/String;Ljava/lang/String;)V
    // Stack: 0, Locals: 3
    public void test(java.lang.String foo, java.lang.String bar);
        0  return
        Line numbers:
            [pc: 0, line: 4]
        Local variable table:
            [pc: 0, pc: 1] local: this index: 0 type: StackOverflowTest
            [pc: 0, pc: 1] local: foo index: 1 type: java.lang.String
            [pc: 0, pc: 1] local: bar index: 2 type: java.lang.String
}

See the parameter names are preserved in the class files.

I would suggest you look into how your source is being compiled, which version it is compiled for etc.

EDIT:

Ah, I see this is different for interfaces – they don’t seem to have this information available for the debugger which I guess makes sense. I don’t think there’ll be a way round this, if you just want to see the parameter names when you’re editing source you’ll need to go the javadoc route as Nagrom_17 suggests (attach the source).

Leave a Comment