{"record":{"id":"bde55d6b8776d5eb","repo":"GoogleContainerTools/jib","slug":"mismatch-between-image-manifest-and-container-conf","errorCode":null,"errorMessage":"Mismatch between image manifest and container configuration","messagePattern":"Mismatch between image manifest and container configuration","errorType":"exception","errorClass":"LayerCountMismatchException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java","lineNumber":126,"sourceCode":"      ContainerConfigurationTemplate containerConfigurationTemplate)\n      throws LayerCountMismatchException, LayerPropertyNotFoundException,\n          BadContainerConfigurationFormatException {\n    List<ReferenceNoDiffIdLayer> layers = new ArrayList<>();\n    for (BuildableManifestTemplate.ContentDescriptorTemplate layerObjectTemplate :\n        manifestTemplate.getLayers()) {\n      if (layerObjectTemplate.getDigest() == null) {\n        throw new IllegalArgumentException(\n            \"All layers in the manifest template must have digest set\");\n      }\n\n      layers.add(\n          new ReferenceNoDiffIdLayer(\n              new BlobDescriptor(layerObjectTemplate.getSize(), layerObjectTemplate.getDigest())));\n    }\n\n    List<DescriptorDigest> diffIds = containerConfigurationTemplate.getDiffIds();\n    if (layers.size() != diffIds.size()) {\n      throw new LayerCountMismatchException(\n          \"Mismatch between image manifest and container configuration\");\n    }\n\n    Image.Builder imageBuilder = Image.builder(manifestTemplate.getClass());\n\n    for (int layerIndex = 0; layerIndex < layers.size(); layerIndex++) {\n      ReferenceNoDiffIdLayer noDiffIdLayer = layers.get(layerIndex);\n      DescriptorDigest diffId = diffIds.get(layerIndex);\n\n      imageBuilder.addLayer(new ReferenceLayer(noDiffIdLayer.getBlobDescriptor(), diffId));\n    }\n\n    configureBuilderWithContainerConfiguration(imageBuilder, containerConfigurationTemplate);\n    return imageBuilder.build();\n  }\n\n  private static void configureBuilderWithContainerConfiguration(\n      Image.Builder imageBuilder, ContainerConfigurationTemplate containerConfigurationTemplate)","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java#L108-L144","documentation":"Jib keeps manifest layers and container-config diff IDs index-aligned: layer i's diff ID is diffIds[i]. toImage throws LayerCountMismatchException when their counts differ, because the pairing would be ambiguous.","triggerScenarios":"Calling JsonToImageTranslator.toImage with a manifest and a container configuration that come from different images, or with a truncated/corrupted config whose diffIds list length differs from the manifest layer count.","commonSituations":"Mixing manifest and config blobs fetched from different registries/tags; a retagged image whose config wasn't updated; hand-crafted test fixtures with mismatched layer counts; pulling a stale cached config after the image was pushed anew.","solutions":["Fetch the manifest and container configuration from the same image reference so their layer counts match","Verify manifest.getLayers().size() equals containerConfig.getDiffIds().size() before calling toImage","Clear stale cached config/manifest pairs and re-pull both from the registry"],"exampleFix":"// before\nImage image = JsonToImageTranslator.toImage(manifestA, configB); // from different tags\n// after\nif (manifestA.getLayers().size() != configB.getDiffIds().size()) {\n  throw new IllegalStateException(\"manifest/config mismatch; re-fetch both from same reference\");\n}\nImage image = JsonToImageTranslator.toImage(manifestA, configA);","handlingStrategy":"validation","validationCode":"if (manifestTemplate.getLayers().size() != containerConfigurationTemplate.getDiffIds().size())\n  throw new IllegalStateException(\"manifest layer count != config diff ID count; refetch both from same image\");","typeGuard":null,"tryCatchPattern":"try { JsonToImageTranslator.toImage(manifest, config); } catch (LayerCountMismatchException e) { /* re-pull manifest+config from the same tag */ }","preventionTips":["Always fetch manifest and container config from the same image digest/tag","Invalidate caches when an image is re-pushed under the same tag","Assert layer counts match before translation in tests"],"tags":["jib","manifest","container-config","layer-count"],"backgroundTag":"shape-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"}