{"record":{"id":"2a5b2d89ea8c1b92","repo":"apache/hadoop","slug":"in-getclass-getname-claims-unbuffer-capab","errorCode":null,"errorMessage":"in.getClass().getName() + \": claims unbuffer capabilty but does not implement CanUnbuffer\"","messagePattern":"in\\.getClass\\(\\)\\.getName\\(\\) \\+ \": claims unbuffer capabilty but does not implement CanUnbuffer\"","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/StreamCapabilitiesPolicy.java","lineNumber":55,"sourceCode":"          StreamCapabilitiesPolicy.class);\n  /**\n   * Implement the policy for {@link CanUnbuffer#unbuffer()}.\n   *\n   * @param in the input stream\n   */\n  public static void unbuffer(InputStream in) {\n    try {\n      if (in instanceof StreamCapabilities\n          && ((StreamCapabilities) in).hasCapability(\n          StreamCapabilities.UNBUFFER)) {\n        ((CanUnbuffer) in).unbuffer();\n      } else {\n        LOG.debug(in.getClass().getName() + \":\"\n                + \" does not implement StreamCapabilities\"\n                + \" and the unbuffer capability\");\n      }\n    } catch (ClassCastException e) {\n      throw new UnsupportedOperationException(in.getClass().getName() + \": \"\n              + CAN_UNBUFFER_NOT_IMPLEMENTED_MESSAGE);\n    }\n  }\n}\n\n","sourceCodeStart":37,"sourceCodeEnd":61,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/StreamCapabilitiesPolicy.java#L37-L61","documentation":"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'.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\npublic class MyInputStream extends InputStream\n    implements StreamCapabilities {\n  public boolean hasCapability(String c) {\n    return StreamCapabilities.UNBUFFER.equals(c); // promise without implementation\n  }\n}\n\n// after\npublic class MyInputStream extends InputStream\n    implements StreamCapabilities, CanUnbuffer {\n  public boolean hasCapability(String c) {\n    return StreamCapabilities.UNBUFFER.equals(c);\n  }\n  public void unbuffer() { /* release read-ahead buffers */ }\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"public static boolean canUnbuffer(java.io.InputStream in) {\n  return in instanceof org.apache.hadoop.fs.CanUnbuffer\n      && in instanceof org.apache.hadoop.fs.StreamCapabilities\n      && ((org.apache.hadoop.fs.StreamCapabilities) in)\n          .hasCapability(org.apache.hadoop.fs.StreamCapabilities.UNBUFFER);\n}\n\n// usage: if (canUnbuffer(in)) ((CanUnbuffer) in).unbuffer(); else LOG.debug(\"no unbuffer\");","tryCatchPattern":"try {\n  StreamCapabilitiesPolicy.unbuffer(in);\n} catch (UnsupportedOperationException e) {\n  // message: \"<Class>: claims unbuffer capabilty but does not implement CanUnbuffer\"\n  // -> bug in the stream implementation; fix the stream class, do not swallow\n  LOG.error(\"Stream advertises unbuffer but cannot unbuffer: {}\", in.getClass(), e);\n}","preventionTips":["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"],"tags":["hadoop","stream-capabilities","unbuffer","interface-contract"],"backgroundTag":"capability-contract-violation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}