{"record":{"id":"8e2d2069327a3ad7","repo":"stanfordnlp/CoreNLP","slug":"invalid-preservespacing-setting","errorCode":null,"errorMessage":"Invalid preserveSpacing setting.","messagePattern":"Invalid preserveSpacing setting\\.","errorType":"http","errorClass":"javax.servlet.ServletException","httpStatus":500,"severity":"error","filePath":"src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java","lineNumber":50,"sourceCode":"\n  private String format;\n  private boolean spacing;\n  private String defaultClassifier;\n  private List<String> classifiers = new ArrayList<>();\n  private Map<String, CRFClassifier<CoreMap>> ners;\n\n  private static final int MAXIMUM_QUERY_LENGTH = 3000;\n\n  @Override\n  public void init() throws ServletException {\n    format = getServletConfig().getInitParameter(\"outputFormat\");\n    if (format == null || format.trim().isEmpty()) {\n      throw new ServletException(\"Invalid outputFormat setting.\");\n    }\n\n    String spacingStr = getServletConfig().getInitParameter(\"preserveSpacing\");\n    if (spacingStr == null || spacingStr.trim().isEmpty()) {\n      throw new ServletException(\"Invalid preserveSpacing setting.\");\n    }\n    //spacing = Boolean.valueOf(spacingStr).booleanValue();\n    spacingStr = spacingStr.trim().toLowerCase();\n    spacing = \"true\".equals(spacingStr);\n\n    String path = getServletContext().getRealPath(\"/WEB-INF/data/models\");\n    for (String classifier : new File(path).list()) {\n      classifiers.add(classifier);\n    }\n    // TODO: get this from somewhere more interesting?\n    defaultClassifier = classifiers.get(0);\n\n    for (String classifier : classifiers) {\n      log(classifier);\n    }\n\n    ners = new HashMap<>();\n    for (String classifier : classifiers) {","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java#L32-L68","documentation":"NERServlet.init() reads the 'preserveSpacing' init-parameter and throws ServletException if it is null or blank. The servlet requires this boolean configuration (parsed case-insensitively as 'true') to start.","triggerScenarios":"Deploying without an <init-param> named preserveSpacing, or providing it as whitespace/empty string.","commonSituations":"Missing init-param after refactoring web.xml; environment-specific overlays (production web.xml) omitting the parameter; typos in the param-name.","solutions":["Add <init-param><param-name>preserveSpacing</param-name><param-value>true</param-value></init-param> to the servlet definition","Set the value to 'true' or 'false' explicitly (any non-blank value; only exact 'true' enables spacing preservation)","Redeploy and confirm init() completes without ServletException"],"exampleFix":"<!-- before -->\n<init-param><param-name>preserveSpacing</param-name><param-value></param-value></init-param>\n<!-- after -->\n<init-param><param-name>preserveSpacing</param-name><param-value>true</param-value></init-param>","handlingStrategy":"validation","validationCode":"String sp = getServletConfig().getInitParameter(\"preserveSpacing\");\nif (sp == null || sp.trim().isEmpty()) throw new ServletException(\"preserveSpacing init-param required\");","typeGuard":null,"tryCatchPattern":"try { servlet.init(cfg); } catch (ServletException e) { failDeployment(\"preserveSpacing not configured\"); }","preventionTips":["Set preserveSpacing explicitly to true or false in web.xml","Include servlet init-params in environment config checklists","Smoke-test servlet init on every deploy"],"tags":["java","servlet","config"],"backgroundTag":"missing-required-config-field","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}