{"record":{"id":"ed9817f5ffe9a883","repo":"apache/hadoop","slug":"use-token-renew-instead","errorCode":null,"errorMessage":"Use Token.renew instead","messagePattern":"Use Token\\.renew instead","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"info","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/main/java/org/apache/hadoop/mapred/YARNRunner.java","lineNumber":197,"sourceCode":"      this.defaultFileContext = FileContext.getFileContext(this.conf);\n    } catch (UnsupportedFileSystemException ufe) {\n      throw new RuntimeException(\"Error in instantiating YarnClient\", ufe);\n    }\n  }\n  \n  @Private\n  /**\n   * Used for testing mostly.\n   * @param resMgrDelegate the resource manager delegate to set to.\n   */\n  public void setResourceMgrDelegate(ResourceMgrDelegate resMgrDelegate) {\n    this.resMgrDelegate = resMgrDelegate;\n  }\n  \n  @Override\n  public void cancelDelegationToken(Token<DelegationTokenIdentifier> arg0)\n      throws IOException, InterruptedException {\n    throw new UnsupportedOperationException(\"Use Token.renew instead\");\n  }\n\n  @Override\n  public TaskTrackerInfo[] getActiveTrackers() throws IOException,\n      InterruptedException {\n    return resMgrDelegate.getActiveTrackers();\n  }\n\n  @Override\n  public JobStatus[] getAllJobs() throws IOException, InterruptedException {\n    return resMgrDelegate.getAllJobs();\n  }\n\n  @Override\n  public TaskTrackerInfo[] getBlacklistedTrackers() throws IOException,\n      InterruptedException {\n    return resMgrDelegate.getBlacklistedTrackers();\n  }","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/main/java/org/apache/hadoop/mapred/YARNRunner.java#L179-L215","documentation":"YARNRunner.cancelDelegationToken is intentionally not implemented and always throws UnsupportedOperationException telling the caller to use the Hadoop security Token API instead. Under YARN, delegation-token lifecycle is managed through org.apache.hadoop.security.token.Token (obtained from the RM/HS via the client protocol), so the legacy ClientProtocol cancel/renew entry points are stubs. Note the message says 'renew' but the method is cancel — both legacy variants delegate to the Token API.","triggerScenarios":"Calling cancelDelegationToken on a JobClient/YARNRunner-backed Cluster instance, e.g. legacy code written against the old JobClient token APIs or tools that walk ClientProtocol and invoke every method.","commonSituations":"Porting pre-YARN (MR1) code that cancelled delegation tokens via the job client; Generic client frameworks that reflectively invoke all ClientProtocol methods; Custom token-management tooling unaware that YARN moved renew/cancel to Token","solutions":["Replace the call with token.cancel() on the org.apache.hadoop.security.token.Token instance obtained from the ResourceManager/JobHistoryServer (getDelegationToken)","Remove the legacy cancel/renew code path entirely for mapreduce.framework.name=yarn","For HS tokens, fetch the token via the history server client and cancel against the issuing service"],"exampleFix":"// before\nrunner.cancelDelegationToken(token); // UnsupportedOperationException\n\n// after\norg.apache.hadoop.security.token.Token<\n    org.apache.hadoop.mapreduce.security.token.delegation.DelegationTokenIdentifier> t =\n  (Token<DelegationTokenIdentifier>) token;\nt.cancel(new org.apache.hadoop.conf.Configuration()); // via Token API","handlingStrategy":"validation","validationCode":"if (runner instanceof org.apache.hadoop.mapred.YARNRunner) {\n  // ClientProtocol token cancel is a stub on YARN - skip and use Token API\n  token.cancel(conf);\n} else {\n  runner.cancelDelegationToken(token);\n}","typeGuard":"boolean isLegacyTokenApiSupported(ClientProtocol p) {\n  return !(p instanceof org.apache.hadoop.mapred.YARNRunner);\n}","tryCatchPattern":null,"preventionTips":["Never call cancel/renewDelegationToken on ClientProtocol when mapreduce.framework.name=yarn","Perform all delegation-token lifecycle on org.apache.hadoop.security.token.Token against the issuing service","Wrap legacy MR1 code paths behind an abstraction so YARN stubs are never reached"],"tags":["hadoop","mapreduce","yarn","delegation-token","unsupported-operation","api-migration"],"backgroundTag":"unsupported-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}