Program: 72491
Project: 72491
Buggy source:
/** 
 * This generic method call the   {@link EncodingHelpers} API or the{@link MessageBuffer} API provided by CERTI to handle data encodingoperation for updated value of HLA attribute that will be published to the federation.
 * @param hp The HLA publisher actor which sends the HLA attribute value.
 * @param tok The token to encode, i.e. the HLA attribute value to encode.
 * @return The encoded value as an array of byte.
 * @throws IllegalActionException If the token is not handled or theencoding has failed.
 */
public static byte[] encodeHlaValue(HlaPublisher hp,Token tok) throws IllegalActionException {
  byte[] encodedValue=null;
  Token t=null;
  double recordTimestamp=-1.0;
  int recordMicrostep=-1;
  double sourceTimestamp=-1.0;
  t=tok;
  BaseType type=(BaseType)t.getType();
  if (hp.useCertiMessageBuffer()) {
    ByteArrayOutputStream bos=new ByteArrayOutputStream();
    MessageBuffer msgBuffer=new MessageBuffer(null,bos);
    if (type.equals(BaseType.BOOLEAN)) {
      msgBuffer.write(((BooleanToken)t).booleanValue());
    }
 else     if (type.equals(BaseType.UNSIGNED_BYTE)) {
      msgBuffer.write(((UnsignedByteToken)t).byteValue());
    }
 else     if (type.equals(BaseType.DOUBLE)) {
      msgBuffer.write(((DoubleToken)t).doubleValue());
    }
 else     if (type.equals(BaseType.FLOAT)) {
      msgBuffer.write(((FloatToken)t).floatValue());
    }
 else     if (type.equals(BaseType.INT)) {
      msgBuffer.write(((IntToken)t).intValue());
    }
 else     if (type.equals(BaseType.LONG)) {
      msgBuffer.write(((LongToken)t).longValue());
    }
 else     if (type.equals(BaseType.SHORT)) {
      msgBuffer.write(((ShortToken)t).shortValue());
    }
 else     if (type.equals(BaseType.STRING)) {
      msgBuffer.write(((StringToken)t).stringValue());
    }
 else {
      throw new IllegalActionException("String_Node_Str" + t + "String_Node_Str");
    }
    try {
      msgBuffer.send();
    }
 catch (    IOException e) {
      throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + e.getMessage());
    }
    encodedValue=bos.toByteArray();
    return encodedValue;
  }
  if (type.equals(BaseType.BOOLEAN)) {
    encodedValue=EncodingHelpers.encodeBoolean(((BooleanToken)t).booleanValue());
  }
 else   if (type.equals(BaseType.UNSIGNED_BYTE)) {
    encodedValue=EncodingHelpers.encodeByte(((UnsignedByteToken)t).byteValue());
  }
 else   if (type.equals(BaseType.DOUBLE)) {
    encodedValue=EncodingHelpers.encodeDouble(((DoubleToken)t).doubleValue());
  }
 else   if (type.equals(BaseType.FLOAT)) {
    encodedValue=EncodingHelpers.encodeFloat(((FloatToken)t).floatValue());
  }
 else   if (type.equals(BaseType.INT)) {
    encodedValue=EncodingHelpers.encodeInt(((IntToken)t).intValue());
  }
 else   if (type.equals(BaseType.LONG)) {
    encodedValue=EncodingHelpers.encodeLong(((LongToken)t).longValue());
  }
 else   if (type.equals(BaseType.SHORT)) {
    encodedValue=EncodingHelpers.encodeShort(((ShortToken)t).shortValue());
  }
 else   if (type.equals(BaseType.STRING)) {
    encodedValue=EncodingHelpers.encodeString(((StringToken)t).stringValue());
  }
 else {
    throw new IllegalActionException("String_Node_Str" + t + "String_Node_Str");
  }
  return encodedValue;
}

Fixed version (ground truth):
/** 
 * This generic method call the   {@link EncodingHelpers} API or the{@link MessageBuffer} API provided by CERTI to handle data encodingoperation for updated value of HLA attribute that will be published to the federation.
 * @param hp The HLA publisher actor which sends the HLA attribute value.
 * @param tok The token to encode, i.e. the HLA attribute value to encode.
 * @return The encoded value as an array of byte.
 * @exception IllegalActionException If the token is not handled or theencoding has failed.
 */
public static byte[] encodeHlaValue(HlaPublisher hp,Token tok) throws IllegalActionException {
  byte[] encodedValue=null;
  Token t=null;
  double recordTimestamp=-1.0;
  int recordMicrostep=-1;
  double sourceTimestamp=-1.0;
  t=tok;
  BaseType type=(BaseType)t.getType();
  if (hp.useCertiMessageBuffer()) {
    ByteArrayOutputStream bos=new ByteArrayOutputStream();
    MessageBuffer msgBuffer=new MessageBuffer(null,bos);
    if (type.equals(BaseType.BOOLEAN)) {
      msgBuffer.write(((BooleanToken)t).booleanValue());
    }
 else     if (type.equals(BaseType.UNSIGNED_BYTE)) {
      msgBuffer.write(((UnsignedByteToken)t).byteValue());
    }
 else     if (type.equals(BaseType.DOUBLE)) {
      msgBuffer.write(((DoubleToken)t).doubleValue());
    }
 else     if (type.equals(BaseType.FLOAT)) {
      msgBuffer.write(((FloatToken)t).floatValue());
    }
 else     if (type.equals(BaseType.INT)) {
      msgBuffer.write(((IntToken)t).intValue());
    }
 else     if (type.equals(BaseType.LONG)) {
      msgBuffer.write(((LongToken)t).longValue());
    }
 else     if (type.equals(BaseType.SHORT)) {
      msgBuffer.write(((ShortToken)t).shortValue());
    }
 else     if (type.equals(BaseType.STRING)) {
      msgBuffer.write(((StringToken)t).stringValue());
    }
 else {
      throw new IllegalActionException("String_Node_Str" + t + "String_Node_Str");
    }
    try {
      msgBuffer.send();
    }
 catch (    IOException e) {
      throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + e.getMessage());
    }
    encodedValue=bos.toByteArray();
    return encodedValue;
  }
  if (type.equals(BaseType.BOOLEAN)) {
    encodedValue=EncodingHelpers.encodeBoolean(((BooleanToken)t).booleanValue());
  }
 else   if (type.equals(BaseType.UNSIGNED_BYTE)) {
    encodedValue=EncodingHelpers.encodeByte(((UnsignedByteToken)t).byteValue());
  }
 else   if (type.equals(BaseType.DOUBLE)) {
    encodedValue=EncodingHelpers.encodeDouble(((DoubleToken)t).doubleValue());
  }
 else   if (type.equals(BaseType.FLOAT)) {
    encodedValue=EncodingHelpers.encodeFloat(((FloatToken)t).floatValue());
  }
 else   if (type.equals(BaseType.INT)) {
    encodedValue=EncodingHelpers.encodeInt(((IntToken)t).intValue());
  }
 else   if (type.equals(BaseType.LONG)) {
    encodedValue=EncodingHelpers.encodeLong(((LongToken)t).longValue());
  }
 else   if (type.equals(BaseType.SHORT)) {
    encodedValue=EncodingHelpers.encodeShort(((ShortToken)t).shortValue());
  }
 else   if (type.equals(BaseType.STRING)) {
    encodedValue=EncodingHelpers.encodeString(((StringToken)t).stringValue());
  }
 else {
    throw new IllegalActionException("String_Node_Str" + t + "String_Node_Str");
  }
  return encodedValue;
}