{"record":{"id":"e40097ebe9e34642","repo":"apache/hadoop","slug":"bad-format","errorCode":null,"errorMessage":"Bad format: {}","messagePattern":"Bad format: (.+?)","errorType":"http","errorClass":"BadFormatException","httpStatus":400,"severity":"warning","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/ConfServlet.java","lineNumber":103,"sourceCode":"  @VisibleForTesting\n  static String parseAcceptHeader(HttpServletRequest request) {\n    String format = request.getHeader(HttpHeaders.ACCEPT);\n    return format != null && format.contains(FORMAT_JSON) ?\n        FORMAT_JSON : FORMAT_XML;\n  }\n\n  /**\n   * Guts of the servlet - extracted for easy testing.\n   */\n  static void writeResponse(Configuration conf,\n      Writer out, String format, String propertyName)\n          throws IOException, IllegalArgumentException, BadFormatException {\n    if (FORMAT_JSON.equals(format)) {\n      Configuration.dumpConfiguration(conf, propertyName, out);\n    } else if (FORMAT_XML.equals(format)) {\n      conf.writeXml(propertyName, out, conf);\n    } else {\n      throw new BadFormatException(\"Bad format: \" + format);\n    }\n  }\n\n  static void writeResponse(Configuration conf, Writer out, String format)\n      throws IOException, BadFormatException {\n    writeResponse(conf, out, format, null);\n  }\n\n  public static class BadFormatException extends Exception {\n    private static final long serialVersionUID = 1L;\n\n    public BadFormatException(String msg) {\n      super(msg);\n    }\n  }\n\n}\n","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/ConfServlet.java#L85-L121","documentation":"ConfServlet serves /conf requests that dump running configuration. The 'format' query parameter accepts exactly 'json' or 'xml'; writeResponse() dispatches on those two constants and throws BadFormatException('Bad format: <format>') for anything else, which the servlet maps to an HTTP 400 response.","triggerScenarios":"GET http://host:port/conf?format=yaml (or format=json2, format=XML with wrong case, or any typo) — anything other than the literal strings 'json' or 'xml'.","commonSituations":"Monitoring/tooling scripts assuming a different format name; users typing 'format=JSON' uppercase (matching is case-sensitive here, unlike getFormat defaulting); curl probes during setup.","solutions":["Use ?format=json or ?format=xml exactly (lowercase)","Remember the default: with no or non-JSON format parameter the servlet serves XML"],"exampleFix":"# before\ncurl 'http://namenode:9870/conf?format=YAML'   # 400 Bad format\n\n# after\ncurl 'http://namenode:9870/conf?format=json'","handlingStrategy":"validation","validationCode":"if (format != null && !\"json\".equals(format) && !\"xml\".equals(format)) {\n  // reject early with 400 instead of relying on the servlet\n  response.sendError(400, \"format must be json or xml\");\n}","typeGuard":"Optional<String> validFormat(String raw) {\n  return \"json\".equals(raw) || \"xml\".equals(raw) ? Optional.of(raw) : Optional.empty();\n}","tryCatchPattern":"try { ConfServlet.writeResponse(conf, out, format, null); } catch (BadFormatException e) { /* map to HTTP 400 */ }","preventionTips":["Use exactly 'json' or 'xml' (lowercase) in /conf requests","Rely on the default (xml) instead of guessing format names","Check response status in tooling before parsing the body"],"tags":["hadoop-common","conf-servlet","http","query-parameter"],"backgroundTag":"unsupported-response-format","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}