theonedev/onedev · error · ExplicitException
@Code annotation should be applied to a String or List<Strin
Error message
@Code annotation should be applied to a String or List<String> property
What it means
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.
Source
Thrown at server-core/src/main/java/io/onedev/server/web/editable/code/CodeEditSupport.java:63
protected AnnotatedElement getElement() {
return propertyDescriptor.getPropertyGetter();
}
};
}
}
};
}
@Override
public PropertyEditor<Serializable> renderForEdit(String componentId, IModel<Serializable> model) {
return new CodePropertyEditor(componentId, descriptor, model);
}
};
} else {
throw new ExplicitException("@Code annotation should be applied to a String or List<String> property");
}
} else {
return null;
}
}
@Override
public int getPriority() {
return DEFAULT_PRIORITY;
}
}
View on GitHub (pinned to d44925c47c)
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.
Example fix
// before
@Code(language=ScriptLanguage.SHELL)
@Editable
public Map<String, String> getScripts() { ... }
// after
@Code(language=ScriptLanguage.SHELL)
@Editable
public List<String> getScripts() { ... } Defensive patterns
Strategy: validation
Validate before calling
// before applying @Code semantics, check the property type
PropertyDescriptor pd = beanDescriptor.getProperty("scripts");
Class<?> type = pd.getPropertyClass();
boolean ok = type == String.class || type.equals.genericTypeIsListOf(String.class); // String or List<String>
if (!ok) throw new IllegalStateException("@Code target must be String or List<String>"); Type guard
boolean isCodeCompatible(PropertyDescriptor pd) {
Class<?> t = pd.getPropertyClass();
if (t == String.class) return true;
if (List.class.isAssignableFrom(t)) {
java.lang.reflect.Type g = pd.getPropertyGetter().getGenericType();
return g instanceof ParameterizedType
&& ((ParameterizedType) g).getActualTypeArguments().length == 1
&& ((ParameterizedType) g).getActualTypeArguments()[0] == String.class;
}
return false;
} Try / catch
try {
EditContext ctx = codeEditSupport.getEditContext(descriptor);
} catch (ExplicitException e) {
log.error("@Code misapplied on {}: {}", descriptor.getPropertyName(), e.getMessage());
// fall back to a plain text editor or fail the bean registration
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Dependency property not found: ${property}
- Issue schedule permission required to set iterations
- Iteration '${iterationName}' not found
- No permission to update issue fields
- State is required
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/463eebeef2c86c1c.
Report an issue: GitHub.