apache/iceberg · error · NoSuchMethodException

Cannot find constructor for

Error message

Cannot find constructor for ${baseClass}
${formatProblems(problems)}

What it means

DynConstructors.Builder.buildChecked() searches for a constructor matching the classes/arguments added to the builder and returns it as a Ctor. If no matching constructor (or class) was found, it throws a NoSuchMethodException listing every candidate it tried and why it failed. The checked variant lets callers explicitly handle missing implementations.

Solutions

  1. Verify the configured class name is fully qualified and spelled correctly
  2. Ensure the jar providing the class is on the runtime classpath
  3. Check the class exposes a constructor matching the argument types passed to the builder
  4. Call build() instead of buildChecked() if a RuntimeException with the same details is preferred

Example fix

// before
Ctor<FileIO> ctor = DynConstructors.builder().impl("com.example.MyFileIO").buildChecked(); // NoSuchMethodException
// after (verify class exists first)
if (DynClasses.builder().impl("com.example.MyFileIO").buildChecked() != null) {
  Ctor<FileIO> ctor = DynConstructors.builder().impl("com.example.MyFileIO").buildChecked();
}
Defensive patterns

Strategy: try-catch

Validate before calling

try { Class.forName("com.example.MyFileIO", true, loader); } catch (ClassNotFoundException e) { /* fail fast with clear message */ }

Try / catch

try { Ctor<C> ctor = builder.buildChecked(); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Bad impl config: " + e.getMessage(), e); }

Prevention

When it happens

Trigger: Calling buildChecked() when the target class name is wrong/misspelled, the class is not on the classpath, or no constructor matches the supplied parameter types (e.g. the catalog or file-io impl class was configured with a name whose constructor signature differs from the arguments passed).

Common situations: Typo in an impl property like org.apache.iceberg.aws.s3.S3FileIO; a jar is missing at runtime (shaded/not shipped); the implementation class was refactored and its constructor signature changed while config still points at the old one.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/c4867e80fe3c693e. Report an issue: GitHub.

Appendix: source

Thrown at common/src/main/java/org/apache/iceberg/common/DynConstructors.java:282

        problems.put(methodName(targetClass, types), e);
      }
      return this;
    }

    /**
     * Returns the first valid constructor as a {@link Ctor} or throws a NoSuchMethodException if
     * there is none.
     *
     * @param <C> Java class constructed by the constructor
     * @return a {@link Ctor} with a valid implementation
     * @throws NoSuchMethodException if no implementation was found
     */
    @SuppressWarnings("unchecked")
    public <C> Ctor<C> buildChecked() throws NoSuchMethodException {
      if (ctor != null) {
        return (Ctor<C>) ctor;
      }
      throw buildCheckedException(baseClass, problems);
    }

    /**
     * Returns the first valid constructor as a {@link Ctor} or throws a RuntimeException if there
     * is none.
     *
     * @param <C> Java class constructed by the constructor
     * @return a {@link Ctor} with a valid implementation
     * @throws RuntimeException if no implementation was found
     */
    @SuppressWarnings("unchecked")
    public <C> Ctor<C> build() {
      if (ctor != null) {
        return (Ctor<C>) ctor;
      }
      throw buildRuntimeException(baseClass, problems);
    }

View on GitHub (pinned to 86d9c8fc54)