apache/hadoop · warning · BadFormatException

Bad format: {}

Error message

Bad format: {}

What it means

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.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/ConfServlet.java:103

  @VisibleForTesting
  static String parseAcceptHeader(HttpServletRequest request) {
    String format = request.getHeader(HttpHeaders.ACCEPT);
    return format != null && format.contains(FORMAT_JSON) ?
        FORMAT_JSON : FORMAT_XML;
  }

  /**
   * Guts of the servlet - extracted for easy testing.
   */
  static void writeResponse(Configuration conf,
      Writer out, String format, String propertyName)
          throws IOException, IllegalArgumentException, BadFormatException {
    if (FORMAT_JSON.equals(format)) {
      Configuration.dumpConfiguration(conf, propertyName, out);
    } else if (FORMAT_XML.equals(format)) {
      conf.writeXml(propertyName, out, conf);
    } else {
      throw new BadFormatException("Bad format: " + format);
    }
  }

  static void writeResponse(Configuration conf, Writer out, String format)
      throws IOException, BadFormatException {
    writeResponse(conf, out, format, null);
  }

  public static class BadFormatException extends Exception {
    private static final long serialVersionUID = 1L;

    public BadFormatException(String msg) {
      super(msg);
    }
  }

}

View on GitHub (pinned to 2add963021)

Solutions

  1. Use ?format=json or ?format=xml exactly (lowercase)
  2. Remember the default: with no or non-JSON format parameter the servlet serves XML

Example fix

# before
curl 'http://namenode:9870/conf?format=YAML'   # 400 Bad format

# after
curl 'http://namenode:9870/conf?format=json'
Defensive patterns

Strategy: validation

Validate before calling

if (format != null && !"json".equals(format) && !"xml".equals(format)) {
  // reject early with 400 instead of relying on the servlet
  response.sendError(400, "format must be json or xml");
}

Type guard

Optional<String> validFormat(String raw) {
  return "json".equals(raw) || "xml".equals(raw) ? Optional.of(raw) : Optional.empty();
}

Try / catch

try { ConfServlet.writeResponse(conf, out, format, null); } catch (BadFormatException e) { /* map to HTTP 400 */ }

Prevention

When it happens

Trigger: 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'.

Common situations: 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.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/e40097ebe9e34642. Report an issue: GitHub.