I am facing problem with IntegerCache : Using iBatis data access framework which internally use iBatis PreparedStatement class.
Calling database procedure like
{ call UPDATE_PROC(?,?,?,?,?,?) }
with params : [123, 234, 345, TEST1, 567, TEST2]
while iBatis API setting first parameter using :
typeHandler.setParameter(ps, i + 1, value, mapping.getJdbcTypeName());
i=0, value=123
here ps is reference to PreparedStatement, i is parameter index in database procedure.
it internally call
ps.setInt(i, ((Integer) parameter).intValue());
i=1, parameter=123 (Note : i is int not Integer)
Internally this call invoked using Java reflection api :
public Object invoke(Object proxy, Method method, Object[] params) throws Throwable
method : setInt, params : [1, 123]
while getting Integer value of i for method invocation, JVM invoke below 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
the value of IntegerCache.cache[i + (-IntegerCache.low)]
ends up with IntegerCache.cache[129]
there should be value 1
at integer cache index [129] but when I debug the code i found value 3
at index [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
as IntegerCache is final type there should not be repeating values e.g. 3 at index [129] and [131]
so, I end up with exception :
java.sql.SQLException: Missing IN or OUT parameter at index:: 1
my question is how this can be possible? please suggest