pinpoint-apm/pinpoint · error · RuntimeException
invalid Type
Error message
invalid Type
What it means
RuntimeException("invalid Type") thrown by InterceptorDefinitionFactory.createInterceptorTypeHandler when an interceptor class does not declare exactly 2 methods. Pinpoint's interceptor contract requires exactly one before() and one after() method; any other method count (0, 1, or 3+, including bridge/synthetic methods) fails this invariant.
Source
Thrown at agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/interceptor/InterceptorDefinitionFactory.java:118
addTypeHandler(typeHandlerList, BlockAroundInterceptor5.class, InterceptorType.BASIC);
addTypeHandler(typeHandlerList, BlockStaticAroundInterceptor.class, InterceptorType.STATIC);
addTypeHandler(typeHandlerList, BlockApiIdAwareAroundInterceptor.class, InterceptorType.API_ID_AWARE);
return typeHandlerList;
}
private void addTypeHandler(List<TypeHandler> typeHandlerList, Class<? extends Interceptor> interceptorClazz, InterceptorType arrayArgs) {
final TypeHandler typeHandler = createInterceptorTypeHandler(interceptorClazz, arrayArgs);
typeHandlerList.add(typeHandler);
}
private TypeHandler createInterceptorTypeHandler(Class<? extends Interceptor> interceptorClazz, InterceptorType interceptorType) {
Objects.requireNonNull(interceptorClazz, "interceptorClazz");
Objects.requireNonNull(interceptorType, "interceptorType");
final Method[] declaredMethods = interceptorClazz.getDeclaredMethods();
if (declaredMethods.length != 2) {
throw new RuntimeException("invalid Type");
}
final String before = "before";
final Method beforeMethod = findMethodByName(declaredMethods, before);
final Class<?>[] beforeParamList = beforeMethod.getParameterTypes();
final String after = "after";
final Method afterMethod = findMethodByName(declaredMethods, after);
final Class<?>[] afterParamList = afterMethod.getParameterTypes();
return new TypeHandler(interceptorClazz, interceptorType, before, beforeParamList, after, afterParamList);
}
private Method findMethodByName(Method[] declaredMethods, String methodName) {
Method findMethod = null;
int count = 0;
for (Method method : declaredMethods) {
if (method.getName().equals(methodName)) {View on GitHub (pinned to 744c3d3075)
Solutions
- Ensure the interceptor class declares exactly two methods: one before(...) and one after(...).
- Move any helper logic into a separate utility class or inline it.
- If you need shared code, use composition with a separate delegate object rather than extra declared methods.
- Check for compiler-generated methods (e.g. overloads) and remove them.
Example fix
// before
class MyInterceptor implements Interceptor {
public void before(Object t, Object[] a) { helper(); }
public void after(Object t, Object r, Throwable th) { }
private void helper() { } // extra declared method -> invalid Type
}
// after
class MyInterceptor implements Interceptor {
public void before(Object t, Object[] a) { /* inline helper */ }
public void after(Object t, Object r, Throwable th) { }
} Defensive patterns
Strategy: validation
Validate before calling
if (interceptorClazz.getDeclaredMethods().length != 2) {
throw new IllegalArgumentException(interceptorClazz + " must declare exactly before() and after()");
} Try / catch
try { factory.createInterceptorDefinition(clazz); } catch (RuntimeException e) { if ("invalid Type".equals(e.getMessage())) { /* inspect getDeclaredMethods() and remove extras */ } throw e; } Prevention
- Never add helper methods to interceptor classes
- Use composition for shared logic
- Add a build-time check that every interceptor has exactly two declared methods
When it happens
Trigger: createInterceptorTypeHandler invoked with an interceptor class whose getDeclaredMethods().length != 2 - e.g. a class with extra helper methods, abstract methods, or a base class adding methods.
Common situations: Adding a private helper or an extra overload to an interceptor class, extending another interceptor class and inheriting extra declared methods, or declaring toString/equals-style methods alongside before/after (getDeclaredMethods excludes inherited but includes everything declared locally).
Related errors
- unsupported Interceptor Type. ${interceptorClazz.getName()}
- invocation fail, className=
- not found 'set' method, className=
- result-replace interceptor requires an object or array retur
- ${methodName} not found
AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07).
Data as JSON: /api/errors/268c6adaef8d681f.
Report an issue: GitHub.