pentaho/pentaho-kettle · error · IllegalArgumentException

HttpServletResponse cannot be null

Error message

HttpServletResponse cannot be null 

What it means

An IllegalArgumentException thrown by Trans.setServletReponse when passed a null HttpServletResponse. This setter applies the KETTLE_DEFAULT_SERVLET_ENCODING property to the response; it cannot do that without a response object, so null is rejected immediately.

Solutions

  1. Pass the actual HttpServletResponse from the servlet request context
  2. Guard the call site: only call setServletReponse when a response object exists
  3. In tests, use a mock HttpServletResponse (e.g., Mockito) instead of null

Example fix

// before
trans.setServletReponse(null);
// after
if (response != null) {
  trans.setServletReponse(response);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (response == null) { throw new IllegalStateException("servlet response not available in this context"); }

Type guard

boolean hasResponse(HttpServletResponse r) { return r != null; }

Try / catch

try { trans.setServletReponse(response); } catch (IllegalArgumentException e) { log.warn("No servlet response bound; skipping servlet encoding setup", e); }

Prevention

When it happens

Trigger: Calling trans.setServletReponse(null), typically from custom servlet/execution code wiring a trans to an HTTP response where the response was never injected.

Common situations: Custom Carte/servlet extensions calling the setter outside a real request lifecycle; unit tests passing null; refactors that made the response field optional.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/070ccc44ca1747e1. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/Trans.java:5599

  }

  public void setMetaStore( IMetaStore metaStore ) {
    this.metaStore = metaStore;
    if ( transMeta != null ) {
      transMeta.setMetaStore( metaStore );
    }
  }

  /**
   * Sets encoding of HttpServletResponse according to System encoding.Check if system encoding is null or an empty and
   * set it to HttpServletResponse when not and writes error to log if null. Throw IllegalArgumentException if input
   * parameter is null.
   *
   * @param response the HttpServletResponse to set encoding, mayn't be null
   */
  public void setServletReponse( HttpServletResponse response ) {
    if ( response == null ) {
      throw new IllegalArgumentException( "HttpServletResponse cannot be null " );
    }
    String encoding = System.getProperty( "KETTLE_DEFAULT_SERVLET_ENCODING", null );
    // true if encoding is null or an empty (also for the next kin of strings: " ")
    if ( !StringUtils.isBlank( encoding ) ) {
      try {
        response.setCharacterEncoding( encoding.trim() );
        response.setContentType( "text/html; charset=" + encoding );
      } catch ( Exception ex ) {
        LogChannel.GENERAL.logError( "Unable to encode data with encoding : '" + encoding + "'", ex );
      }
    }
    this.servletResponse = response;
  }

  public HttpServletResponse getServletResponse() {
    return servletResponse;
  }

View on GitHub (pinned to f3058517a1)