{"record":{"id":"463eebeef2c86c1c","repo":"theonedev/onedev","slug":"code-annotation-should-be-applied-to-a-string-or","errorCode":null,"errorMessage":"@Code annotation should be applied to a String or List<String> property","messagePattern":"@Code annotation should be applied to a String or List<String> property","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/web/editable/code/CodeEditSupport.java","lineNumber":63,"sourceCode":"\t\t\t\t\t\t\t\t\t\tprotected AnnotatedElement getElement() {\n\t\t\t\t\t\t\t\t\t\t\treturn propertyDescriptor.getPropertyGetter();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic PropertyEditor<Serializable> renderForEdit(String componentId, IModel<Serializable> model) {\n\t\t\t\t\t\treturn new CodePropertyEditor(componentId, descriptor, model);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tthrow new ExplicitException(\"@Code annotation should be applied to a String or List<String> property\");\n\t\t\t}\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t@Override\n\tpublic int getPriority() {\n\t\treturn DEFAULT_PRIORITY;\n\t}\n\t\n}\n","sourceCodeStart":45,"sourceCodeEnd":76,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/web/editable/code/CodeEditSupport.java#L45-L76","documentation":"CodeEditSupport.getEditContext inspects a property annotated with @Code and builds a code editor edit context only when the property type is String or List<String>. If the @Code annotation is applied to a property of any other type, it throws this ExplicitException. The @Code annotation is only meaningful for textual/code content.","triggerScenarios":"Annotating a getter/setter with @Code when the property type is not String and not List<String> — e.g. Integer, Map, List<String[]>, or a custom type — and then rendering the bean in an editable form (BeanEditor/property editor).","commonSituations":"Authoring custom build spec, job, or issue field classes in plugins/scripts; mistakenly adding @Code to a numeric or collection-of-non-string property expecting a code editor.","solutions":["Change the property type to String (or List<String>) so it matches what @Code supports.","Remove the @Code annotation if the property should not be a code editor.","For structured data, use a different property type/edit mechanism instead of @Code.","Rebuild the class and reload the server so the corrected bean is used."],"exampleFix":"// before\n@Code(language=ScriptLanguage.SHELL)\n@Editable\npublic Map<String, String> getScripts() { ... }\n// after\n@Code(language=ScriptLanguage.SHELL)\n@Editable\npublic List<String> getScripts() { ... }","handlingStrategy":"validation","validationCode":"// before applying @Code semantics, check the property type\nPropertyDescriptor pd = beanDescriptor.getProperty(\"scripts\");\nClass<?> type = pd.getPropertyClass();\nboolean ok = type == String.class || type.equals.genericTypeIsListOf(String.class); // String or List<String>\nif (!ok) throw new IllegalStateException(\"@Code target must be String or List<String>\");","typeGuard":"boolean isCodeCompatible(PropertyDescriptor pd) {\n    Class<?> t = pd.getPropertyClass();\n    if (t == String.class) return true;\n    if (List.class.isAssignableFrom(t)) {\n        java.lang.reflect.Type g = pd.getPropertyGetter().getGenericType();\n        return g instanceof ParameterizedType\n            && ((ParameterizedType) g).getActualTypeArguments().length == 1\n            && ((ParameterizedType) g).getActualTypeArguments()[0] == String.class;\n    }\n    return false;\n}","tryCatchPattern":"try {\n    EditContext ctx = codeEditSupport.getEditContext(descriptor);\n} catch (ExplicitException e) {\n    log.error(\"@Code misapplied on {}: {}\", descriptor.getPropertyName(), e.getMessage());\n    // fall back to a plain text editor or fail the bean registration\n}","preventionTips":["Apply @Code only to String or List<String> typed properties; verify the getter's return type when adding the annotation.","For collections, declare them explicitly as List<String>, not raw List or List<Object>.","Add a test that builds the bean descriptor for all custom annotated classes to surface type violations at build time."],"tags":["annotation","editable","type-mismatch","onedev"],"backgroundTag":"invalid-argument-value","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"}