pinpoint-apm/pinpoint · error · IllegalStateException

invoke fail Caused by:

Error message

 invoke fail Caused by:

What it means

createClassLoader calls the cached reflective constructor via newInstance. If instantiation throws (IllegalAccessException, InstantiationException, InvocationTargetException from the target constructor), it is rethrown as IllegalStateException '<ctor> invoke fail Caused by:...'.

Source

Thrown at agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/DynamicClassLoaderFactory.java:51


    private static Constructor<? extends ClassLoader> getConstructor(String classLoaderName, ClassLoader classLoader) {
        try {
            final Class<? extends ClassLoader> classLoaderClazz =
                    (Class<? extends ClassLoader>) Class.forName(classLoaderName, true, classLoader);
            return classLoaderClazz.getDeclaredConstructor(String.class, URL[].class, ClassLoader.class, List.class);
        } catch (ReflectiveOperationException ex) {
            throw new IllegalStateException(classLoaderName +  " initialize fail Caused by:" + ex.getMessage(), ex);
        }
    }


    @Override
    public ClassLoader createClassLoader(String name, URL[] urls, ClassLoader parent, List<String> libClass) {
        try {
            return constructor.newInstance(name, urls, parent, libClass);
        } catch (ReflectiveOperationException ex) {
            throw new IllegalStateException(constructor + " invoke fail Caused by:" + ex.getMessage(), ex);
        }
    }
}

View on GitHub (pinned to 744c3d3075)

Solutions

  1. Check the Caused-by chain to find the exception thrown inside the target constructor
  2. Fix the URL[]/name/parent arguments passed into createClassLoader
  3. Make the target constructor public and ensure it does not throw on valid input
  4. Ensure no security manager / JPMS restrictions block reflective access

Example fix

// before
createClassLoader("pinpoint", new URL[]{new File("missing.jar").toURI().toURL()}, parent, libs);
// after
File jar = new File("lib/agent.jar");
if (!jar.exists()) throw new IllegalArgumentException("agent jar missing");
createClassLoader("pinpoint", new URL[]{jar.toURI().toURL()}, parent, libs);
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate args passed to createClassLoader
Objects.requireNonNull(name, "loader name");
Objects.requireNonNull(urls, "urls");
for (URL u : urls) { try { u.openStream().close(); } catch (IOException ioe) { throw new IllegalArgumentException("Unreachable classpath entry: " + u); } }

Try / catch

try { ClassLoader cl = factory.createClassLoader(name, urls, parent, libs); } catch (IllegalStateException e) { Throwable cause = e.getCause(); if (cause instanceof InvocationTargetException) { log.error("Target constructor threw: {}", cause.getCause()); } throw e; }

Prevention

When it happens

Trigger: The target classloader's constructor itself throws (e.g. invalid URLs, null name), the constructor is not public, or the declaring class failed initialization, when DynamicClassLoaderFactory.createClassLoader runs.

Common situations: Classloader constructor validating URLs and throwing on a missing jar path, security manager blocking reflective access, or class initialization errors in the custom classloader.

Related errors


AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07). Data as JSON: /api/errors/47c60b7a2abfff1e. Report an issue: GitHub.