apache/dubbo · error · IllegalStateException

get attribute value of annotation failed: {method}

Error message

get attribute value of annotation failed: {method}

What it means

Thrown by AnnotationUtils.getAttributes when invoking an annotation's method via reflection (method.invoke) throws any exception. getAttributes iterates every declared method of an annotation type and reads its value; any reflective failure (access denied, annotation proxy broken, exception thrown inside the attribute method) is wrapped in this IllegalStateException.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/AnnotationUtils.java:575

     * @param annotation
     * @return
     */
    static Map<String, Object> getAttributes(Annotation annotation, boolean filterDefaultValue) {
        Class<?> annotationType = annotation.annotationType();
        Method[] methods = annotationType.getMethods();
        Map<String, Object> attributes = new LinkedHashMap<>(methods.length);
        for (Method method : methods) {
            try {
                if (method.getDeclaringClass() == Annotation.class) {
                    continue;
                }
                String name = method.getName();
                Object value = method.invoke(annotation);
                if (!filterDefaultValue || !Objects.deepEquals(value, method.getDefaultValue())) {
                    attributes.put(name, value);
                }
            } catch (Exception e) {
                throw new IllegalStateException("get attribute value of annotation failed: " + method, e);
            }
        }
        return attributes;
    }
}

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Read the wrapped cause (the chained Throwable) in the stack trace — the real reason is there, not in the message.
  2. If caused by access restrictions, ensure the calling code has ReflectPermission / module 'opens' for the annotation's package.
  3. If the annotation proxy is malformed (classpath duplication, stale serialized annotation), resolve the classpath conflict and rebuild.
  4. Catch IllegalStateException around the getAttributes call if annotation introspection is best-effort.

Example fix

// before
Map<String,Object> attrs = AnnotationUtils.getAttributes(anno, true); // may throw

// after
try {
    Map<String,Object> attrs = AnnotationUtils.getAttributes(anno, true);
} catch (IllegalStateException e) {
    // log e.getCause() and degrade gracefully
    log.warn("Cannot read annotation attributes", e.getCause());
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    Map<String,Object> attrs = AnnotationUtils.getAttributes(anno, true);
} catch (IllegalStateException e) {
    Throwable cause = e.getCause(); // the real reflective failure
    log.warn("Annotation introspection failed for {}", anno, cause);
}

Prevention

When it happens

Trigger: getAttributes(annotation, filterDefaultValue) is called and method.invoke(annotation) throws — e.g. InvocationTargetException from the attribute method, IllegalAccessException under a SecurityManager, or an annotation proxy whose state is corrupted (classpath/serialization issues).

Common situations: Running under a restrictive SecurityManager or module boundary that blocks reflective access to annotation members; a custom/serialized annotation instance whose proxy cannot resolve; JVM or annotation-processor edge cases. The underlying cause is chained (the second constructor arg 'e').

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/b3fd18537d43cd49. Report an issue: GitHub.