{"record":{"id":"2059c80270ac93f2","repo":"GoogleContainerTools/jib","slug":"field1-and-field2-are-required-but-not-set","errorCode":null,"errorMessage":"<field1> and <field2> are required but not set","messagePattern":"<field1> and <field2> are 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":352,"sourceCode":"              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() {\n      return baseImageLayersCacheDirectory;\n    }\n","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/configuration/BuildContext.java#L334-L370","documentation":"BuildContext.Builder.build() validates that required fields (base image, target image, etc.) were set before constructing the BuildConfiguration. When exactly one or two required fields are missing, it throws an IllegalStateException naming them. Jib throws this because a build context without these fields cannot produce a valid build plan.","triggerScenarios":"Calling build() on a BuildContext.Builder after setting only some required fields — e.g. a builder where setBaseImage was called but setTargetImage (or another mandatory field) was not, leaving 1-2 entries in the missingFields list.","commonSituations":"Programmatic use of jib-core without the Maven/Gradle plugins: forgetting to call one setter on the builder, constructing a builder from partially parsed configuration, or refactoring code that dropped a setter call.","solutions":["Read the exception message and call the corresponding setter(s) on the BuildContext.Builder (e.g. builder.setBaseImage(...), builder.setTargetImage(...)) before calling build()","If building from config, log/inspect which fields your config loader populated and fix the missing one","Wrap builder construction in a helper that validates all required inputs before calling build()"],"exampleFix":"// before\nBuildContext.Builder builder = BuildContext.builder()\n    .setBaseImageRegistry(\"gcr.io\")\n    .setTargetImage(...);\nBuildContext ctx = builder.build(); // throws\n// after\nBuildContext.Builder builder = BuildContext.builder()\n    .setBaseImageRegistry(\"gcr.io\")\n    .setBaseImage(...)              // add the missing required setter\n    .setTargetImage(...);\nBuildContext ctx = builder.build();","handlingStrategy":"validation","validationCode":"// Java\nList<String> missing = new ArrayList<>();\nif (baseImage == null) missing.add(\"base image\");\nif (targetImage == null) missing.add(\"target image\");\nif (!missing.isEmpty()) throw new IllegalArgumentException(\"Missing: \" + missing);\nBuildContext ctx = builder.build();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep builder construction in one place with all required setters visible","Unit-test your BuildContext construction path","Mirror the required-field list from the exception message into your config validation"],"tags":["jib","configuration","builder","illegal-state"],"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-14T05:17:10.506Z"}