{"record":{"id":"ea59a1fe9c4cd9b5","repo":"apache/pulsar","slug":"cannot-disable-validation-of-default-values","errorCode":null,"errorMessage":"Cannot disable validation of default values","messagePattern":"Cannot disable validation of default values","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/util/SchemaUtil.java","lineNumber":82,"sourceCode":"                .name(\"\")\n                .type(schemaType).build();\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public static Schema createAvroSchema(SchemaDefinition schemaDefinition) {\n        Class pojo = schemaDefinition.getPojo();\n\n        if (StringUtils.isNotBlank(schemaDefinition.getJsonDef())) {\n            return parseAvroSchema(schemaDefinition.getJsonDef());\n        } else if (pojo != null) {\n            ThreadLocal<Boolean> validateDefaults = null;\n\n            try {\n                Field validateDefaultsField = Schema.class.getDeclaredField(\"VALIDATE_DEFAULTS\");\n                validateDefaultsField.setAccessible(true);\n                validateDefaults = (ThreadLocal<Boolean>) validateDefaultsField.get(null);\n            } catch (NoSuchFieldException | IllegalAccessException e) {\n                throw new RuntimeException(\"Cannot disable validation of default values\", e);\n            }\n\n            final boolean savedValidateDefaults = validateDefaults.get();\n\n            try {\n                // Disable validation of default values for compatibility\n                validateDefaults.set(false);\n                return extractAvroSchema(schemaDefinition, pojo);\n            } finally {\n                validateDefaults.set(savedValidateDefaults);\n            }\n        } else {\n            throw new RuntimeException(\"Schema definition must specify pojo class or schema json definition\");\n        }\n    }\n\n    public static Schema extractAvroSchema(SchemaDefinition schemaDefinition, Class pojo) {\n        try {","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/util/SchemaUtil.java#L64-L100","documentation":"When building an Avro schema via createAvroSchema, Pulsar reflectively accesses the internal static field Schema.VALIDATE_DEFAULTS (a ThreadLocal<Boolean>) from the Avro library so it can disable validation of default values for compatibility. If that field cannot be found or accessed, a RuntimeException is thrown. This typically means the Avro version on the classpath differs from the one Pulsar was compiled against.","triggerScenarios":"Calling Schema.AVRO(SomePojo.class) (or JSONSchema/other createAvroSchema paths) when the runtime Avro library lacks the VALIDATE_DEFAULTS field or blocks reflective access (Java module strong encapsulation / SecurityManager).","commonSituations":"Pulsar client and Avro version mismatch after upgrading Avro (field renamed/removed in Avro 1.12+); shaded/uber jars bundling the wrong Avro; running on a JDK with strict module access blocking setAccessible.","solutions":["Align the Avro dependency version with the one required by your Pulsar client version (check pulsar-client's avro dependency in its pom).","Add JVM args like --add-opens org.apache.avro:org.apache.avro.schema if reflective access is blocked by modules.","Check for conflicting Avro jars on the classpath (mvn dependency:tree / shading conflicts) and exclude duplicates.","As a workaround, define the schema from an explicit JSON schema string (Schema ParseSchemaInfo path) instead of the pojo reflection path."],"exampleFix":"// before (pom.xml)\n<dependency><groupId>org.apache.avro</groupId><artifactId>avro</artifactId><version>1.11.0</version></dependency>\n// after\n<dependency><groupId>org.apache.avro</groupId><artifactId>avro</artifactId><version>1.11.3</version></dependency> <!-- version matching pulsar-client -->","handlingStrategy":"try-catch","validationCode":"try {\n    Class.forName(\"org.apache.avro.Schema\")\n         .getDeclaredField(\"VALIDATE_DEFAULTS\");\n} catch (NoSuchFieldException e) {\n    throw new IllegalStateException(\"Avro on classpath lacks VALIDATE_DEFAULTS; fix Avro version\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Schema<Event> s = Schema.AVRO(Event.class);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"Cannot disable validation of default values\")) {\n        log.error(\"Avro/Pulsar version mismatch\", e); // fix avro dependency\n    }\n}","preventionTips":["Pin the Avro version required by your Pulsar client version","Run mvn dependency:tree to detect conflicting avro jars","Test schema creation early in application startup","Watch for --add-opens requirements on newer JDKs"],"tags":["avro","reflection","schema","version-mismatch"],"backgroundTag":"avro-reflective-access-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}