Program: 51143
Project: 51143
Buggy source:
/** 
 * Generates the RSA-SHA1 signature of OAuth request elements.
 * @param elements the combined OAuth elements to sign.
 * @param secrets the secrets object containing the private key for generating the signature.
 * @return the OAuth signature, in base64-encoded form.
 * @throws InvalidSecretException if the supplied secret is not valid.
 */
public String sign(String elements,OAuthSecrets secrets) throws InvalidSecretException {
  Signature sig;
  try {
    sig=Signature.getInstance(SIGNATURE_ALGORITHM);
  }
 catch (  NoSuchAlgorithmException nsae) {
    throw new IllegalStateException(nsae);
  }
  byte[] decodedPrivKey;
  try {
    decodedPrivKey=Base64.decode(secrets.getConsumerSecret());
  }
 catch (  IOException ioe) {
    throw new InvalidSecretException("String_Node_Str");
  }
  KeyFactory keyf;
  try {
    keyf=KeyFactory.getInstance(KEY_TYPE);
  }
 catch (  NoSuchAlgorithmException nsae) {
    throw new IllegalStateException(nsae);
  }
  EncodedKeySpec keySpec=new PKCS8EncodedKeySpec(decodedPrivKey);
  RSAPrivateKey rsaPrivKey;
  try {
    rsaPrivKey=(RSAPrivateKey)keyf.generatePrivate(keySpec);
  }
 catch (  InvalidKeySpecException ikse) {
    throw new IllegalStateException(ikse);
  }
  try {
    sig.initSign(rsaPrivKey);
  }
 catch (  InvalidKeyException ike) {
    throw new IllegalStateException(ike);
  }
  try {
    sig.update(elements.getBytes());
  }
 catch (  SignatureException se) {
    throw new IllegalStateException(se);
  }
  byte[] rsasha1;
  try {
    rsasha1=sig.sign();
  }
 catch (  SignatureException se) {
    throw new IllegalStateException(se);
  }
  return UriComponent.encode(new String(Base64.encode(rsasha1)),UriComponent.Type.UNRESERVED);
}

Fixed version (ground truth):
/** 
 * Generates the RSA-SHA1 signature of OAuth request elements.
 * @param elements the combined OAuth elements to sign.
 * @param secrets the secrets object containing the private key for generating the signature.
 * @return the OAuth signature, in base64-encoded form.
 * @throws InvalidSecretException if the supplied secret is not valid.
 */
@Override public String sign(String elements,OAuthSecrets secrets) throws InvalidSecretException {
  Signature sig;
  try {
    sig=Signature.getInstance(SIGNATURE_ALGORITHM);
  }
 catch (  NoSuchAlgorithmException nsae) {
    throw new IllegalStateException(nsae);
  }
  byte[] decodedPrivKey;
  try {
    decodedPrivKey=Base64.decode(secrets.getConsumerSecret());
  }
 catch (  IOException ioe) {
    throw new InvalidSecretException("String_Node_Str");
  }
  KeyFactory keyf;
  try {
    keyf=KeyFactory.getInstance(KEY_TYPE);
  }
 catch (  NoSuchAlgorithmException nsae) {
    throw new IllegalStateException(nsae);
  }
  EncodedKeySpec keySpec=new PKCS8EncodedKeySpec(decodedPrivKey);
  RSAPrivateKey rsaPrivKey;
  try {
    rsaPrivKey=(RSAPrivateKey)keyf.generatePrivate(keySpec);
  }
 catch (  InvalidKeySpecException ikse) {
    throw new IllegalStateException(ikse);
  }
  try {
    sig.initSign(rsaPrivKey);
  }
 catch (  InvalidKeyException ike) {
    throw new IllegalStateException(ike);
  }
  try {
    sig.update(elements.getBytes());
  }
 catch (  SignatureException se) {
    throw new IllegalStateException(se);
  }
  byte[] rsasha1;
  try {
    rsasha1=sig.sign();
  }
 catch (  SignatureException se) {
    throw new IllegalStateException(se);
  }
  return Base64.encode(rsasha1);
}