{"record":{"id":"a8cc7c85474867e7","repo":"apache/hadoop","slug":"is-expected-to-be-an-instance-of-org-apache-had","errorCode":null,"errorMessage":"{} is expected to be an instance of org.apache.hadoop.mapreduce.v2.hs.CachedHistoryStorage","messagePattern":"(.+?) is expected to be an instance of org\\.apache\\.hadoop\\.mapreduce\\.v2\\.hs\\.CachedHistoryStorage","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/JobHistory.java","lineNumber":249,"sourceCode":"    // currently there is 1 to 1 mapping between app and job id\n    org.apache.hadoop.mapreduce.JobID oldJobID = TypeConverter.fromYarn(appID);\n    Map<JobId, Job> jobs = new HashMap<JobId, Job>();\n    JobId jobID = TypeConverter.toYarn(oldJobID);\n    jobs.put(jobID, getJob(jobID));\n    return jobs;\n  }\n\n  @Override\n  public Map<JobId, Job> getAllJobs() {\n    return storage.getAllPartialJobs();\n  }\n\n  public void refreshLoadedJobCache() {\n    if (getServiceState() == STATE.STARTED) {\n      if (storage instanceof CachedHistoryStorage) {\n        ((CachedHistoryStorage) storage).refreshLoadedJobCache();\n      } else {\n        throw new UnsupportedOperationException(storage.getClass().getName()\n            + \" is expected to be an instance of \"\n            + CachedHistoryStorage.class.getName());\n      }\n    } else {\n      LOG.warn(\"Failed to execute refreshLoadedJobCache: JobHistory service is not started\");\n    }\n  }\n\n  @VisibleForTesting\n  HistoryStorage getHistoryStorage() {\n    return storage;\n  }\n  \n  /**\n   * Look for a set of partial jobs.\n   * \n   * @param offset\n   *          the offset into the list of jobs.","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/JobHistory.java#L231-L267","documentation":"refreshLoadedJobCache reloads the loaded-jobs cache but is only meaningful for CachedHistoryStorage, the default HistoryStorage. If a custom storage implementation was configured (JobHistory.createHistoryStorage reads the storage class from configuration), the instanceof check fails and UnsupportedOperationException names the mismatched class. The call is a no-op-with-warning when the service is not STARTED, so this exception specifically means: running service plus non-cached storage.","triggerScenarios":"Invoking the admin refresh operation (refreshLoadedJobCache) while a custom HistoryStorage class is configured; a storage wrapper that does not extend CachedHistoryStorage.","commonSituations":"Deployments plugging in custom history storage and then invoking cache refresh; configuration copied from another deployment that sets the storage class.","solutions":["Remove the custom mapreduce.jobhistory.storage.class setting to fall back to CachedHistoryStorage if cache refresh is needed.","Make the custom class extend org.apache.hadoop.mapreduce.v2.hs.CachedHistoryStorage.","Skip invoking refreshLoadedJobCache when a non-cached storage is deployed."],"exampleFix":"// before\njobHistory.refreshLoadedJobCache();\n\n// after\nif (jobHistory.getHistoryStorage()\n    instanceof org.apache.hadoop.mapreduce.v2.hs.CachedHistoryStorage) {\n  jobHistory.refreshLoadedJobCache();\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"private static boolean isCachedStorage(HistoryStorage storage) {\n  return storage instanceof org.apache.hadoop.mapreduce.v2.hs.CachedHistoryStorage;\n}","tryCatchPattern":null,"preventionTips":["Guard admin refresh calls with an instanceof check on the storage.","Document that cache refresh requires CachedHistoryStorage.","Extend CachedHistoryStorage in custom storage implementations that must support refresh."],"tags":["mapreduce","job-history-server","api-misuse","type-check"],"backgroundTag":"type-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}