Java valueOf (int) with IntegerCache returns value 3 for valueOf (1)

I have a problem with IntegerCache : Using the iBatis data access infrastructure that internally uses the iBatis PreparedStatement class.

A database procedure call, for example

{ call UPDATE_PROC(?,?,?,?,?,?)  }
with params : [123, 234, 345, TEST1, 567, TEST2]

while the iBatis API sets the first parameter using:

typeHandler.setParameter(ps, i + 1, value, mapping.getJdbcTypeName());

i = 0, value = 123

here ps refers to PreparedStatement, i am the index of the parameter in the database procedure.

he internally calls

 ps.setInt(i, ((Integer) parameter).intValue());

i = 1, parameter = 123 (Note: I am int not Integer)

Internal call invoked using reflection Java api:

public Object invoke(Object proxy, Method method, Object[] params) throws Throwable

method: setInt, params: [1, 123]

getting the Integer value i for the method call, the JVM is called below the method:

public static Integer valueOf(int i) {
    assert IntegerCache.high >= 127;
    if (i >= IntegerCache.low && i <= IntegerCache.high)
        return IntegerCache.cache[i + (-IntegerCache.low)];
    return new Integer(i);
}

IntegerCache.low = -128 IntegerCache.high = 127

IntegerCache.cache[i + (-IntegerCache.low)] IntegerCache.cache[129] 1 [129], , 3 [129]:

, -8, -7, -6, -5, -4, -3, -2, -1, 0, 3 **index[129]**, 2, 3 **index[131]**, 4, 5, 6, 7, 8, 9, 10, 11

IntegerCache , , . 3 [129] [131]

:

java.sql.SQLException: Missing IN or OUT parameter at index:: 1

, ? ,

+4
2

, . . , STS JVM. int Integer , IntegerCache.

, , , .

POC, :

public class TestEclipseJVMDebugger {

    public static void main(String[] argc) {

        Integer i1 = new Integer(27);
        int i2 = 7;

        assert (-128 <= i1 && i1 <= 127);
        assert (-128 <= i2 && i2 <= 127);

        System.out.println("i1 = " + i1);
        i1 = Integer.valueOf(i2);
        System.out.println("i1 = " + i1);

        System.out
                .println("apply debug point here and change value of primitive data type of i1 to 666 from debug mode");
        System.out.println("i1 = " + i1);
        i1 = Integer.valueOf(i2);
        System.out.println("i1 = " + i1);

    }

}

, JVM Eclipse , JVM.

, StringCache, DoubleCache .. .

0

, ?

Integer.value .

0

All Articles