Program: 135659
Project: 135659
Buggy source:
public String encodePublicKey(PublicKey publicKey) throws IOException {
  String publicKeyEncoded;
  ByteArrayOutputStream byteOs=new ByteArrayOutputStream();
  if (publicKey.getAlgorithm().equals(KEY_FACTORY_TYPE_RSA)) {
    RSAPublicKey rsaPublicKey=(RSAPublicKey)publicKey;
    DataOutputStream dataOutputStream=new DataOutputStream(byteOs);
    dataOutputStream.writeInt(KEY_TYPE_RSA.getBytes().length);
    dataOutputStream.write(KEY_TYPE_RSA.getBytes());
    dataOutputStream.writeInt(rsaPublicKey.getPublicExponent().toByteArray().length);
    dataOutputStream.write(rsaPublicKey.getPublicExponent().toByteArray());
    dataOutputStream.writeInt(rsaPublicKey.getModulus().toByteArray().length);
    dataOutputStream.write(rsaPublicKey.getModulus().toByteArray());
  }
 else   if (publicKey.getAlgorithm().equals(KEY_FACTORY_TYPE_DSA)) {
    DSAPublicKey dsaPublicKey=(DSAPublicKey)publicKey;
    DSAParams dsaParams=dsaPublicKey.getParams();
    DataOutputStream dataOutputStream=new DataOutputStream(byteOs);
    dataOutputStream.writeInt(KEY_TYPE_DSA.getBytes().length);
    dataOutputStream.write(KEY_TYPE_DSA.getBytes());
    dataOutputStream.writeInt(dsaParams.getP().toByteArray().length);
    dataOutputStream.write(dsaParams.getP().toByteArray());
    dataOutputStream.writeInt(dsaParams.getQ().toByteArray().length);
    dataOutputStream.write(dsaParams.getQ().toByteArray());
    dataOutputStream.writeInt(dsaParams.getG().toByteArray().length);
    dataOutputStream.write(dsaParams.getG().toByteArray());
    dataOutputStream.writeInt(dsaPublicKey.getY().toByteArray().length);
    dataOutputStream.write(dsaPublicKey.getY().toByteArray());
  }
 else   if (publicKey.getAlgorithm().equals(KEY_FACTORY_TYPE_ECDSA)) {
    BCECPublicKey ecPublicKey=(BCECPublicKey)publicKey;
    DataOutputStream dataOutputStream=new DataOutputStream(byteOs);
    dataOutputStream.writeInt(KEY_TYPE_ECDSA.getBytes().length);
    dataOutputStream.write(KEY_TYPE_ECDSA.getBytes());
    dataOutputStream.writeInt(ECDSA_SUPPORTED_CURVE_NAME.getBytes().length);
    dataOutputStream.write(ECDSA_SUPPORTED_CURVE_NAME.getBytes());
    byte[] affineXCoord=ecPublicKey.getQ().getAffineXCoord().getEncoded();
    byte[] affineYCoord=ecPublicKey.getQ().getAffineYCoord().getEncoded();
    dataOutputStream.writeInt(affineXCoord.length + affineYCoord.length + 1);
    dataOutputStream.writeByte(0x04);
    dataOutputStream.write(affineXCoord);
    dataOutputStream.write(affineYCoord);
  }
 else {
    throw new IllegalArgumentException("String_Node_Str" + publicKey.getAlgorithm());
  }
  publicKeyEncoded=new String(Base64.getEncoder().encodeToString(byteOs.toByteArray()));
  return publicKeyEncoded;
}

Fixed version (ground truth):
public String encodePublicKey(PublicKey publicKey) throws IOException {
  ByteArrayOutputStream byteOs=new ByteArrayOutputStream();
  if (publicKey instanceof RSAPublicKey && publicKey.getAlgorithm().equals(KEY_FACTORY_TYPE_RSA)) {
    RSAPublicKey rsaPublicKey=(RSAPublicKey)publicKey;
    DataOutputStream dataOutputStream=new DataOutputStream(byteOs);
    dataOutputStream.writeInt(KEY_TYPE_RSA.getBytes(StandardCharsets.UTF_8).length);
    dataOutputStream.write(KEY_TYPE_RSA.getBytes(StandardCharsets.UTF_8));
    dataOutputStream.writeInt(rsaPublicKey.getPublicExponent().toByteArray().length);
    dataOutputStream.write(rsaPublicKey.getPublicExponent().toByteArray());
    dataOutputStream.writeInt(rsaPublicKey.getModulus().toByteArray().length);
    dataOutputStream.write(rsaPublicKey.getModulus().toByteArray());
  }
 else   if (publicKey instanceof DSAPublicKey && publicKey.getAlgorithm().equals(KEY_FACTORY_TYPE_DSA)) {
    DSAPublicKey dsaPublicKey=(DSAPublicKey)publicKey;
    DSAParams dsaParams=dsaPublicKey.getParams();
    DataOutputStream dataOutputStream=new DataOutputStream(byteOs);
    dataOutputStream.writeInt(KEY_TYPE_DSA.getBytes(StandardCharsets.UTF_8).length);
    dataOutputStream.write(KEY_TYPE_DSA.getBytes(StandardCharsets.UTF_8));
    dataOutputStream.writeInt(dsaParams.getP().toByteArray().length);
    dataOutputStream.write(dsaParams.getP().toByteArray());
    dataOutputStream.writeInt(dsaParams.getQ().toByteArray().length);
    dataOutputStream.write(dsaParams.getQ().toByteArray());
    dataOutputStream.writeInt(dsaParams.getG().toByteArray().length);
    dataOutputStream.write(dsaParams.getG().toByteArray());
    dataOutputStream.writeInt(dsaPublicKey.getY().toByteArray().length);
    dataOutputStream.write(dsaPublicKey.getY().toByteArray());
  }
 else   if (publicKey instanceof BCECPublicKey && publicKey.getAlgorithm().equals(KEY_FACTORY_TYPE_ECDSA)) {
    BCECPublicKey ecPublicKey=(BCECPublicKey)publicKey;
    DataOutputStream dataOutputStream=new DataOutputStream(byteOs);
    dataOutputStream.writeInt(KEY_TYPE_ECDSA.getBytes(StandardCharsets.UTF_8).length);
    dataOutputStream.write(KEY_TYPE_ECDSA.getBytes(StandardCharsets.UTF_8));
    dataOutputStream.writeInt(ECDSA_SUPPORTED_CURVE_NAME.getBytes(StandardCharsets.UTF_8).length);
    dataOutputStream.write(ECDSA_SUPPORTED_CURVE_NAME.getBytes(StandardCharsets.UTF_8));
    byte[] affineXCoord=ecPublicKey.getQ().getAffineXCoord().getEncoded();
    byte[] affineYCoord=ecPublicKey.getQ().getAffineYCoord().getEncoded();
    dataOutputStream.writeInt(affineXCoord.length + affineYCoord.length + 1);
    dataOutputStream.writeByte(0x04);
    dataOutputStream.write(affineXCoord);
    dataOutputStream.write(affineYCoord);
  }
 else {
    throw new IllegalArgumentException("String_Node_Str" + publicKey.getAlgorithm());
  }
  return Base64.getEncoder().encodeToString(byteOs.toByteArray());
}