apache/hadoop · error · UnsupportedOperationException
in.getClass().getName() + ": claims unbuffer capabilty but d
Error message
in.getClass().getName() + ": claims unbuffer capabilty but does not implement CanUnbuffer"
What it means
Thrown by StreamCapabilitiesPolicy.unbuffer when a stream answers true to hasCapability("unbuffer") but the subsequent cast to CanUnbuffer fails with ClassCastException, which the policy converts to UnsupportedOperationException with the class name prefixed. It is a contract violation inside the stream implementation: the stream advertises an unbuffer capability it does not actually implement. The message constant contains the upstream typo 'capabilty'.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/StreamCapabilitiesPolicy.java:55
StreamCapabilitiesPolicy.class);
/**
* Implement the policy for {@link CanUnbuffer#unbuffer()}.
*
* @param in the input stream
*/
public static void unbuffer(InputStream in) {
try {
if (in instanceof StreamCapabilities
&& ((StreamCapabilities) in).hasCapability(
StreamCapabilities.UNBUFFER)) {
((CanUnbuffer) in).unbuffer();
} else {
LOG.debug(in.getClass().getName() + ":"
+ " does not implement StreamCapabilities"
+ " and the unbuffer capability");
}
} catch (ClassCastException e) {
throw new UnsupportedOperationException(in.getClass().getName() + ": "
+ CAN_UNBUFFER_NOT_IMPLEMENTED_MESSAGE);
}
}
}
View on GitHub (pinned to 2add963021)
Solutions
- Fix the stream class: implement CanUnbuffer and provide a real unbuffer() that releases read-ahead buffers
- Until implemented, make hasCapability("unbuffer") return false so callers skip the path gracefully
- As a caller, pre-check 'in instanceof CanUnbuffer' before invoking unbuffer logic
Example fix
// before
public class MyInputStream extends InputStream
implements StreamCapabilities {
public boolean hasCapability(String c) {
return StreamCapabilities.UNBUFFER.equals(c); // promise without implementation
}
}
// after
public class MyInputStream extends InputStream
implements StreamCapabilities, CanUnbuffer {
public boolean hasCapability(String c) {
return StreamCapabilities.UNBUFFER.equals(c);
}
public void unbuffer() { /* release read-ahead buffers */ }
} Defensive patterns
Strategy: type-guard
Type guard
public static boolean canUnbuffer(java.io.InputStream in) {
return in instanceof org.apache.hadoop.fs.CanUnbuffer
&& in instanceof org.apache.hadoop.fs.StreamCapabilities
&& ((org.apache.hadoop.fs.StreamCapabilities) in)
.hasCapability(org.apache.hadoop.fs.StreamCapabilities.UNBUFFER);
}
// usage: if (canUnbuffer(in)) ((CanUnbuffer) in).unbuffer(); else LOG.debug("no unbuffer"); Try / catch
try {
StreamCapabilitiesPolicy.unbuffer(in);
} catch (UnsupportedOperationException e) {
// message: "<Class>: claims unbuffer capabilty but does not implement CanUnbuffer"
// -> bug in the stream implementation; fix the stream class, do not swallow
LOG.error("Stream advertises unbuffer but cannot unbuffer: {}", in.getClass(), e);
} Prevention
- Whenever hasCapability(X) returns true, verify the class implements the interface paired with X before shipping
- Write a unit test asserting every capability string your stream reports is backed by a working implementation
When it happens
Trigger: A custom InputStream implements StreamCapabilities.hasCapability() returning true for StreamCapabilities.UNBUFFER but does not implement the CanUnbuffer interface; unbuffer() is then invoked on it (e.g. via IOUtils/Shell 'unbuffer' paths or FileSystem reopen logic).
Common situations: Third-party or in-house FileSystem connectors that copied a hasCapability table without wiring the corresponding interfaces; upgrading a connector whose capability list gained 'unbuffer' prematurely.
Related errors
- Path must be absolute: " + path
- Append is not supported by BaiduBosFileSystem
- No more entry in " + f
- f + " is a directory"
- f + " already exists"
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/2a5b2d89ea8c1b92.
Report an issue: GitHub.