quarkusio/quarkus · error · java.lang.RuntimeException
Cannot read field value: ${className}#${name}
Error message
Cannot read field value: ${className}#${name} What it means
Reflections.readField() fetches a declared field's value reflectively, calling setAccessible(true) if needed. Any NoSuchFieldException, SecurityException, IllegalArgumentException, or IllegalAccessException is rethrown as a RuntimeException identifying the class and field name. This typically means the field name is wrong or reflective access was denied.
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Reflections.java:160
// this method is only used to instantiate beans, so throwing `CreationException` is fine
throw new CreationException(cause);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {
throw new RuntimeException("Cannot invoke constructor: " + clazz.getName(), e);
}
}
throw new RuntimeException(
"No " + clazz.getName() + "constructor found for params: " + Arrays.toString(parameterTypes));
}
public static Object readField(Class<?> clazz, String name, Object instance) {
try {
Field field = clazz.getDeclaredField(name);
if (!field.canAccess(instance)) {
field.setAccessible(true);
}
return field.get(instance);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException("Cannot read field value: " + clazz.getName() + "#" + name, e);
}
}
public static void writeField(Class<?> clazz, String name, Object instance, Object value) {
try {
Field field = clazz.getDeclaredField(name);
if (!field.canAccess(instance)) {
field.setAccessible(true);
}
field.set(instance, value);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException("Cannot set field value: " + clazz.getName() + "#" + name, e);
}
}
public static Object invokeMethod(Class<?> clazz, String name, Class<?>[] paramTypes, Object instance, Object[] args) {
try {
Method method = clazz.getDeclaredMethod(name, paramTypes);View on GitHub (pinned to e1c734241f)
Solutions
- Verify the field name and that it is declared on the exact class passed in
- Register the field/class for reflection when building a native image
- Pass an instance compatible with the declaring class (or null for static fields)
- Prefer a getter/accessor API over reflective field access when available
Example fix
// before String v = (String) Reflections.readField(Config.class, "valeu", config); // after String v = (String) Reflections.readField(Config.class, "value", config);
Defensive patterns
Strategy: validation
Validate before calling
try { clazz.getDeclaredField(name); } catch (NoSuchFieldException e) {
throw new IllegalArgumentException("Field " + name + " missing on " + clazz);
} Type guard
static boolean hasField(Class<?> c, String name) { try { c.getDeclaredField(name); return true; } catch (NoSuchFieldException e) { return false; } } Try / catch
try { return Reflections.readField(clazz, name, instance); }
catch (RuntimeException e) { log.warn("Field read failed: " + clazz.getName() + "#" + name, e); return fallback; } Prevention
- Prefer getters over reflective field access
- Register classes/fields for reflection in native builds
- Verify field names after refactors with tests
When it happens
Trigger: Calling Reflections.readField(clazz, name, instance) where clazz has no declared field `name`, a security manager / module rules block access, the instance is not of the right type (IllegalArgumentException), or the field cannot be accessed (IllegalAccessException, e.g. final or inaccessible in native mode without configuration).
Common situations: Field renamed after a refactor while extension/test code still uses the old name; accessing private fields of JDK/library classes under strong encapsulation; GraalVM native image where the field was not registered for reflection; passing a null or mismatched instance.
Related errors
- Cannot set field value: ${className}#${name}
- Cannot invoke constructor: ${className}
- No ${className}constructor found for params: ${parameterType
- Not an array type ${type}
- Unsupported injection point target: <injectionPoint>
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/4ec866ad4bdea6e0.
Report an issue: GitHub.