Program: 15805
Project: 15805
Buggy source:
/** 
 * Read a value.
 * @return the value
 */
public Value readValue() throws IOException {
  int type=readInt();
switch (type) {
case Value.NULL:
    return ValueNull.INSTANCE;
case Value.BYTES:
  return ValueBytes.getNoCopy(readBytes());
case Value.UUID:
return ValueUuid.get(readLong(),readLong());
case Value.JAVA_OBJECT:
return ValueJavaObject.getNoCopy(null,readBytes(),session.getDataHandler());
case Value.BOOLEAN:
return ValueBoolean.get(readBoolean());
case Value.BYTE:
return ValueByte.get(readByte());
case Value.DATE:
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
return ValueDate.fromDateValue(readLong());
}
 else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
return ValueDate.fromMillis(DateTimeUtils.getTimeUTCWithoutDst(readLong()));
}
return ValueDate.fromMillis(readLong());
case Value.TIME:
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
return ValueTime.fromNanos(readLong());
}
 else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
return ValueTime.fromMillis(DateTimeUtils.getTimeUTCWithoutDst(readLong()));
}
return ValueTime.fromMillis(readLong());
case Value.TIMESTAMP:
{
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
return ValueTimestamp.fromDateValueAndNanos(readLong(),readLong());
}
 else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
return ValueTimestamp.fromMillisNanos(DateTimeUtils.getTimeUTCWithoutDst(readLong()),readInt());
}
return ValueTimestamp.fromMillisNanos(readLong(),readInt());
}
case Value.DECIMAL:
return ValueDecimal.get(new BigDecimal(readString()));
case Value.DOUBLE:
return ValueDouble.get(readDouble());
case Value.FLOAT:
return ValueFloat.get(readFloat());
case Value.INT:
return ValueInt.get(readInt());
case Value.LONG:
return ValueLong.get(readLong());
case Value.SHORT:
return ValueShort.get((short)readInt());
case Value.STRING:
return ValueString.get(readString());
case Value.STRING_IGNORECASE:
return ValueStringIgnoreCase.get(readString());
case Value.STRING_FIXED:
return ValueStringFixed.get(readString());
case Value.BLOB:
{
long length=readLong();
if (version >= Constants.TCP_PROTOCOL_VERSION_11) {
if (length == -1) {
int tableId=readInt();
long id=readLong();
byte[] hmac;
if (version >= Constants.TCP_PROTOCOL_VERSION_12) {
hmac=readBytes();
}
 else {
hmac=null;
}
long precision=readLong();
return ValueLobDb.create(Value.BLOB,session.getDataHandler(),tableId,id,hmac,precision);
}
int len=(int)length;
byte[] small=new byte[len];
IOUtils.readFully(in,small,len);
int magic=readInt();
if (magic != LOB_MAGIC) {
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1,"String_Node_Str" + magic);
}
return ValueLobDb.createSmallLob(Value.BLOB,small,length);
}
Value v=session.getDataHandler().getLobStorage().createBlob(in,length);
int magic=readInt();
if (magic != LOB_MAGIC) {
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1,"String_Node_Str" + magic);
}
return v;
}
case Value.CLOB:
{
long length=readLong();
if (version >= Constants.TCP_PROTOCOL_VERSION_11) {
if (length == -1) {
int tableId=readInt();
long id=readLong();
byte[] hmac;
if (version >= Constants.TCP_PROTOCOL_VERSION_12) {
hmac=readBytes();
}
 else {
hmac=null;
}
long precision=readLong();
return ValueLobDb.create(Value.CLOB,session.getDataHandler(),tableId,id,hmac,precision);
}
DataReader reader=new DataReader(in);
int len=(int)length;
char[] buff=new char[len];
IOUtils.readFully(reader,buff,len);
int magic=readInt();
if (magic != LOB_MAGIC) {
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1,"String_Node_Str" + magic);
}
byte[] small=new String(buff).getBytes(Constants.UTF8);
return ValueLobDb.createSmallLob(Value.CLOB,small,length);
}
Value v=session.getDataHandler().getLobStorage().createClob(new DataReader(in),length);
int magic=readInt();
if (magic != LOB_MAGIC) {
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1,"String_Node_Str" + magic);
}
return v;
}
case Value.ARRAY:
{
int len=readInt();
Class<?> componentType=Object.class;
if (len < 0) {
len=-(len + 1);
componentType=Utils.loadUserClass(readString());
}
Value[] list=new Value[len];
for (int i=0; i < len; i++) {
list[i]=readValue();
}
return ValueArray.get(componentType,list);
}
case Value.RESULT_SET:
{
SimpleResultSet rs=new SimpleResultSet();
rs.setAutoClose(false);
int columns=readInt();
for (int i=0; i < columns; i++) {
rs.addColumn(readString(),readInt(),readInt(),readInt());
}
while (true) {
if (!readBoolean()) {
break;
}
Object[] o=new Object[columns];
for (int i=0; i < columns; i++) {
o[i]=readValue().getObject();
}
rs.addRow(o);
}
return ValueResultSet.get(rs);
}
case Value.GEOMETRY:
if (version >= Constants.TCP_PROTOCOL_VERSION_14) {
return ValueGeometry.get(readBytes());
}
return ValueGeometry.get(readString());
default :
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1,"String_Node_Str" + type);
}
}

Fixed version (ground truth):
/** 
 * Read a value.
 * @return the value
 */
public Value readValue() throws IOException {
  int type=readInt();
switch (type) {
case Value.NULL:
    return ValueNull.INSTANCE;
case Value.BYTES:
  return ValueBytes.getNoCopy(readBytes());
case Value.UUID:
return ValueUuid.get(readLong(),readLong());
case Value.JAVA_OBJECT:
return ValueJavaObject.getNoCopy(null,readBytes(),session.getDataHandler());
case Value.BOOLEAN:
return ValueBoolean.get(readBoolean());
case Value.BYTE:
return ValueByte.get(readByte());
case Value.DATE:
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
return ValueDate.fromDateValue(readLong());
}
 else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
return ValueDate.fromMillis(DateTimeUtils.getTimeUTCWithoutDst(readLong()));
}
return ValueDate.fromMillis(readLong());
case Value.TIME:
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
return ValueTime.fromNanos(readLong());
}
 else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
return ValueTime.fromMillis(DateTimeUtils.getTimeUTCWithoutDst(readLong()));
}
return ValueTime.fromMillis(readLong());
case Value.TIMESTAMP:
{
if (version >= Constants.TCP_PROTOCOL_VERSION_9) {
return ValueTimestamp.fromDateValueAndNanos(readLong(),readLong());
}
 else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
return ValueTimestamp.fromMillisNanos(DateTimeUtils.getTimeUTCWithoutDst(readLong()),readInt() % 1000000);
}
return ValueTimestamp.fromMillisNanos(readLong(),readInt() % 1000000);
}
case Value.DECIMAL:
return ValueDecimal.get(new BigDecimal(readString()));
case Value.DOUBLE:
return ValueDouble.get(readDouble());
case Value.FLOAT:
return ValueFloat.get(readFloat());
case Value.INT:
return ValueInt.get(readInt());
case Value.LONG:
return ValueLong.get(readLong());
case Value.SHORT:
return ValueShort.get((short)readInt());
case Value.STRING:
return ValueString.get(readString());
case Value.STRING_IGNORECASE:
return ValueStringIgnoreCase.get(readString());
case Value.STRING_FIXED:
return ValueStringFixed.get(readString());
case Value.BLOB:
{
long length=readLong();
if (version >= Constants.TCP_PROTOCOL_VERSION_11) {
if (length == -1) {
int tableId=readInt();
long id=readLong();
byte[] hmac;
if (version >= Constants.TCP_PROTOCOL_VERSION_12) {
hmac=readBytes();
}
 else {
hmac=null;
}
long precision=readLong();
return ValueLobDb.create(Value.BLOB,session.getDataHandler(),tableId,id,hmac,precision);
}
int len=(int)length;
byte[] small=new byte[len];
IOUtils.readFully(in,small,len);
int magic=readInt();
if (magic != LOB_MAGIC) {
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1,"String_Node_Str" + magic);
}
return ValueLobDb.createSmallLob(Value.BLOB,small,length);
}
Value v=session.getDataHandler().getLobStorage().createBlob(in,length);
int magic=readInt();
if (magic != LOB_MAGIC) {
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1,"String_Node_Str" + magic);
}
return v;
}
case Value.CLOB:
{
long length=readLong();
if (version >= Constants.TCP_PROTOCOL_VERSION_11) {
if (length == -1) {
int tableId=readInt();
long id=readLong();
byte[] hmac;
if (version >= Constants.TCP_PROTOCOL_VERSION_12) {
hmac=readBytes();
}
 else {
hmac=null;
}
long precision=readLong();
return ValueLobDb.create(Value.CLOB,session.getDataHandler(),tableId,id,hmac,precision);
}
DataReader reader=new DataReader(in);
int len=(int)length;
char[] buff=new char[len];
IOUtils.readFully(reader,buff,len);
int magic=readInt();
if (magic != LOB_MAGIC) {
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1,"String_Node_Str" + magic);
}
byte[] small=new String(buff).getBytes(Constants.UTF8);
return ValueLobDb.createSmallLob(Value.CLOB,small,length);
}
Value v=session.getDataHandler().getLobStorage().createClob(new DataReader(in),length);
int magic=readInt();
if (magic != LOB_MAGIC) {
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1,"String_Node_Str" + magic);
}
return v;
}
case Value.ARRAY:
{
int len=readInt();
Class<?> componentType=Object.class;
if (len < 0) {
len=-(len + 1);
componentType=Utils.loadUserClass(readString());
}
Value[] list=new Value[len];
for (int i=0; i < len; i++) {
list[i]=readValue();
}
return ValueArray.get(componentType,list);
}
case Value.RESULT_SET:
{
SimpleResultSet rs=new SimpleResultSet();
rs.setAutoClose(false);
int columns=readInt();
for (int i=0; i < columns; i++) {
rs.addColumn(readString(),readInt(),readInt(),readInt());
}
while (true) {
if (!readBoolean()) {
break;
}
Object[] o=new Object[columns];
for (int i=0; i < columns; i++) {
o[i]=readValue().getObject();
}
rs.addRow(o);
}
return ValueResultSet.get(rs);
}
case Value.GEOMETRY:
if (version >= Constants.TCP_PROTOCOL_VERSION_14) {
return ValueGeometry.get(readBytes());
}
return ValueGeometry.get(readString());
default :
throw DbException.get(ErrorCode.CONNECTION_BROKEN_1,"String_Node_Str" + type);
}
}