Program: 31342
Project: 31342
Buggy source:
/** 
 * Test <i>portable</i> serialization. 
 */
@Test public final void testPortableSerialization(){
  System.err.println("String_Node_Str");
  String filename="String_Node_Str";
  File serializedFile=new File(filename);
  serializedFile.delete();
  CipherSpec cipherSpec=new CipherSpec(encryptor,256);
  cipherSpec.setIV(ivSpec.getIV());
  SecretKey key;
  try {
    key=CryptoHelper.generateSecretKey(cipherSpec.getCipherAlgorithm(),256);
    encryptor.init(Cipher.ENCRYPT_MODE,key,ivSpec);
    byte[] raw=encryptor.doFinal("String_Node_Str".getBytes("String_Node_Str"));
    CipherText ciphertext=new CipherText(cipherSpec,raw);
    SecretKey authKey=CryptoHelper.computeDerivedKey(key,key.getEncoded().length * 8,"String_Node_Str");
    ciphertext.computeAndStoreMAC(authKey);
    byte[] serializedBytes=ciphertext.asPortableSerializedByteArray();
    FileOutputStream fos=new FileOutputStream(serializedFile);
    fos.write(serializedBytes);
    fos.close();
    FileInputStream fis=new FileInputStream(serializedFile);
    int avail=fis.available();
    byte[] bytes=new byte[avail];
    fis.read(bytes,0,avail);
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
      ;
    }
    CipherText restoredCipherText=CipherText.fromPortableSerializedBytes(bytes);
    assertTrue(ciphertext.equals(restoredCipherText));
  }
 catch (  EncryptionException e) {
    Assert.fail("String_Node_Str" + e);
  }
catch (  FileNotFoundException e) {
    Assert.fail("String_Node_Str" + e);
  }
catch (  IOException e) {
    Assert.fail("String_Node_Str" + e);
  }
catch (  Exception e) {
    Assert.fail("String_Node_Str" + e);
  }
 finally {
    serializedFile.delete();
  }
}

Fixed version (ground truth):
/** 
 * Test <i>portable</i> serialization. 
 */
@Test public final void testPortableSerialization(){
  System.err.println("String_Node_Str");
  String filename="String_Node_Str";
  File serializedFile=new File(filename);
  serializedFile.delete();
  int keySize=128;
  if (CryptoPolicy.isUnlimitedStrengthCryptoAvailable()) {
    keySize=256;
  }
  CipherSpec cipherSpec=new CipherSpec(encryptor,keySize);
  cipherSpec.setIV(ivSpec.getIV());
  SecretKey key;
  try {
    key=CryptoHelper.generateSecretKey(cipherSpec.getCipherAlgorithm(),keySize);
    encryptor.init(Cipher.ENCRYPT_MODE,key,ivSpec);
    byte[] raw=encryptor.doFinal("String_Node_Str".getBytes("String_Node_Str"));
    CipherText ciphertext=new CipherText(cipherSpec,raw);
    SecretKey authKey=CryptoHelper.computeDerivedKey(key,key.getEncoded().length * 8,"String_Node_Str");
    ciphertext.computeAndStoreMAC(authKey);
    byte[] serializedBytes=ciphertext.asPortableSerializedByteArray();
    FileOutputStream fos=new FileOutputStream(serializedFile);
    fos.write(serializedBytes);
    fos.close();
    FileInputStream fis=new FileInputStream(serializedFile);
    int avail=fis.available();
    byte[] bytes=new byte[avail];
    fis.read(bytes,0,avail);
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
      ;
    }
    CipherText restoredCipherText=CipherText.fromPortableSerializedBytes(bytes);
    assertTrue(ciphertext.equals(restoredCipherText));
  }
 catch (  EncryptionException e) {
    Assert.fail("String_Node_Str" + e);
  }
catch (  FileNotFoundException e) {
    Assert.fail("String_Node_Str" + e);
  }
catch (  IOException e) {
    Assert.fail("String_Node_Str" + e);
  }
catch (  Exception e) {
    Assert.fail("String_Node_Str" + e);
  }
 finally {
    serializedFile.delete();
  }
}