theonedev/onedev · error · RuntimeException

Cannot find setter (class: %s, property: %s, type: %s)

Error message

Cannot find setter (class: %s, property: %s, type: %s)

What it means

BeanUtils.getSetter finds the setter Method corresponding to a given getter via JavaBeans conventions (setXxx with a single parameter matching the getter return type). It throws this RuntimeException when findSetter returns null, i.e. no matching setter exists on the declaring class.

Source

Thrown at server-core/src/main/java/io/onedev/server/util/BeanUtils.java:265

		}
	}
	
	/**
	 * Find corresponding setter method by getter in specified class and super classes.
	 * <p>
	 * @param getter
	 * 			getter method to search setter for
	 * @return
	 * 			setter method
	 * @throws
	 * 			RuntimeException if not found in class hierarchy
	 */
	public static Method getSetter(Method getter) {
		Method setter = findSetter(getter);
		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

  1. Add a public setter matching JavaBeans conventions: public void setPropertyName(<getterReturnType> value).
  2. If using Lombok, add @Setter (or @Data) to the class or the field.
  3. Verify the setter parameter type exactly matches the getter's return type; autoboxing/generics mismatches are not resolved by this lookup.
  4. If the property is intentionally read-only, use findSetter(...) and handle null, or avoid reflective write of that property instead of calling getSetter.

Example fix

// before (read-only bean, throws)
class Config { public String getName() { return name; } }
// after
class Config {
  private String name;
  public String getName() { return name; }
  public void setName(String name) { this.name = name; }
}
Defensive patterns

Strategy: validation

Validate before calling

Method setter = BeanUtils.findSetter(getter);
if (setter == null) {
    // skip read-only property or fail fast with your own message
    return;
}

Prevention

When it happens

Trigger: Calling BeanUtils.getSetter(getter) where the class has a readable property (getXxx/isXxx) but no public setXxx(Method type) accepting the getter's return type, or the setter has a different/incompatible parameter type, or the property is read-only.

Common situations: Reflection-based bean copying/serialization utilities over classes with computed or read-only properties (e.g. getters without setters), Lombok @Getter without @Setter, immutable value objects, or a setter whose parameter type differs from the getter return type (covariant getter overriding).

Related errors


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