#4 signed integer is not treated correctly

open
nobody
None
5
2010-06-02
2010-06-02
Anonymous
No

If integer value is negative, for example, -10, when serp read the class file and define the class, value is turned into 246.
Here is a test case:
package tests;

public class TestSignedNumber {
int testint;

public int businessMethodSignedInt() {
setSignedInt(-10);
return getSignedInt();
}

public void setSignedInt(int value) {
testint = value;
}

public int getSignedInt() {
return testint;
}
}
If you test businessMethodSignedInt(), return value is 246 instead of -10.

Discussion

  • Xiaoqin Feng
    Xiaoqin Feng
    2010-06-02

    The above bug is filed by me.
    I found the place that causes this problem and here is the candidate fix:
    In serp.bytecode.ConstantInstruction.read(DataInput in),
    Index: ConstantInstruction.java
    ===================================================================
    RCS file: /cvsroot/serp/serp/src/main/java/serp/bytecode/ConstantInstruction.java,v
    retrieving revision 1.5
    diff -u -r1.5 ConstantInstruction.java
    --- ConstantInstruction.java 2 Oct 2007 15:24:38 -0000 1.5
    +++ ConstantInstruction.java 2 Jun 2010 23:24:59 -0000
    @@ -377,10 +377,14 @@
    super.read(in);
    switch (getOpcode()) {
    case Constants.BIPUSH:
    + _arg = in.readByte();
    + break;
    case Constants.LDC:
    _arg = in.readUnsignedByte();
    break;
    case Constants.SIPUSH:
    + _arg = in.readShort();
    + break;
    case Constants.LDCW:
    case Constants.LDC2W:
    _arg = in.readUnsignedShort();

    I have tested my test case and run serp "mvn test". They all passed.