{"record":{"id":"d53130c519f1502b","repo":"apache/hadoop","slug":"invalid-options-opts-getclass","errorCode":null,"errorMessage":"Invalid options \" + opts.getClass()","messagePattern":"Invalid options \" \\+ opts\\.getClass\\(\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/impl/LevelDBFileRegionAliasMap.java","lineNumber":79,"sourceCode":"  @Override\n  public void setConf(Configuration conf) {\n    opts.setConf(conf);\n    this.conf = conf;\n  }\n\n  @Override\n  public Configuration getConf() {\n    return conf;\n  }\n\n  @Override\n  public Reader<FileRegion> getReader(Reader.Options opts, String blockPoolID)\n      throws IOException {\n    if (null == opts) {\n      opts = this.opts;\n    }\n    if (!(opts instanceof LevelDBOptions)) {\n      throw new IllegalArgumentException(\"Invalid options \" + opts.getClass());\n    }\n    LevelDBOptions o = (LevelDBOptions) opts;\n    return new LevelDBFileRegionAliasMap.LevelDBReader(\n        createDB(o.levelDBPath, false, blockPoolID));\n  }\n\n  @Override\n  public Writer<FileRegion> getWriter(Writer.Options opts, String blockPoolID)\n      throws IOException {\n    if (null == opts) {\n      opts = this.opts;\n    }\n    if (!(opts instanceof LevelDBOptions)) {\n      throw new IllegalArgumentException(\"Invalid options \" + opts.getClass());\n    }\n    LevelDBOptions o = (LevelDBOptions) opts;\n    return new LevelDBFileRegionAliasMap.LevelDBWriter(\n        createDB(o.levelDBPath, true, blockPoolID));","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/impl/LevelDBFileRegionAliasMap.java#L61-L97","documentation":"LevelDBFileRegionAliasMap.getReader requires its own LevelDBOptions subclass (carrying the leveldb path) so it can open the local DB; any other Reader.Options implementation — including options belonging to other alias map implementations — is rejected with IllegalArgumentException before any I/O happens.","triggerScenarios":"Passing a TextFileRegionAliasMap.ReaderOptions, InMemoryLevelDB options, or a hand-rolled Options class to getReader of LevelDBFileRegionAliasMap.","commonSituations":"Generic factory code that abstracts over BlockAliasMap implementations but shares one Options object; refactoring from the text alias map to the leveldb alias map without updating call sites.","solutions":["Pass null to use the map's defaults built from configuration (dfs.provided.aliasmap.leveldb.path)","Or construct the right type: new LevelDBFileRegionAliasMap.LevelDBOptions() and set its levelDBPath","Keep Options objects paired with their implementation — don't share them across alias map classes"],"exampleFix":"// before\nBlockAliasMap.Reader.Options o = new TextFileRegionAliasMap.ReaderOptions();\nReader<FileRegion> r = leveldbAliasMap.getReader(o, bpid);\n\n// after\nReader<FileRegion> r = leveldbAliasMap.getReader(null, bpid); // uses conf defaults","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean validReaderOpts(LevelDBFileRegionAliasMap map,\n    BlockAliasMap.Reader.Options o) {\n  return o == null || o instanceof LevelDBFileRegionAliasMap.LevelDBOptions;\n}","tryCatchPattern":null,"preventionTips":["Prefer passing null and letting configuration drive defaults","Never share Options instances across different BlockAliasMap implementations"],"tags":["provided-storage","aliasmap","leveldb","options","illegal-argument"],"backgroundTag":"options-type-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}