{"record":{"id":"070ccc44ca1747e1","repo":"pentaho/pentaho-kettle","slug":"httpservletresponse-cannot-be-null","errorCode":null,"errorMessage":"HttpServletResponse cannot be null ","messagePattern":"HttpServletResponse cannot be null ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/Trans.java","lineNumber":5599,"sourceCode":"  }\n\n  public void setMetaStore( IMetaStore metaStore ) {\n    this.metaStore = metaStore;\n    if ( transMeta != null ) {\n      transMeta.setMetaStore( metaStore );\n    }\n  }\n\n  /**\n   * Sets encoding of HttpServletResponse according to System encoding.Check if system encoding is null or an empty and\n   * set it to HttpServletResponse when not and writes error to log if null. Throw IllegalArgumentException if input\n   * parameter is null.\n   *\n   * @param response the HttpServletResponse to set encoding, mayn't be null\n   */\n  public void setServletReponse( HttpServletResponse response ) {\n    if ( response == null ) {\n      throw new IllegalArgumentException( \"HttpServletResponse cannot be null \" );\n    }\n    String encoding = System.getProperty( \"KETTLE_DEFAULT_SERVLET_ENCODING\", null );\n    // true if encoding is null or an empty (also for the next kin of strings: \" \")\n    if ( !StringUtils.isBlank( encoding ) ) {\n      try {\n        response.setCharacterEncoding( encoding.trim() );\n        response.setContentType( \"text/html; charset=\" + encoding );\n      } catch ( Exception ex ) {\n        LogChannel.GENERAL.logError( \"Unable to encode data with encoding : '\" + encoding + \"'\", ex );\n      }\n    }\n    this.servletResponse = response;\n  }\n\n  public HttpServletResponse getServletResponse() {\n    return servletResponse;\n  }\n","sourceCodeStart":5581,"sourceCodeEnd":5617,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/Trans.java#L5581-L5617","documentation":"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.","triggerScenarios":"Calling trans.setServletReponse(null), typically from custom servlet/execution code wiring a trans to an HTTP response where the response was never injected.","commonSituations":"Custom Carte/servlet extensions calling the setter outside a real request lifecycle; unit tests passing null; refactors that made the response field optional.","solutions":["Pass the actual HttpServletResponse from the servlet request context","Guard the call site: only call setServletReponse when a response object exists","In tests, use a mock HttpServletResponse (e.g., Mockito) instead of null"],"exampleFix":"// before\ntrans.setServletReponse(null);\n// after\nif (response != null) {\n  trans.setServletReponse(response);\n}","handlingStrategy":"type-guard","validationCode":"if (response == null) { throw new IllegalStateException(\"servlet response not available in this context\"); }","typeGuard":"boolean hasResponse(HttpServletResponse r) { return r != null; }","tryCatchPattern":"try { trans.setServletReponse(response); } catch (IllegalArgumentException e) { log.warn(\"No servlet response bound; skipping servlet encoding setup\", e); }","preventionTips":["Only call setServletReponse inside a live servlet request thread","Never pass null; skip the call instead","Use mock responses in unit tests"],"tags":["kettle","servlet","null-argument","illegal-argument"],"backgroundTag":"null-argument","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}