{"record":{"id":"45c48a814111628f","repo":"theonedev/onedev","slug":"invalid-element-type","errorCode":null,"errorMessage":"Invalid element type: ","messagePattern":"Invalid element type: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/util/BeanUtils.java","lineNumber":280,"sourceCode":"\t\tif (setter == null) {\n\t\t\tString message = String.format(\"Cannot find setter (class: %s, property: %s, type: %s)\", \n\t\t\t\t\tgetter.getDeclaringClass().getName(), getPropertyName(getter), getter.getReturnType().getName());\n\t\t\tthrow new RuntimeException(message);\n\t\t}\n\t\treturn setter;\n\t}\n\n\tpublic static String getDisplayName(AnnotatedElement element) {\n\t\tif (element instanceof Class)\n\t\t\treturn WordUtils.uncamel(((Class<?>)element).getSimpleName());\n\t\telse if (element instanceof Field) \n\t\t\treturn WordUtils.uncamel(WordUtils.capitalize(((Field)element).getName()));\n\t\telse if (element instanceof Method)\n\t\t\treturn StringUtils.substringAfter(WordUtils.uncamel(((Method)element).getName()), \" \");\n\t\telse if (element instanceof Package) \n\t\t\treturn ((Package)element).getName();\n\t\telse\n\t\t\tthrow new RuntimeException(\"Invalid element type: \" + element.getClass().getName());\n\t}\n\t\n}\n","sourceCodeStart":262,"sourceCodeEnd":284,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/util/BeanUtils.java#L262-L284","documentation":"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.","triggerScenarios":"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).","commonSituations":"Running on a newer JDK that adds new AnnotatedElement subtypes, or passing custom/proxied reflective wrappers into the utility.","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."],"exampleFix":"// before\nString name = BeanUtils.getDisplayName(someCustomAnnotatedElement); // throws\n// after\nif (element instanceof Field || element instanceof Method || element instanceof Package) {\n  String name = BeanUtils.getDisplayName(element);\n}","handlingStrategy":"type-guard","validationCode":"if (!(element instanceof Field) && !(element instanceof Method) && !(element instanceof Package)) return null;","typeGuard":"static boolean hasSupportedDisplayName(AnnotatedElement e) {\n    return e instanceof Field || e instanceof Method || e instanceof Package;\n}","tryCatchPattern":"try {\n    name = BeanUtils.getDisplayName(element);\n} catch (RuntimeException e) {\n    name = element.toString(); // fallback\n}","preventionTips":["Only feed Field/Method/Package elements into BeanUtils display helpers.","Wrap custom AnnotatedElement implementations before calling third-party utils."],"tags":["reflection","type-mismatch","runtime"],"backgroundTag":"unsupported-operation","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}