apache/pulsar · error · RuntimeException
The log error handler cannot be set to null
Error message
The log error handler cannot be set to null
What it means
LogAppender.setHandler is called by the function runtime to attach the ErrorHandler that receives log appender failures. Passing null is invalid because the appender relies on the handler to surface producer errors, so the method rejects null with RuntimeException immediately.
Source
Thrown at pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/LogAppender.java:92
@Override
public Layout<? extends Serializable> getLayout() {
return null;
}
@Override
public boolean ignoreExceptions() {
return false;
}
@Override
public ErrorHandler getHandler() {
return errorHandler;
}
@Override
public void setHandler(ErrorHandler errorHandler) {
if (errorHandler == null) {
throw new RuntimeException("The log error handler cannot be set to null");
}
if (isStarted()) {
throw new RuntimeException("The log error handler cannot be changed once the appender is started");
}
this.errorHandler = errorHandler;
}
@Override
public State getState() {
return state;
}
@Override
public void initialize() {
this.state = State.INITIALIZED;
}
@OverrideView on GitHub (pinned to 820761864e)
Solutions
- Always construct and pass a valid org.apache.pulsar.functions.instance.ErrorHandler before calling setHandler
- If no failure handling is needed, provide a no-op ErrorHandler implementation rather than null
- Call setHandler before start(), since start also requires the handler-dependent wiring to be complete
Example fix
// before
logAppender.setHandler(null);
// after
ErrorHandler handler = (throwable) -> { log.error("log appender failed", throwable); };
logAppender.setHandler(handler); Defensive patterns
Strategy: validation
Validate before calling
if (handler == null) {
throw new IllegalArgumentException("ErrorHandler must be non-null before setHandler");
}
logAppender.setHandler(handler); Type guard
boolean hasHandler(ErrorHandler h) { return h != null; } Try / catch
try { logAppender.setHandler(handler); }
catch (RuntimeException e) {
if (e.getMessage().contains("cannot be set to null")) {
log.error("Provide a non-null ErrorHandler", e);
}
} Prevention
- Construct the ErrorHandler before wiring the LogAppender
- Provide a no-op ErrorHandler instead of null when handling is unnecessary
- Add a null assertion in harness code that wires appenders
When it happens
Trigger: Calling setHandler(null) directly on a LogAppender from custom code or a misconfigured appenders setup path that forgot to construct the ErrorHandler.
Common situations: Custom function runtime harness code that wires LogAppender manually and passes null when no error handler is defined; framework wiring bug after refactor where the ErrorHandler bean is absent.
Related errors
- The record returned by the source cannot be null
- The log error handler cannot be changed once the appender is
- Component cannot get state store
- not implemented
- Schema should not be null.
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/286e306cee2fe737.
Report an issue: GitHub.