Program: 77439
Project: 77439
Buggy source:
/** 
 * Returns a hexadecimal string representation of the  {@code double} argument. All characters mentioned beloware ASCII characters. <ul> <li>If the argument is NaN, the result is the string " {@code NaN}". <li>Otherwise, the result is a string that represents the sign and magnitude of the argument. If the sign is negative, the first character of the result is '  {@code -}' (  {@code '\u005Cu002D'}); if the sign is positive, no sign character appears in the result. As for the magnitude <i>m</i>: <ul> <li>If <i>m</i> is infinity, it is represented by the string  {@code "Infinity"}; thus, positive infinity produces the result   {@code "Infinity"} and negative infinity producesthe result  {@code "-Infinity"}. <li>If <i>m</i> is zero, it is represented by the string  {@code "0x0.0p0"}; thus, negative zero produces the result  {@code "-0x0.0p0"} and positive zero produces the result{@code "0x0.0p0"}. <li>If <i>m</i> is a   {@code double} value with anormalized representation, substrings are used to represent the significand and exponent fields.  The significand is represented by the characters  {@code "0x1."}followed by a lowercase hexadecimal representation of the rest of the significand as a fraction.  Trailing zeros in the hexadecimal representation are removed unless all the digits are zero, in which case a single zero is used. Next, the exponent is represented by   {@code "p"} followedby a decimal string of the unbiased exponent as if produced by a call to  {@link Integer#toString(int) Integer.toString} on theexponent value. <li>If <i>m</i> is a  {@code double} value with a subnormalrepresentation, the significand is represented by the characters  {@code "0x0."} followed by ahexadecimal representation of the rest of the significand as a fraction.  Trailing zeros in the hexadecimal representation are removed. Next, the exponent is represented by {@code "p-1022"}.  Note that there must be at least one nonzero digit in a subnormal significand. </ul> </ul> <table border> <caption><h3>Examples</h3></caption> <tr><th>Floating-point Value</th><th>Hexadecimal String</th> <tr><td>  {@code 1.0}</td> <td>  {@code 0x1.0p0}</td> <tr><td>  {@code -1.0}</td>        <td>  {@code -0x1.0p0}</td> <tr><td>  {@code 2.0}</td> <td>  {@code 0x1.0p1}</td> <tr><td>  {@code 3.0}</td> <td>  {@code 0x1.8p1}</td> <tr><td>  {@code 0.5}</td> <td>  {@code 0x1.0p-1}</td> <tr><td>  {@code 0.25}</td>        <td>  {@code 0x1.0p-2}</td> <tr><td>  {@code Double.MAX_VALUE}</td> <td>  {@code 0x1.fffffffffffffp1023}</td> <tr><td>  {@code Minimum Normal Value}</td> <td>  {@code 0x1.0p-1022}</td> <tr><td>  {@code Maximum Subnormal Value}</td> <td>  {@code 0x0.fffffffffffffp-1022}</td> <tr><td>  {@code Double.MIN_VALUE}</td> <td>  {@code 0x0.0000000000001p-1022}</td> </table>
 * @param d   the {@code double} to be converted.
 * @return a hex string representation of the argument.
 * @since 1.5
 * @author Joseph D. Darcy
 */
public static String toHexString(double d){
  if (!isFinite(d))   return Double.toString(d);
 else {
    StringBuilder answer=new StringBuilder(24);
    if (Math.copySign(1.0,d) == -1.0)     answer.append("String_Node_Str");
    answer.append("String_Node_Str");
    d=Math.abs(d);
    if (d == 0.0) {
      answer.append("String_Node_Str");
    }
 else {
      boolean subnormal=(d < DoubleConsts.MIN_NORMAL);
      long signifBits=(Double.doubleToLongBits(d) & DoubleConsts.SIGNIF_BIT_MASK) | 0x1000000000000000L;
      answer.append(subnormal ? "String_Node_Str" : "String_Node_Str");
      String signif=Long.toHexString(signifBits).substring(3,16);
      answer.append(signif.equals("String_Node_Str") ? "String_Node_Str" : signif.replaceFirst("String_Node_Str","String_Node_Str"));
      answer.append('p');
      answer.append(subnormal ? DoubleConsts.MIN_EXPONENT : Math.getExponent(d));
    }
    return answer.toString();
  }
}

Fixed version (ground truth):
/** 
 * Returns a hexadecimal string representation of the  {@code double} argument. All characters mentioned beloware ASCII characters. <ul> <li>If the argument is NaN, the result is the string " {@code NaN}". <li>Otherwise, the result is a string that represents the sign and magnitude of the argument. If the sign is negative, the first character of the result is '  {@code -}' (  {@code '\u005Cu002D'}); if the sign is positive, no sign character appears in the result. As for the magnitude <i>m</i>: <ul> <li>If <i>m</i> is infinity, it is represented by the string  {@code "Infinity"}; thus, positive infinity produces the result   {@code "Infinity"} and negative infinity producesthe result  {@code "-Infinity"}. <li>If <i>m</i> is zero, it is represented by the string  {@code "0x0.0p0"}; thus, negative zero produces the result  {@code "-0x0.0p0"} and positive zero produces the result{@code "0x0.0p0"}. <li>If <i>m</i> is a   {@code double} value with anormalized representation, substrings are used to represent the significand and exponent fields.  The significand is represented by the characters  {@code "0x1."}followed by a lowercase hexadecimal representation of the rest of the significand as a fraction.  Trailing zeros in the hexadecimal representation are removed unless all the digits are zero, in which case a single zero is used. Next, the exponent is represented by   {@code "p"} followedby a decimal string of the unbiased exponent as if produced by a call to  {@link Integer#toString(int) Integer.toString} on theexponent value. <li>If <i>m</i> is a  {@code double} value with a subnormalrepresentation, the significand is represented by the characters  {@code "0x0."} followed by ahexadecimal representation of the rest of the significand as a fraction.  Trailing zeros in the hexadecimal representation are removed. Next, the exponent is represented by {@code "p-1022"}.  Note that there must be at least one nonzero digit in a subnormal significand. </ul> </ul> <table border> <caption>Examples</caption> <tr><th>Floating-point Value</th><th>Hexadecimal String</th> <tr><td>  {@code 1.0}</td> <td>  {@code 0x1.0p0}</td> <tr><td>  {@code -1.0}</td>        <td>  {@code -0x1.0p0}</td> <tr><td>  {@code 2.0}</td> <td>  {@code 0x1.0p1}</td> <tr><td>  {@code 3.0}</td> <td>  {@code 0x1.8p1}</td> <tr><td>  {@code 0.5}</td> <td>  {@code 0x1.0p-1}</td> <tr><td>  {@code 0.25}</td>        <td>  {@code 0x1.0p-2}</td> <tr><td>  {@code Double.MAX_VALUE}</td> <td>  {@code 0x1.fffffffffffffp1023}</td> <tr><td>  {@code Minimum Normal Value}</td> <td>  {@code 0x1.0p-1022}</td> <tr><td>  {@code Maximum Subnormal Value}</td> <td>  {@code 0x0.fffffffffffffp-1022}</td> <tr><td>  {@code Double.MIN_VALUE}</td> <td>  {@code 0x0.0000000000001p-1022}</td> </table>
 * @param d   the {@code double} to be converted.
 * @return a hex string representation of the argument.
 * @since 1.5
 * @author Joseph D. Darcy
 */
public static String toHexString(double d){
  if (!isFinite(d))   return Double.toString(d);
 else {
    StringBuilder answer=new StringBuilder(24);
    if (Math.copySign(1.0,d) == -1.0)     answer.append("String_Node_Str");
    answer.append("String_Node_Str");
    d=Math.abs(d);
    if (d == 0.0) {
      answer.append("String_Node_Str");
    }
 else {
      boolean subnormal=(d < DoubleConsts.MIN_NORMAL);
      long signifBits=(Double.doubleToLongBits(d) & DoubleConsts.SIGNIF_BIT_MASK) | 0x1000000000000000L;
      answer.append(subnormal ? "String_Node_Str" : "String_Node_Str");
      String signif=Long.toHexString(signifBits).substring(3,16);
      answer.append(signif.equals("String_Node_Str") ? "String_Node_Str" : signif.replaceFirst("String_Node_Str","String_Node_Str"));
      answer.append('p');
      answer.append(subnormal ? DoubleConsts.MIN_EXPONENT : Math.getExponent(d));
    }
    return answer.toString();
  }
}