{"record":{"id":"7870817a69226373","repo":"apache/beam","slug":"properties-cannot-be-null","errorCode":null,"errorMessage":"Properties cannot be null","messagePattern":"Properties cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/ClickHouseIO.java","lineNumber":418,"sourceCode":"\n    /**\n     * Set connection properties (user, password, etc.).\n     *\n     * <p><b>Important:</b> If using the deprecated JDBC URL-based {@link #write(String, String)}\n     * method, this will fail if any properties specified here conflict with properties already\n     * extracted from the JDBC URL. This prevents accidental property conflicts.\n     *\n     * <p>For the new API {@link #write(String, String, String)}, properties can be set freely since\n     * there are no URL-embedded properties to conflict with.\n     *\n     * @param properties connection properties\n     * @return a {@link PTransform} writing data to ClickHouse\n     * @throws IllegalArgumentException if properties is null or if any property conflicts with\n     *     existing properties (e.g., from JDBC URL)\n     */\n    public Write<T> withProperties(Properties properties) {\n      if (properties == null) {\n        throw new IllegalArgumentException(\"Properties cannot be null\");\n      }\n\n      // Check for conflicts with existing properties\n      Properties existing = properties();\n      for (String key : properties.stringPropertyNames()) {\n        if (existing.containsKey(key)) {\n          String existingValue = existing.getProperty(key);\n          String newValue = properties.getProperty(key);\n          if (!existingValue.equals(newValue)) {\n            throw new IllegalArgumentException(\n                String.format(\n                    \"Property conflict: '%s' is already set to '%s' (likely from JDBC URL), \"\n                        + \"but attempting to set it to '%s'. \"\n                        + \"Please use either JDBC URL properties OR withProperties(), not both for the same keys.\",\n                    key, existingValue, newValue));\n          }\n        }\n      }","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/clickhouse/src/main/java/org/apache/beam/sdk/io/clickhouse/ClickHouseIO.java#L400-L436","documentation":"ClickHouseIO.Write.withProperties accepts extra JDBC connection properties to pass to the ClickHouse client. Because a null Properties object cannot be merged or conflict-checked against properties already parsed from the JDBC URL, the builder throws IllegalArgumentException immediately when null is supplied.","triggerScenarios":"Calling writer.withProperties(null) directly, or forwarding a Properties field/variable that was never initialized (e.g., a method parameter that defaults to null when no user properties are configured).","commonSituations":"Wiring user-supplied connection properties from config where the absence of settings yields null; refactors that changed a default Properties instance into null; calling withProperties unconditionally even when the user supplied none.","solutions":["Only call withProperties when the Properties object is non-null","Initialize with new Properties() instead of null as the default","Use an empty Properties object — withProperties accepts an empty set safely"],"exampleFix":"// before\nif (userProps != null) writer = writer.withProperties(userProps); // called unconditionally elsewhere\n// after\nwriter = writer.withProperties(userProps == null ? new Properties() : userProps);","handlingStrategy":"type-guard","validationCode":"if (props == null) {\n  props = new Properties(); // or skip the withProperties call\n}","typeGuard":"static Properties nonNullProps(Properties p) {\n  return p == null ? new Properties() : p;\n}","tryCatchPattern":"try {\n  writer = writer.withProperties(props);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Properties cannot be null\")) { writer = writer.withProperties(new Properties()); }\n  else throw e;\n}","preventionTips":["Initialize Properties fields to new Properties(), never null","Guard withProperties calls behind a null check on user-supplied settings","Remember an empty Properties object is always valid input"],"tags":["java","clickhouse","beam","null-argument","jdbc"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}