Program: 43036
Project: 43036
Buggy source:
Object doReadObject(int leadByte,final boolean unshared) throws IOException, ClassNotFoundException {
  depth++;
  try {
    for (; ; ) switch (leadByte) {
case TC_NULL:
{
        return null;
      }
case TC_REFERENCE:
{
      final Object prevObj=readBackReference(readInt());
      if (prevObj instanceof Descriptor) {
        throw objectStreamClassException();
      }
      return prevObj;
    }
case TC_CLASS:
{
    final Descriptor descriptor=readNonNullClassDescriptor();
    final Class<?> obj=descriptor.getType();
    instanceCache.add(obj);
    return obj;
  }
case TC_CLASSDESC:
{
  throw objectStreamClassException();
}
case TC_PROXYCLASSDESC:
{
throw objectStreamClassException();
}
case TC_STRING:
{
final int len=readUnsignedShort();
final String str=UTFUtils.readUTFBytesByByteCount(this,len);
instanceCache.add(unshared ? UNSHARED : str);
return str;
}
case TC_LONGSTRING:
{
final long len=super.readLong();
final String str=UTFUtils.readUTFBytesByByteCount(this,len);
instanceCache.add(unshared ? UNSHARED : str);
return str;
}
case TC_ARRAY:
{
final Descriptor descriptor=readNonNullClassDescriptor();
final int idx=instanceCache.size();
instanceCache.add(UNRESOLVED);
final int size=readInt();
final Class<?> type=descriptor.getType();
if (!type.isArray()) {
throw new InvalidClassException(type.getName(),"String_Node_Str");
}
final Class<?> ct=type.getComponentType();
if (ct.isPrimitive()) {
if (ct == byte.class) {
final byte[] bytes=new byte[size];
readFully(bytes);
instanceCache.set(idx,bytes);
return bytes;
}
 else if (ct == short.class) {
final short[] shorts=new short[size];
for (int i=0; i < shorts.length; i++) {
shorts[i]=readShort();
}
instanceCache.set(idx,shorts);
return shorts;
}
 else if (ct == int.class) {
final int[] ints=new int[size];
for (int i=0; i < ints.length; i++) {
ints[i]=readInt();
}
instanceCache.set(idx,ints);
return ints;
}
 else if (ct == long.class) {
final long[] longs=new long[size];
for (int i=0; i < longs.length; i++) {
longs[i]=readLong();
}
instanceCache.set(idx,longs);
return longs;
}
 else if (ct == float.class) {
final float[] floats=new float[size];
for (int i=0; i < floats.length; i++) {
floats[i]=readFloat();
}
instanceCache.set(idx,floats);
return floats;
}
 else if (ct == double.class) {
final double[] doubles=new double[size];
for (int i=0; i < doubles.length; i++) {
doubles[i]=readDouble();
}
instanceCache.set(idx,doubles);
return doubles;
}
 else if (ct == boolean.class) {
final boolean[] booleans=new boolean[size];
for (int i=0; i < booleans.length; i++) {
booleans[i]=readBoolean();
}
instanceCache.set(idx,booleans);
return booleans;
}
 else if (ct == char.class) {
final char[] chars=new char[size];
for (int i=0; i < chars.length; i++) {
chars[i]=readChar();
}
instanceCache.set(idx,chars);
return chars;
}
 else {
throw new InvalidClassException(type.getName(),"String_Node_Str");
}
}
 else {
final Object[] objects=(Object[])Array.newInstance(ct,size);
instanceCache.set(idx,objects);
for (int i=0; i < objects.length; i++) {
objects[i]=doReadObject(false);
}
return objects;
}
}
case TC_ENUM:
{
final Descriptor descriptor=readNonNullClassDescriptor();
final Class<? extends Enum> enumType;
try {
enumType=descriptor.getType().asSubclass(Enum.class);
}
 catch (ClassCastException e) {
throw new InvalidClassException("String_Node_Str");
}
final int h=instanceCache.size();
instanceCache.add(UNRESOLVED);
final String constName=(String)doReadObject(false);
final Enum obj=Enum.valueOf(enumType,constName);
instanceCache.set(h,obj);
return obj;
}
case TC_OBJECT:
{
final Descriptor descriptor=readNonNullClassDescriptor();
if ((descriptor.getFlags() & (SC_SERIALIZABLE | SC_EXTERNALIZABLE)) == 0) {
throw new NotSerializableException(descriptor.getClass().getName());
}
final Object obj=creator.create(descriptor.getType());
instanceCache.add(unshared ? UNSHARED : obj);
if ((descriptor.getFlags() & SC_EXTERNALIZABLE) != 0) {
if (obj instanceof Externalizable) {
final Externalizable externalizable=(Externalizable)obj;
if ((descriptor.getFlags() & SC_BLOCK_DATA) != 0) {
externalizable.readExternal(blockUnmarshaller);
blockUnmarshaller.readToEndBlockData();
blockUnmarshaller.unblock();
}
 else {
externalizable.readExternal(this);
}
}
 else {
throw new InvalidObjectException("String_Node_Str");
}
}
 else if (obj instanceof Externalizable) {
throw new InvalidObjectException("String_Node_Str");
}
 else {
doReadSerialObject(descriptor,obj.getClass(),obj);
}
return obj;
}
case TC_EXCEPTION:
{
clearInstanceCache();
final IOException ex=(IOException)doReadObject(false);
throw new WriteAbortedException("String_Node_Str",ex);
}
case TC_BLOCKDATA:
case TC_BLOCKDATALONG:
{
blockUnmarshaller.readBlockHeader(leadByte);
throw createOptionalDataException(blockUnmarshaller.remaining());
}
case TC_ENDBLOCKDATA:
{
throw createOptionalDataException(0);
}
case TC_RESET:
{
if (depth > 1) {
throw new StreamCorruptedException("String_Node_Str");
}
clearInstanceCache();
leadByte=readByte() & 0xff;
continue;
}
default :
{
throw badLeadByte(leadByte);
}
}
}
  finally {
depth--;
}
}

Fixed version (ground truth):
Object doReadObject(int leadByte,final boolean unshared) throws IOException, ClassNotFoundException {
  depth++;
  try {
    for (; ; ) switch (leadByte) {
case TC_NULL:
{
        return null;
      }
case TC_REFERENCE:
{
      final Object prevObj=readBackReference(readInt());
      if (prevObj instanceof Descriptor) {
        throw objectStreamClassException();
      }
      return prevObj;
    }
case TC_CLASS:
{
    final Descriptor descriptor=readNonNullClassDescriptor();
    final Class<?> obj=descriptor.getType();
    instanceCache.add(obj);
    return obj;
  }
case TC_CLASSDESC:
{
  throw objectStreamClassException();
}
case TC_PROXYCLASSDESC:
{
throw objectStreamClassException();
}
case TC_STRING:
{
final int len=readUnsignedShort();
final String str=UTFUtils.readUTFBytesByByteCount(this,len);
instanceCache.add(unshared ? UNSHARED : str);
return str;
}
case TC_LONGSTRING:
{
final long len=super.readLong();
final String str=UTFUtils.readUTFBytesByByteCount(this,len);
instanceCache.add(unshared ? UNSHARED : str);
return str;
}
case TC_ARRAY:
{
final Descriptor descriptor=readNonNullClassDescriptor();
final int idx=instanceCache.size();
instanceCache.add(UNRESOLVED);
final int size=readInt();
final Class<?> type=descriptor.getType();
if (!type.isArray()) {
throw new InvalidClassException(type.getName(),"String_Node_Str");
}
final Class<?> ct=type.getComponentType();
if (ct.isPrimitive()) {
if (ct == byte.class) {
final byte[] bytes=new byte[size];
readFully(bytes);
instanceCache.set(idx,bytes);
return bytes;
}
 else if (ct == short.class) {
final short[] shorts=new short[size];
for (int i=0; i < shorts.length; i++) {
shorts[i]=readShort();
}
instanceCache.set(idx,shorts);
return shorts;
}
 else if (ct == int.class) {
final int[] ints=new int[size];
for (int i=0; i < ints.length; i++) {
ints[i]=readInt();
}
instanceCache.set(idx,ints);
return ints;
}
 else if (ct == long.class) {
final long[] longs=new long[size];
for (int i=0; i < longs.length; i++) {
longs[i]=readLong();
}
instanceCache.set(idx,longs);
return longs;
}
 else if (ct == float.class) {
final float[] floats=new float[size];
for (int i=0; i < floats.length; i++) {
floats[i]=readFloat();
}
instanceCache.set(idx,floats);
return floats;
}
 else if (ct == double.class) {
final double[] doubles=new double[size];
for (int i=0; i < doubles.length; i++) {
doubles[i]=readDouble();
}
instanceCache.set(idx,doubles);
return doubles;
}
 else if (ct == boolean.class) {
final boolean[] booleans=new boolean[size];
for (int i=0; i < booleans.length; i++) {
booleans[i]=readBoolean();
}
instanceCache.set(idx,booleans);
return booleans;
}
 else if (ct == char.class) {
final char[] chars=new char[size];
for (int i=0; i < chars.length; i++) {
chars[i]=readChar();
}
instanceCache.set(idx,chars);
return chars;
}
 else {
throw new InvalidClassException(type.getName(),"String_Node_Str");
}
}
 else {
final Object[] objects=(Object[])Array.newInstance(ct,size);
instanceCache.set(idx,objects);
for (int i=0; i < objects.length; i++) {
objects[i]=doReadObject(false);
}
return objects;
}
}
case TC_ENUM:
{
final Descriptor descriptor=readNonNullClassDescriptor();
final Class<? extends Enum> enumType;
try {
enumType=descriptor.getType().asSubclass(Enum.class);
}
 catch (ClassCastException e) {
throw new InvalidClassException("String_Node_Str");
}
final int h=instanceCache.size();
instanceCache.add(UNRESOLVED);
final String constName=(String)doReadObject(false);
final Enum obj=Enum.valueOf(enumType,constName);
instanceCache.set(h,obj);
return obj;
}
case TC_OBJECT:
{
final Descriptor descriptor=readNonNullClassDescriptor();
if ((descriptor.getFlags() & (SC_SERIALIZABLE | SC_EXTERNALIZABLE)) == 0) {
throw new NotSerializableException(descriptor.getClass().getName());
}
final Object obj=creator.create(descriptor.getType());
instanceCache.add(unshared ? UNSHARED : obj);
if ((descriptor.getFlags() & SC_EXTERNALIZABLE) != 0) {
if (obj instanceof Externalizable) {
final Externalizable externalizable=(Externalizable)obj;
if ((descriptor.getFlags() & SC_BLOCK_DATA) != 0) {
externalizable.readExternal(blockUnmarshaller);
blockUnmarshaller.readToEndBlockData();
blockUnmarshaller.unblock();
}
 else {
externalizable.readExternal(this);
}
}
 else {
throw new InvalidObjectException("String_Node_Str");
}
}
 else if (obj instanceof Externalizable) {
throw new InvalidObjectException("String_Node_Str");
}
 else {
doReadSerialObject(descriptor,obj);
}
return obj;
}
case TC_EXCEPTION:
{
clearInstanceCache();
final IOException ex=(IOException)doReadObject(false);
throw new WriteAbortedException("String_Node_Str",ex);
}
case TC_BLOCKDATA:
case TC_BLOCKDATALONG:
{
blockUnmarshaller.readBlockHeader(leadByte);
throw createOptionalDataException(blockUnmarshaller.remaining());
}
case TC_ENDBLOCKDATA:
{
throw createOptionalDataException(0);
}
case TC_RESET:
{
if (depth > 1) {
throw new StreamCorruptedException("String_Node_Str");
}
clearInstanceCache();
leadByte=readByte() & 0xff;
continue;
}
default :
{
throw badLeadByte(leadByte);
}
}
}
  finally {
depth--;
}
}