chinabugotech/hutool · error · IllegalArgumentException
No method for alias: [{}]
Error message
No method for alias: [{}] What it means
An annotation attribute declared an @Alias("name") whose target name does not exist among the annotation's member methods. AnnotationProxy.invoke looks up the alias name in the attributes map and, finding no matching method, rejects the configuration at proxy construction time. This surfaces during annotation synthesis/resolution, typically when the annotated type is first introspected.
Source
Thrown at hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationProxy.java:54
this.attributes = initAttributes();
}
@Override
public Class<? extends Annotation> annotationType() {
return type;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// 注解别名
Alias alias = method.getAnnotation(Alias.class);
if(null != alias){
final String name = alias.value();
if(StrUtil.isNotBlank(name)){
if(false == attributes.containsKey(name)){
throw new IllegalArgumentException(StrUtil.format("No method for alias: [{}]", name));
}
return attributes.get(name);
}
}
final Object value = attributes.get(method.getName());
if (value != null) {
return value;
}
return method.invoke(this, args);
}
/**
* 初始化注解的属性<br>
* 此方法预先调用所有注解的方法,将注解方法值缓存于attributes中
*
* @return 属性(方法结果)映射
*/View on GitHub (pinned to 8870454b2a)
Solutions
- Verify the @Alias value exactly matches an existing member method name on the same annotation (case-sensitive).
- Re-run after renaming the alias target back or updating the @Alias string.
- Search the codebase for the referenced name to confirm it still exists.
Example fix
// before
public @interface Config {
String path();
@Alias("location") String path2(); // location does not exist
}
// after
public @interface Config {
String location();
@Alias("location") String path();
} Defensive patterns
Strategy: validation
Validate before calling
Set<String> members = Stream.of(ann.annotationType().getDeclaredMethods())
.map(Method::getName).collect(Collectors.toSet());
for (Method m : ann.annotationType().getDeclaredMethods()) {
Alias a = m.getAnnotation(Alias.class);
if (a != null && !members.contains(a.value())) throw new IllegalStateException("bad alias target: " + a.value());
} Prevention
- Keep @Alias targets and member names in sync during refactors.
- Add a unit test that synthesizes each custom annotation to catch alias errors at build time.
When it happens
Trigger: Writing @Alias("foo") on a member whose sibling member is actually named bar (typo or rename). Using @Alias to cross-reference an attribute that was removed/renamed between library versions. Combining @Alias with an inherited meta-annotation whose target attribute is not present on the concrete annotation.
Common situations: Refactoring annotation members without updating @Alias targets; copy-pasting an @Alias value; version mismatch where a dependency annotation changed member names.
Related errors
- attribute [{}] cannot mirror for [{}], because it's already
- attribute [{}] cannot mirror for [{}], because [{}] already
- Failed to create AIConfig instance
- No constructor provided
- No constructor provided
AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14).
Data as JSON: /api/errors/169a26a4c351ff00.
Report an issue: GitHub.