theonedev/onedev · error · RuntimeException
Invalid element type:
Error message
Invalid element type:
What it means
BeanUtils.getDisplayName derives a human-readable name from an AnnotatedElement (Field, Method, or Package). It throws this RuntimeException when the element is none of those three types, which indicates an internal invariant violation since AnnotatedElement's common direct implementations are exhausted.
Source
Thrown at server-core/src/main/java/io/onedev/server/util/BeanUtils.java:280
if (setter == null) {
String message = String.format("Cannot find setter (class: %s, property: %s, type: %s)",
getter.getDeclaringClass().getName(), getPropertyName(getter), getter.getReturnType().getName());
throw new RuntimeException(message);
}
return setter;
}
public static String getDisplayName(AnnotatedElement element) {
if (element instanceof Class)
return WordUtils.uncamel(((Class<?>)element).getSimpleName());
else if (element instanceof Field)
return WordUtils.uncamel(WordUtils.capitalize(((Field)element).getName()));
else if (element instanceof Method)
return StringUtils.substringAfter(WordUtils.uncamel(((Method)element).getName()), " ");
else if (element instanceof Package)
return ((Package)element).getName();
else
throw new RuntimeException("Invalid element type: " + element.getClass().getName());
}
}
View on GitHub (pinned to d44925c47c)
Solutions
- Only pass Field, Method, or Package instances to getDisplayName.
- Check the element type before calling: if (!(element instanceof Field || element instanceof Method || element instanceof Package)) skip or handle separately.
- If running on a newer JDK with new element kinds, handle them explicitly before calling or upgrade/patch BeanUtils.
Example fix
// before
String name = BeanUtils.getDisplayName(someCustomAnnotatedElement); // throws
// after
if (element instanceof Field || element instanceof Method || element instanceof Package) {
String name = BeanUtils.getDisplayName(element);
} Defensive patterns
Strategy: type-guard
Validate before calling
if (!(element instanceof Field) && !(element instanceof Method) && !(element instanceof Package)) return null;
Type guard
static boolean hasSupportedDisplayName(AnnotatedElement e) {
return e instanceof Field || e instanceof Method || e instanceof Package;
} Try / catch
try {
name = BeanUtils.getDisplayName(element);
} catch (RuntimeException e) {
name = element.toString(); // fallback
} Prevention
- Only feed Field/Method/Package elements into BeanUtils display helpers.
- Wrap custom AnnotatedElement implementations before calling third-party utils.
When it happens
Trigger: Passing an AnnotatedElement that is not a Field, Method, or Package to BeanUtils.getDisplayName — in practice only possible with a custom AnnotatedElement implementation or future JDK element kinds (e.g. records/components on newer JDKs).
Common situations: Running on a newer JDK that adds new AnnotatedElement subtypes, or passing custom/proxied reflective wrappers into the utility.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Getter not found (class: %s, property: %s)
- Not recognized getter method (class: %s, method: %s)
- Cannot find setter (class: %s, property: %s, type: %s)
- Parameter types do not match: expected type {expected} but f
- Unknown collection element class (bean: X, property: Y)
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/45c48a814111628f.
Report an issue: GitHub.