{"record":{"id":"59d3891120bbe5c2","repo":"apache/beam","slug":"option-s-is-not-nullable","errorCode":null,"errorMessage":"Option %s is not nullable","messagePattern":"Option (.+?) is not nullable","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/Schema.java","lineNumber":1344,"sourceCode":"      Builder(Map<String, Option> init) {\n        this.options = new HashMap<>(init);\n      }\n\n      Builder() {\n        this(new HashMap<>());\n      }\n\n      public Builder setOption(String optionName, Row value) {\n        setOption(optionName, FieldType.row(value.getSchema()), value);\n        return this;\n      }\n\n      public Builder setOption(String optionName, FieldType fieldType, Object value) {\n        if (value == null) {\n          if (fieldType.getNullable()) {\n            options.put(optionName, new Option(fieldType, null));\n          } else {\n            throw new IllegalArgumentException(\n                String.format(\"Option %s is not nullable\", optionName));\n          }\n        } else {\n          options.put(\n              optionName, new Option(fieldType, verifyFieldValue(value, fieldType, optionName)));\n        }\n        return this;\n      }\n\n      public Options build() {\n        return new Options(this.options);\n      }\n\n      public Builder addOptions(Options options) {\n        this.options.putAll(options.options);\n        return this;\n      }\n    }","sourceCodeStart":1326,"sourceCodeEnd":1362,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/Schema.java#L1326-L1362","documentation":"Schema.Options.Builder.setOption stores a null option value only when the declared FieldType is nullable. Setting a null value for a non-nullable option type throws IllegalArgumentException 'Option %s is not nullable'.","triggerScenarios":"Calling schema.getOptions().setOption(name, FieldType.STRING, null) (or any non-nullable FieldType) with a null value.","commonSituations":"Propagating optional config into schema options without defaulting; dynamic option construction where the value may be absent.","solutions":["Make the option's FieldType nullable: FieldType.of(...).withNullable(true) before passing a null value.","Substitute a default non-null value when the option is missing.","Skip calling setOption entirely when the value is null instead of storing a null option."],"exampleFix":"// before\nbuilder.setOption(\"owner\", FieldType.STRING, maybeNullOwner);\n\n// after\nbuilder.setOption(\"owner\", FieldType.STRING.withNullable(true), maybeNullOwner);","handlingStrategy":"validation","validationCode":"// Java: guard null option values\nif (value == null && !fieldType.getNullable()) {\n  value = defaultValue; // or skip setOption\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare optional schema options as nullable FieldTypes.","Centralize option-setting logic with default handling."],"tags":["java","schema","null-value","options"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}