{"record":{"id":"25d2ae1b75db8dcb","repo":"apache/pulsar","slug":"failed-to-initialize-s-field-while-setting-value","errorCode":null,"errorMessage":"failed to initialize %s field while setting value %s","messagePattern":"failed to initialize (.+?) field while setting value (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/OffloadPoliciesImpl.java","lineNumber":268,"sourceCode":"        } else if (driver.equalsIgnoreCase(DRIVER_GOOGLE_CLOUD_STORAGE)) {\n            builder.gcsManagedLedgerOffloadRegion(region)\n                .gcsManagedLedgerOffloadBucket(bucket)\n                .gcsManagedLedgerOffloadMaxBlockSizeInBytes(maxBlockSizeInBytes)\n                .gcsManagedLedgerOffloadReadBufferSizeInBytes(readBufferSizeInBytes);\n        }\n\n        return builder.build();\n    }\n\n    public static OffloadPoliciesImpl create(Properties properties) {\n        OffloadPoliciesImpl data = new OffloadPoliciesImpl();\n        for (Field f : CONFIGURATION_FIELDS) {\n            if (properties.containsKey(f.getName())) {\n                try {\n                    f.setAccessible(true);\n                    f.set(data, value((String) properties.get(f.getName()), f));\n                } catch (Exception e) {\n                    throw new IllegalArgumentException(\n                            String.format(\"failed to initialize %s field while setting value %s\",\n                                    f.getName(), properties.get(f.getName())), e);\n                }\n            }\n        }\n\n        Map<String, String> extraConfigurations = getExtraConfigurations(properties);\n        if (extraConfigurations != null) {\n            data.getManagedLedgerExtraConfigurations().putAll(extraConfigurations);\n        }\n\n        data.compatibleWithBrokerConfigFile(properties);\n        return data;\n    }\n\n    public static OffloadPoliciesImplBuilder builder() {\n        return new OffloadPoliciesImplBuilder();\n    }","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/OffloadPoliciesImpl.java#L250-L286","documentation":"OffloadPoliciesImpl.create(Properties) builds an OffloadPoliciesImpl by reflectively setting each CONFIGURATION_FIELDS field from a properties entry. If f.set fails for any field — value conversion error in the value() helper, a ClassCastException (property value not a String), IllegalArgumentException from the field type, or accessibility issues — it wraps the cause in IllegalArgumentException('failed to initialize <field> field while setting value <value>').","triggerScenarios":"Creating offloader policies from a Properties object where a known offload field (e.g. s3ManagedLedgerOffloadRegion, offloadersDirectory, or a numeric/boolean/size field) has a value that cannot be converted to the field's type — e.g. 's3ManagedLedgerOffloadMaxBlockSizeInBytes=abc', a non-String object in the Properties, or a malformed size/time spec.","commonSituations":"broker.conf / standalone.conf offload settings copied with wrong units or typo'd values; passing Properties read from a config file where numbers are unparsable; mixing typed properties (Integer values) into Properties<String,String>.","solutions":["Read the wrapped cause — it identifies the exact field and conversion problem.","Correct the property value's format: numbers must be plain integers, sizes/times use the expected unit format.","Ensure all values inserted into Properties are Strings (cast to (String) in create implies String values only).","Check for typos against the documented offload configuration keys (s3ManagedLedgerOffread*/azureblob* etc.) — wrong key names are ignored, wrong values fail here.","Set the properties programmatically as strings: props.setProperty(key, String.valueOf(value))."],"exampleFix":"// before\nprops.setProperty(\"s3ManagedLedgerOffloadMaxBlockSizeInBytes\", \"64MB\"); // wrong format\n// after\nprops.setProperty(\"s3ManagedLedgerOffloadMaxBlockSizeInBytes\", String.valueOf(64 * 1024 * 1024)); // \"67108864\"","handlingStrategy":"try-catch","validationCode":"static void validateOffloadProps(Properties props) {\n    for (String name : new String[]{\"s3ManagedLedgerOffloadMaxBlockSizeInBytes\",\n                                    \"s3ManagedLedgerOffloadReadBufferSizeInBytes\",\n                                    \"managedLedgerOffloadThrottleInBytes\"}) {\n        String v = props.getProperty(name);\n        if (v != null) Long.parseLong(v.trim()); // throws early on bad format\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    OffloadPoliciesImpl policies = OffloadPoliciesImpl.create(properties);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"failed to initialize\")) {\n        // e.getCause() names the field and bad value; fix the property value format\n    }\n    throw e;\n}","preventionTips":["Store all offload settings in Properties as Strings (setProperty, not put with typed objects).","Use plain integer values for byte/size/time fields; verify against the documented unit format.","Log e.getCause() to identify the exact failing field name and value.","Keep offload config keys and values in sync with the broker.conf template for your Pulsar version."],"tags":["reflection","config","offload"],"backgroundTag":"config-property-conversion-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}