Program: 154053
Project: 154053
Buggy source:
private void writeValues(TIFFField field) throws IOException {
  int dataType=field.getType();
  int count=field.getCount();
switch (dataType) {
case TIFFField.TIFF_BYTE:
case TIFFField.TIFF_SBYTE:
case TIFFField.TIFF_UNDEFINED:
    byte bytes[]=field.getAsBytes();
  for (int i=0; i < count; i++) {
    output.write(bytes[i]);
  }
break;
case TIFFField.TIFF_SHORT:
char shorts[]=field.getAsChars();
for (int i=0; i < count; i++) {
writeUnsignedShort(shorts[i]);
}
break;
case TIFFField.TIFF_SSHORT:
short sshorts[]=field.getAsShorts();
for (int i=0; i < count; i++) {
writeUnsignedShort(sshorts[i]);
}
break;
case TIFFField.TIFF_LONG:
long longs[]=field.getAsLongs();
for (int i=0; i < count; i++) {
writeLong(longs[i]);
}
break;
case TIFFField.TIFF_SLONG:
int slongs[]=field.getAsInts();
for (int i=0; i < count; i++) {
writeLong(slongs[i]);
}
break;
case TIFFField.TIFF_FLOAT:
float[] floats=field.getAsFloats();
for (int i=0; i < count; i++) {
int intBits=Float.floatToIntBits(floats[i]);
writeLong(intBits);
}
break;
case TIFFField.TIFF_DOUBLE:
double[] doubles=field.getAsDoubles();
for (int i=0; i < count; i++) {
long longBits=Double.doubleToLongBits(doubles[i]);
writeLong((int)(longBits >> 32));
writeLong((int)(longBits & 0xffffffff));
}
break;
case TIFFField.TIFF_RATIONAL:
long rationals[][]=field.getAsRationals();
for (int i=0; i < count; i++) {
writeLong(rationals[i][0]);
writeLong(rationals[i][1]);
}
break;
case TIFFField.TIFF_SRATIONAL:
int srationals[][]=field.getAsSRationals();
for (int i=0; i < count; i++) {
writeLong(srationals[i][0]);
writeLong(srationals[i][1]);
}
break;
case TIFFField.TIFF_ASCII:
for (int i=0; i < count; i++) {
byte[] stringBytes=field.getAsString(i).getBytes();
output.write(stringBytes);
if (stringBytes[stringBytes.length - 1] != (byte)0) {
output.write(0);
}
}
break;
default :
throw new Error(JaiI18N.getString("String_Node_Str"));
}
}

Fixed version (ground truth):
private void writeValues(TIFFField field) throws IOException {
  int dataType=field.getType();
  int count=field.getCount();
switch (dataType) {
case TIFFField.TIFF_BYTE:
case TIFFField.TIFF_SBYTE:
case TIFFField.TIFF_UNDEFINED:
    byte bytes[]=field.getAsBytes();
  for (int i=0; i < count; i++) {
    output.write(bytes[i]);
  }
break;
case TIFFField.TIFF_SHORT:
char shorts[]=field.getAsChars();
for (int i=0; i < count; i++) {
writeUnsignedShort(shorts[i]);
}
break;
case TIFFField.TIFF_SSHORT:
short sshorts[]=field.getAsShorts();
for (int i=0; i < count; i++) {
writeUnsignedShort(sshorts[i]);
}
break;
case TIFFField.TIFF_LONG:
long longs[]=field.getAsLongs();
for (int i=0; i < count; i++) {
writeLong(longs[i]);
}
break;
case TIFFField.TIFF_SLONG:
int slongs[]=field.getAsInts();
for (int i=0; i < count; i++) {
writeLong(slongs[i]);
}
break;
case TIFFField.TIFF_FLOAT:
float[] floats=field.getAsFloats();
for (int i=0; i < count; i++) {
int intBits=Float.floatToIntBits(floats[i]);
writeLong(intBits);
}
break;
case TIFFField.TIFF_DOUBLE:
double[] doubles=field.getAsDoubles();
for (int i=0; i < count; i++) {
long longBits=Double.doubleToLongBits(doubles[i]);
writeLong((int)(longBits >> 32));
writeLong((int)(longBits & 0xffffffff));
}
break;
case TIFFField.TIFF_RATIONAL:
long rationals[][]=field.getAsRationals();
for (int i=0; i < count; i++) {
writeLong(rationals[i][0]);
writeLong(rationals[i][1]);
}
break;
case TIFFField.TIFF_SRATIONAL:
int srationals[][]=field.getAsSRationals();
for (int i=0; i < count; i++) {
writeLong(srationals[i][0]);
writeLong(srationals[i][1]);
}
break;
case TIFFField.TIFF_ASCII:
for (int i=0; i < count; i++) {
byte[] stringBytes=field.getAsString(i).getBytes();
output.write(stringBytes);
if (stringBytes[stringBytes.length - 1] != (byte)0) {
output.write(0);
}
}
break;
default :
throw new RuntimeException(JaiI18N.getString("String_Node_Str"));
}
}