alibaba/spring-ai-alibaba · error · UnsupportedOperationException
Unknown Object method:
Error message
Unknown Object method:
What it means
The proxy's handleObjectMethod special-cases the core Object methods it supports (toString, equals, hashCode). Any other Object-level method invoked through the proxy — e.g. clone(), finalize(), notify() — reaches the default branch and throws UnsupportedOperationException('Unknown Object method: ' + name).
Solutions
- Do not call clone() or other unsupported Object methods on the proxy; clone/copy the underlying ChatOptions instance instead.
- If a specific Object method is needed, add a case for it in ChatOptionsProxy.handleObjectMethod.
- Unwrap the proxy to the real ChatOptions before passing it to utilities that expect full Object semantics.
Example fix
// before MyOptions copy = (MyOptions) proxiedOptions.clone(); // throws // after MyOptions copy = underlyingOptions.copy(); // use the real instance
Defensive patterns
Strategy: type-guard
Type guard
static ChatOptions unwrap(Object maybeProxy) {
return (maybeProxy instanceof ChatOptionsProxy.ProxyRef pr) ? pr.target() : (ChatOptions) maybeProxy;
}
// use unwrap() before clone()/other Object methods Try / catch
try { return proxied.equals(other); }
catch (UnsupportedOperationException e) {
if (e.getMessage().startsWith("Unknown Object method")) { return underlying.equals(other); }
throw e;
} Prevention
- Only rely on toString/equals/hashCode through the proxy
- Perform clone/copy on the original ChatOptions, not the proxy
- Keep a reference to the unproxied options instance alongside the proxy
When it happens
Trigger: Calling an Object method other than toString/equals/hashCode on a ChatOptionsProxy instance, e.g. options.clone(), or framework/util code calling getClass()-adjacent methods through the proxy interface.
Common situations: Deep-copy utilities or serialization frameworks that call clone() on the options; debuggers/collection code invoking unexpected Object methods; developer code assuming the proxy behaves like the original object for all methods.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- LoopAgent must have only one subAgent, please use…
- Unknown observation method:
- 数据集版本数据量为0或不存在
- A2aRemoteAgent has not support schedule.
- Agent not found:
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/a824fa9e3adaee14.
Report an issue: GitHub.
Appendix: source
Thrown at spring-boot-starters/spring-ai-alibaba-starter-config-nacos/src/main/java/com/alibaba/cloud/ai/agent/nacos/utils/ChatOptionsProxy.java:205
case "toString":
return "CglibProxy{" +
"chatOptions=" + chatOptions +
", observationMetadata=" + observationMetadata +
", observationName='" + observationName + '\'' +
", observationEnabled=" + observationEnabled +
'}';
case "equals":
if (args != null && args.length > 0) {
return obj == args[0];
}
return false;
case "hashCode":
return System.identityHashCode(obj);
default:
throw new UnsupportedOperationException("Unknown Object method: " + methodName);
}
}
}
}
View on GitHub (pinned to f82da0b50f)