{"record":{"id":"5b55f497f52180fb","repo":"apache/druid","slug":"input-is-null","errorCode":null,"errorMessage":"Input is null","messagePattern":"Input is null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/Numbers.java","lineNumber":47,"sourceCode":"{\n  /**\n   * Parse the given object as a {@code long}. The input object can be a {@link String} or one of the implementations of\n   * {@link Number}. You may want to use {@code GuavaUtils.tryParseLong()} instead if the input is a nullable string and\n   * you want to avoid any exceptions.\n   *\n   * @throws NumberFormatException if the input is an unparseable string.\n   * @throws NullPointerException if the input is null.\n   * @throws ISE if the input is not a string or a number.\n   */\n  public static long parseLong(Object val)\n  {\n    if (val instanceof String) {\n      return Long.parseLong((String) val);\n    } else if (val instanceof Number) {\n      return ((Number) val).longValue();\n    } else {\n      if (val == null) {\n        throw new NullPointerException(\"Input is null\");\n      } else {\n        throw new ISE(\"Unknown type [%s]\", val.getClass());\n      }\n    }\n  }\n\n  /**\n   * Parse the given object as a {@code int}. The input object can be a {@link String} or one of the implementations of\n   * {@link Number}.\n   *\n   * @throws NumberFormatException if the input is an unparseable string.\n   * @throws NullPointerException if the input is null.\n   * @throws ISE if the input is not a string or a number.\n   */\n  public static int parseInt(Object val)\n  {\n    if (val instanceof String) {\n      return Integer.parseInt((String) val);","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/Numbers.java#L29-L65","documentation":"Numbers.parseLong converts a String or Number object to a primitive long. A null input is neither type, so the method throws NullPointerException with the message \"Input is null\" rather than returning a default. This makes silent null coercion impossible for callers who expect a value.","triggerScenarios":"Calling Numbers.parseLong(null) directly, or passing a map/JSON field that is absent or explicitly null.","commonSituations":"Optional JSON fields missing from ingestion specs or query parameters; a config map entry removed in a newer spec version; passing the result of Map.get() without a null check.","solutions":["Ensure the input value is set before parsing (supply the field in the spec/config)","Check for null first and substitute a default: val == null ? 0L : Numbers.parseLong(val)","Use a nullable-aware accessor like MapUtils.getLong with a default for map inputs","Inspect why the upstream produced null (wrong key, skipped field, earlier filter)"],"exampleFix":"// before\nlong ts = Numbers.parseLong(queryContext.get(\"timeout\"));\n// after\nObject v = queryContext.get(\"timeout\");\nlong ts = v == null ? 30000L : Numbers.parseLong(v);","handlingStrategy":"type-guard","validationCode":"if (val == null) {\n  throw new IllegalArgumentException(\"Numeric field is required but was null\");\n}\nlong n = Numbers.parseLong(val);","typeGuard":"static Long safeParseLong(Object val) {\n  return val == null ? null : (val instanceof String || val instanceof Number ? Numbers.parseLong(val) : null);\n}","tryCatchPattern":"try {\n  return Numbers.parseLong(val);\n} catch (NullPointerException e) {\n  log.warn(\"parseLong got null; using default\");\n  return 0L;\n}","preventionTips":["Null-check map/JSON field values before numeric conversion","Prefer accessors with built-in defaults (MapUtils.getLong) for map input","Make optional numeric fields explicit in specs/configs","Log null sources to identify which upstream field is missing"],"tags":["null-pointer","type-conversion"],"backgroundTag":"null-argument","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}