{"record":{"id":"00c247cecc201ad4","repo":"GoogleContainerTools/jib","slug":"invalid-hash-hash","errorCode":null,"errorMessage":"Invalid hash: ${hash}","messagePattern":"Invalid hash: (.+?)","errorType":"exception","errorClass":"DigestException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/api/DescriptorDigest.java","lineNumber":59,"sourceCode":"\n  /** The algorithm prefix for the digest string. */\n  private static final String DIGEST_PREFIX = \"sha256:\";\n\n  /** Pattern matches a SHA-256 digest - a SHA-256 hash prefixed with \"sha256:\". */\n  static final String DIGEST_REGEX = DIGEST_PREFIX + HASH_REGEX;\n\n  private final String hash;\n\n  /**\n   * Creates a new instance from a valid hash string.\n   *\n   * @param hash the hash to generate the {@link DescriptorDigest} from\n   * @return a new {@link DescriptorDigest} created from the hash\n   * @throws DigestException if the hash is invalid\n   */\n  public static DescriptorDigest fromHash(String hash) throws DigestException {\n    if (!hash.matches(HASH_REGEX)) {\n      throw new DigestException(\"Invalid hash: \" + hash);\n    }\n\n    return new DescriptorDigest(hash);\n  }\n\n  /**\n   * Creates a new instance from a valid digest string.\n   *\n   * @param digest the digest to generate the {@link DescriptorDigest} from\n   * @return a new {@link DescriptorDigest} created from the digest\n   * @throws DigestException if the digest is invalid\n   */\n  public static DescriptorDigest fromDigest(String digest) throws DigestException {\n    if (!digest.matches(DIGEST_REGEX)) {\n      throw new DigestException(\"Invalid digest: \" + digest);\n    }\n\n    // Extracts the hash portion of the digest.","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/api/DescriptorDigest.java#L41-L77","documentation":"DescriptorDigest.fromHash validates that a hash string is exactly a 64-character lowercase hex SHA-256 digest. Non-conforming strings throw DigestException. This guards digest integrity for layer/image descriptors.","triggerScenarios":"Calling DescriptorDigest.fromHash with a string failing HASH_REGEX — wrong length, uppercase hex, non-hex characters, or a digest string containing an algorithm prefix like \"sha256:abc...\".","commonSituations":"Parsing registry API responses where the digest includes the \"sha256:\" prefix; reading digests from logs/files with whitespace or formatting; truncating or hand-editing digests in tests.","solutions":["Strip the \"sha256:\" prefix before calling fromHash (use fromDigest for prefixed strings if available)","Trim whitespace and ensure the hash is exactly 64 lowercase hex characters","Check the source of the hash — a corrupted/truncated value must be re-fetched from the registry"],"exampleFix":"// before\nDescriptorDigest d = DescriptorDigest.fromHash(digestString); // \"sha256:abc...\"\n// after\nDescriptorDigest d = digestString.contains(\":\")\n    ? DescriptorDigest.fromDigest(digestString)\n    : DescriptorDigest.fromHash(digestString);","handlingStrategy":"validation","validationCode":"boolean isValidSha256(String s) { return s != null && s.matches(\"[0-9a-f]{64}\"); }","typeGuard":"DescriptorDigest safeFromHash(String s) throws DigestException { return (s != null && s.matches(\"[0-9a-f]{64}\")) ? DescriptorDigest.fromHash(s) : DescriptorDigest.fromDigest(s); }","tryCatchPattern":"try { digest = DescriptorDigest.fromHash(hash); } catch (DigestException e) { digest = DescriptorDigest.fromDigest(normalize(hash)); }","preventionTips":["Strip algorithm prefixes (\"sha256:\") before fromHash","Trim and lowercase hashes sourced from logs or external files","Use fromDigest for registry-style digest strings"],"tags":["jib","digest","sha256","validation"],"backgroundTag":"checksum-mismatch","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}