{"record":{"id":"3b45bc10ec438efa","repo":"apache/hadoop","slug":"theclass-getname-could-not-be-constructed","errorCode":null,"errorMessage":"${theClass.getName()} could not be constructed.","messagePattern":"(.+?) could not be constructed\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallQueueManager.java","lineNumber":153,"sourceCode":"    }\n\n    // Otherwise return default value.\n    LOG.info(\"{} not specified set default value is {}\",\n        IPC_CALLQUEUE_SERVER_FAILOVER_ENABLE, IPC_CALLQUEUE_SERVER_FAILOVER_ENABLE_DEFAULT);\n    return CommonConfigurationKeys.IPC_CALLQUEUE_SERVER_FAILOVER_ENABLE_DEFAULT;\n  }\n\n  private static <T extends RpcScheduler> T createScheduler(\n      Class<T> theClass, int priorityLevels, String ns, Configuration conf) {\n    // Used for custom, configurable scheduler\n    try {\n      Constructor<T> ctor = theClass.getDeclaredConstructor(int.class,\n          String.class, Configuration.class);\n      return ctor.newInstance(priorityLevels, ns, conf);\n    } catch (RuntimeException e) {\n      throw e;\n    } catch (InvocationTargetException e) {\n      throw new RuntimeException(theClass.getName()\n          + \" could not be constructed.\", e.getCause());\n    } catch (Exception e) {\n    }\n\n    try {\n      Constructor<T> ctor = theClass.getDeclaredConstructor(int.class);\n      return ctor.newInstance(priorityLevels);\n    } catch (RuntimeException e) {\n      throw e;\n    } catch (InvocationTargetException e) {\n      throw new RuntimeException(theClass.getName()\n          + \" could not be constructed.\", e.getCause());\n    } catch (Exception e) {\n    }\n\n    // Last attempt\n    try {\n      Constructor<T> ctor = theClass.getDeclaredConstructor();","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallQueueManager.java#L135-L171","documentation":"CallQueueManager.createScheduler reflectively instantiates the class configured under ipc.<port>.scheduler.impl (default FairCallQueueRpcScheduler). It first tries the constructor (int priorityLevels, String ns, Configuration conf). This RuntimeException is thrown from the InvocationTargetException handler: that constructor exists but its body threw, and the original exception is attached as getCause(). (NoSuchMethodException is silently swallowed by `catch (Exception e) {}` and the next signature is tried.)","triggerScenarios":"A custom RpcScheduler whose (int, String, Configuration) constructor throws — typically an NPE or IllegalArgumentException while reading namespaced configuration keys (e.g., ipc.<port>.scheduler.*) or instantiating its own dependencies; a scheduler class that partially initializes and aborts.","commonSituations":"Writing a custom IPC scheduler plug-in and testing it on a live RPC server (NameNode/DataNode/ResourceManager ports); typo'd or missing config keys read inside the constructor; constructor expecting a different namespace argument than what CallQueueManager passes.","solutions":["Read the root cause: the RuntimeException's getCause() holds the actual exception thrown inside your constructor — log/print it before anything else.","Fix the failing code inside the custom scheduler's constructor (usually bad or missing config lookups keyed off ns).","Unit-test the constructor directly with the exact arguments CallQueueManager passes: new MyScheduler(priorityLevels, \"ipc.<port>\", conf).","As a fallback provide a simpler (int) or no-arg constructor that does not throw."],"exampleFix":"// before\npublic MyScheduler(int priorityLevels, String ns, Configuration conf) {\n  this.weights = conf.getInts(ns + \".weights\"); // NPE later if null... or throws here on bad key\n}\n\n// after\npublic MyScheduler(int priorityLevels, String ns, Configuration conf) {\n  this.weights = conf.getInts(ns + \".weights\");\n  if (weights == null || weights.length == 0) {\n    this.weights = new int[priorityLevels]; // sane default, do not throw\n    Arrays.fill(this.weights, 1);\n  }\n}","handlingStrategy":"validation","validationCode":"// before pointing ipc.<port>.scheduler.impl at it, prove the constructor works:\nString ns = \"ipc.8020\";\nint levels = conf.getInt(ns + \".scheduler.priority.levels\", 4);\nRpcScheduler s = new MyScheduler(levels, ns, conf); // must not throw\n","typeGuard":null,"tryCatchPattern":"try {\n  server.start(); // reflective scheduler construction happens here\n} catch (RuntimeException e) {\n  Throwable root = e.getCause() != null ? e.getCause() : e; // InvocationTargetException cause\n  LOG.error(\"Scheduler construction failed: {}\", root, e);\n}","preventionTips":["Unit-test the (int, String, Configuration) constructor with the server's real namespaced config.","Never throw from plug-in constructors; validate lazily after startup.","Run `hdfs getconf -confKey ipc.<port>.scheduler.impl` to confirm what will be instantiated.","Log and surface getCause() so the real failure is not buried under 'could not be constructed'."],"tags":["hadoop","ipc","rpc-server","callqueue","reflection","plugin","server-startup"],"backgroundTag":"plugin-constructor-threw-exception","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}