apache/druid · error · NullPointerException
Input is null
Error message
Input is null
What it means
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.
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)
Example fix
// before
long ts = Numbers.parseLong(queryContext.get("timeout"));
// after
Object v = queryContext.get("timeout");
long ts = v == null ? 30000L : Numbers.parseLong(v); Defensive patterns
Strategy: type-guard
Validate before calling
if (val == null) {
throw new IllegalArgumentException("Numeric field is required but was null");
}
long n = Numbers.parseLong(val); Type guard
static Long safeParseLong(Object val) {
return val == null ? null : (val instanceof String || val instanceof Number ? Numbers.parseLong(val) : null);
} Try / catch
try {
return Numbers.parseLong(val);
} catch (NullPointerException e) {
log.warn("parseLong got null; using default");
return 0L;
} Prevention
- 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
When it happens
Trigger: Calling Numbers.parseLong(null) directly, or passing a map/JSON field that is absent or explicitly null.
Common situations: 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.
Related errors
- Cannot have a null result!
- Could not convert value
- Could not convert value
- Could not convert value
- Could not convert value
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/5b55f497f52180fb.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/java/util/common/Numbers.java:47
{
/**
* Parse the given object as a {@code long}. The input object can be a {@link String} or one of the implementations of
* {@link Number}. You may want to use {@code GuavaUtils.tryParseLong()} instead if the input is a nullable string and
* you want to avoid any exceptions.
*
* @throws NumberFormatException if the input is an unparseable string.
* @throws NullPointerException if the input is null.
* @throws ISE if the input is not a string or a number.
*/
public static long parseLong(Object val)
{
if (val instanceof String) {
return Long.parseLong((String) val);
} else if (val instanceof Number) {
return ((Number) val).longValue();
} else {
if (val == null) {
throw new NullPointerException("Input is null");
} else {
throw new ISE("Unknown type [%s]", val.getClass());
}
}
}
/**
* Parse the given object as a {@code int}. The input object can be a {@link String} or one of the implementations of
* {@link Number}.
*
* @throws NumberFormatException if the input is an unparseable string.
* @throws NullPointerException if the input is null.
* @throws ISE if the input is not a string or a number.
*/
public static int parseInt(Object val)
{
if (val instanceof String) {
return Integer.parseInt((String) val);View on GitHub (pinned to 9b90983fd2)