{"record":{"id":"613cd30ff046da63","repo":"GoogleContainerTools/jib","slug":"field-is-required-but-not-set","errorCode":null,"errorMessage":"<field> is required but not set","messagePattern":"<field> is required but not set","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/configuration/BuildContext.java","lineNumber":349,"sourceCode":"              targetFormat,\n              offline,\n              layerConfigurations,\n              toolName,\n              toolVersion,\n              eventHandlers,\n              // TODO: try setting global User-Agent: here\n              new FailoverHttpClient(\n                  allowInsecureRegistries,\n                  JibSystemProperties.sendCredentialsOverHttp(),\n                  eventHandlers::dispatch),\n              executorService == null ? Executors.newCachedThreadPool() : executorService,\n              executorService == null, // shutDownExecutorService\n              alwaysCacheBaseImage,\n              registryMirrors,\n              enablePlatformTags);\n\n        case 1:\n          throw new IllegalStateException(missingFields.get(0) + \" is required but not set\");\n\n        case 2:\n          throw new IllegalStateException(\n              missingFields.get(0) + \" and \" + missingFields.get(1) + \" are required but not set\");\n\n        default:\n          missingFields.add(\"and \" + missingFields.remove(missingFields.size() - 1));\n          StringJoiner errorMessage = new StringJoiner(\", \", \"\", \" are required but not set\");\n          for (String missingField : missingFields) {\n            errorMessage.add(missingField);\n          }\n          throw new IllegalStateException(errorMessage.toString());\n      }\n    }\n\n    @Nullable\n    @VisibleForTesting\n    Path getBaseImageLayersCacheDirectory() {","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/configuration/BuildContext.java#L331-L367","documentation":"BuildContext.Builder.build() collects builder fields that were not set into a missingFields list and throws IllegalStateException naming them — one field: \"<field> is required but not set\". This is Jib's internal guard that a fully-specified build configuration (target image, credentials, etc.) exists before the build runs.","triggerScenarios":"BuildContext.build() is invoked with exactly one unset required builder field (missingFields.size() == 1) — e.g. target image, credential retrievers, or container configuration omitted from the Jib extension/plugin or the Jib Core API builder.","commonSituations":"Programmatic Jib Core/Lib usage where a builder field was forgotten; Maven/Gradle plugin misconfiguration where <to><image> or auth is absent; missing settings causing downstream nulls.","solutions":["Set the field named in the message on the BuildContext.Builder (e.g. .setTargetImage(...)) before calling build()","In Maven/Gradle, configure the missing jib parameter (commonly to.image)","Check the ordering: setters called after build() do not apply","If using plugin extensions/profiles, ensure the active profile defines the required jib values"],"exampleFix":"// before\nBuildContext builder = ...; // setTargetImage never called\nBuildContext context = builder.build();\n// after\nbuilder.setTargetImage(RegistryImage.named(\"gcr.io/project/app\"));\nBuildContext context = builder.build();","handlingStrategy":"validation","validationCode":"List<String> missing = new ArrayList<>();\nif (targetImage == null) missing.add(\"target image\");\nif (credentialRetrievers.isEmpty()) missing.add(\"credential retrievers\");\nif (!missing.isEmpty()) throw new IllegalStateException(missing + \" must be set before build()\");","typeGuard":"static <T> T requireSet(T v, String name) {\n  if (v == null) throw new IllegalStateException(name + \" is required but not set\");\n  return v;\n}","tryCatchPattern":"try {\n  BuildContext ctx = builder.build();\n} catch (IllegalStateException e) {\n  if (e.getMessage().endsWith(\"is required but not set\")) {\n    throw new ConfigurationException(\"Jib misconfiguration: \" + e.getMessage());\n  }\n  throw e;\n}","preventionTips":["Build a single factory method that sets every required builder field","In Maven/Gradle, validate jib.to.image is configured before running goals","Call build() only after all setters; don't mutate the builder afterwards"],"tags":["configuration","builder","validation"],"backgroundTag":"missing-required-config-field","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"}