apache/hadoop · error · BadFencingConfigurationException
Unable to parse line: '{}'
Error message
Unable to parse line: '{}' What it means
NodeFencer.parseMethod() throws BadFencingConfigurationException("Unable to parse line: '<line>'") when an entry of dfs.ha.fencing.methods matches neither CLASS_WITH_ARGUMENT ('class(arg)') nor CLASS_WITHOUT_ARGUMENT ('class'). The fencing configuration line is malformed, so no fencer can be built.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/NodeFencer.java:162
methods.add(parseMethod(conf, line));
}
}
return methods;
}
private static FenceMethodWithArg parseMethod(Configuration conf, String line)
throws BadFencingConfigurationException {
Matcher m;
if ((m = CLASS_WITH_ARGUMENT.matcher(line)).matches()) {
String className = m.group(1);
String arg = m.group(2);
return createFenceMethod(conf, className, arg);
} else if ((m = CLASS_WITHOUT_ARGUMENT.matcher(line)).matches()) {
String className = m.group(1);
return createFenceMethod(conf, className, null);
} else {
throw new BadFencingConfigurationException(
"Unable to parse line: '" + line + "'");
}
}
private static FenceMethodWithArg createFenceMethod(
Configuration conf, String clazzName, String arg)
throws BadFencingConfigurationException {
Class<?> clazz;
try {
// See if it's a short name for one of the built-in methods
clazz = STANDARD_METHODS.get(clazzName);
if (clazz == null) {
// Try to instantiate the user's custom method
clazz = Class.forName(clazzName);
}
} catch (Exception e) {
throw new BadFencingConfigurationException(View on GitHub (pinned to 2add963021)
Solutions
- Use exact syntax 'method(arg)' or 'method', one method per line, no spaces inside: e.g. 'sshfence(hdfs:22)' then a second line 'shell(/path/fence.sh)'.
- Use built-in short names sshfence/shell, or a fully-qualified class name of a custom FenceMethod.
- Validate the property value in hdfs-site.xml (matched parens, no stray whitespace), then restart the daemon — the error appears only when fencing is attempted, not at config load.
Example fix
<!-- before: malformed lines --> <value>sshfence(hdfs :22) shell /usr/local/bin/fence-nn.sh</value> <!-- after: correct method(arg) syntax, one per line --> <value>sshfence(hdfs:22) shell(/usr/local/bin/fence-nn.sh)</value>
Defensive patterns
Strategy: validation
Validate before calling
// Validate fencing method lines exactly as NodeFencer will parse them
String methods = conf.get("dfs.ha.fencing.methods", "");
for (String line : methods.split("\n")) {
if (!line.trim().matches("[\\w.$]+(\\([^()]*\\))?")) {
throw new IllegalArgumentException("Bad fencing line: '" + line + "'");
}
}
// Stronger: let Hadoop itself validate
new NodeFencer(conf, methods); // throws BadFencingConfigurationException on any bad line Try / catch
try {
new NodeFencer(conf, conf.get("dfs.ha.fencing.methods"));
} catch (BadFencingConfigurationException e) {
// surface the exact offending line in a config-check report at deploy time
} Prevention
- Lint dfs.ha.fencing.methods in CI/deploy scripts: method(arg) or method, one per line, no spaces, matched parens.
- Prefer the sshfence/shell built-ins to reduce the surface for typos.
- Construct a NodeFencer in a post-deploy smoke test so config errors surface before a real failover needs them.
When it happens
Trigger: Configuring dfs.ha.fencing.methods (one method per line) with a line containing whitespace, unbalanced/missing parentheses, an argument without parentheses, or stray characters — e.g. 'sshfence(hdfs :22)' (space), 'shell(/bin/true' (missing ')'), 'shell /bin/true' (no parens). The exception surfaces when the fencer is constructed (failover time or HA service init).
Common situations: Hand-edited hdfs-site.xml with typos; XML entity/quote mistakes; copy-paste of config snippets with placeholders or trailing spaces; multi-line value where one line is bad.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unable to parse user and SSH port: {}
- Could not find configured fencing method {}
- Class {} does not implement FenceMethod
- No argument passed to 'shell' fencing method
- Expecting arguments size of at most two, getting {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/2697f3b08fe942d6.
Report an issue: GitHub.