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

  1. Change the property type to String (or List<String>) so it matches what @Code supports.
  2. Remove the @Code annotation if the property should not be a code editor.
  3. For structured data, use a different property type/edit mechanism instead of @Code.
  4. 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

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


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/463eebeef2c86c1c. Report an issue: GitHub.