{"record":{"id":"0bff877c3dbcb0ef","repo":"apache/hadoop","slug":"param-class-0-does-not-have-default-constructo","errorCode":null,"errorMessage":"Param class [{0}] does not have default constructor","messagePattern":"Param class \\[(.+?)\\] does not have default constructor","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":400,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ParametersProvider.java","lineNumber":53,"sourceCode":"@InterfaceAudience.Private\npublic class ParametersProvider {\n\n  private String driverParam;\n  private Class<? extends Enum> enumClass;\n  private Map<Enum, Class<Param<?>>[]> paramsDef;\n\n  public ParametersProvider(String driverParam, Class<? extends Enum> enumClass,\n      Map<Enum, Class<Param<?>>[]> paramsDef) {\n    this.driverParam = driverParam;\n    this.enumClass = enumClass;\n    this.paramsDef = paramsDef;\n  }\n\n  private Param<?> newParam(Class<Param<?>> paramClass) {\n    try {\n      return paramClass.newInstance();\n    } catch (Exception ex) {\n      throw new UnsupportedOperationException(\n        MessageFormat.format(\"Param class [{0}] does not have default constructor\",\n            paramClass.getName()));\n    }\n  }\n\n  public Parameters get(HttpServletRequest request) {\n    Map<String, List<Param<?>>> map = new HashMap<>();\n\n    Map<String, String[]> queryString = request.getParameterMap();\n    String str = null;\n    if(queryString.containsKey(driverParam)) {\n      str = queryString.get(driverParam)[0];\n    }\n    if (str == null) {\n      throw new IllegalArgumentException(\n        MessageFormat.format(\"Missing Operation parameter [{0}]\",\n                             driverParam));\n    }","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ParametersProvider.java#L35-L71","documentation":"ParametersProvider.newParam (ParametersProvider.java:53) instantiates every registered Param class reflectively via paramClass.newInstance(); if the class lacks an accessible no-argument constructor (non-static inner class, non-public class, abstract class, or only parameterized constructors) it throws UnsupportedOperationException(\"Param class [...] does not have default constructor\"). It fires at request-processing time while building the Parameters object for the incoming operation, turning a wiring bug into a runtime 500.","triggerScenarios":"Extending the httpfs wsrs framework with a custom Param subclass that is (a) a non-static inner class, (b) only defines constructors with arguments, or (c) is package-private or abstract, then registering it in the provider's paramsDef map. The first matching request hits newParam and throws.","commonSituations":"A fork adds a WebHDFS-style operation whose param class was written as an inner class; a refactor makes a static subclass non-static; someone adds an args-taking constructor and deletes the no-arg one; JDK visibility changes make the constructor inaccessible.","solutions":["Make every Param subclass a public static class with a public no-arg constructor — mirror the params in HttpFSParametersProvider.","Re-add the no-arg constructor when a parameterized one is introduced.","Move inner param classes to top level or mark them static.","Add a startup/registration smoke test that instantiates every registered param class."],"exampleFix":"// before\npublic class MyParams {\n  class OffsetParam extends IntegerParam { // inner class: newInstance() fails\n    OffsetParam(int d) { super(\"offset\", d); }\n  }\n}\n\n// after\npublic static class OffsetParam extends IntegerParam {\n  public OffsetParam() { super(\"offset\", 1); } // public no-arg constructor\n}","handlingStrategy":"validation","validationCode":"for (Class<Param<?>> c : paramsDef.get(op)) {\n  if (!java.lang.reflect.Modifier.isPublic(c.getModifiers())) throw new IllegalStateException(c + \" must be public\");\n  try { c.getConstructor(); } catch (NoSuchMethodException e) {\n    throw new IllegalStateException(c + \" needs a public no-arg constructor\");\n  }\n}","typeGuard":"static boolean hasPublicNoArgCtor(Class<?> c) {\n  return java.lang.reflect.Modifier.isPublic(c.getModifiers())\n      && java.util.Arrays.stream(c.getConstructors()).anyMatch(ctor -> ctor.getParameterCount() == 0);\n}","tryCatchPattern":"try {\n  parameters = provider.get(request);\n} catch (UnsupportedOperationException ex) {\n  // server wiring bug: a registered Param class is not instantiable\n  LOG.error(\"Param registration broken\", ex);\n  return serverError();\n}","preventionTips":["Every Param subclass: public static class with a public no-arg constructor.","Run a registration smoke test that instantiates all param classes at startup.","Re-run the smoke test after refactors that change class nesting or constructors."],"tags":["java","hadoop","httpfs","reflection","jax-rs","constructor"],"backgroundTag":"missing-default-constructor","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}