alibaba/spring-ai-alibaba · error · UnsupportedOperationException
Unknown observation method:
Error message
Unknown observation method:
What it means
ChatOptionsProxy is a dynamic proxy that intercepts a known set of observation-related methods (e.g. toggling observationEnabled). Any method invocation on the proxy that is not in its handled list for observation methods falls through to a default case which throws UnsupportedOperationException('Unknown observation method: ' + name).
Solutions
- Read the method name in the exception message and add a corresponding case to handleObservationMethod's switch in ChatOptionsProxy.
- Upgrade/patch spring-ai-alibaba-starter-config-nacos to a version whose proxy covers the current interface.
- Avoid invoking unsupported methods on the proxied options; unwrap to the underlying ChatOptions for those calls.
Example fix
// before case "isObservationEnabled": ... return null; default: throw new UnsupportedOperationException(...); // after case "isObservationEnabled": ... return null; case "newObservationMethod": return handleNewMethod(args); // added case default: throw new UnsupportedOperationException(...);
Defensive patterns
Strategy: try-catch
Try / catch
try { return proxied.someObservationMethod(); }
catch (UnsupportedOperationException e) {
if (e.getMessage().startsWith("Unknown observation method")) { return invokeOnUnwrapped(originalOptions); }
throw e;
} Prevention
- After Spring AI upgrades, re-check the proxy switch covers all interface methods
- Call only documented observation methods on the proxy
- Add a catch-all default that delegates to the underlying options instead of throwing, if extending the proxy
When it happens
Trigger: Code calls an observation-interface method on the ChatOptionsProxy that handleObservationMethod's switch does not cover — e.g. a newly added method in an upgraded observation interface, or a typo'd/direct call to an unhandled getter/setter routed to the observation handler.
Common situations: Spring AI upgrade adds a new method to the observed interface and the proxy switch was not updated; passing the proxy to framework code that invokes methods the proxy author didn't anticipate; calling proxy methods directly in tests.
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
- Unknown Object method:
- A2aRemoteAgent has not support schedule.
- cancel is not implemented yet!
- ChatClient error
- ChatClient is required
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/59f36d05ff62bf93.
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:178
return observationName;
case "setObservationName":
if (args != null && args.length > 0) {
observationName = (String) args[0];
}
return null;
case "isObservationEnabled":
return observationEnabled;
case "setObservationEnabled":
if (args != null && args.length > 0) {
observationEnabled = (Boolean) args[0];
}
return null;
default:
throw new UnsupportedOperationException("Unknown observation method: " + methodName);
}
}
/**
* 处理Object类的方法
*/
private Object handleObjectMethod(String methodName, Object[] args, Object obj) {
switch (methodName) {
case "toString":
return "CglibProxy{" +
"chatOptions=" + chatOptions +
", observationMetadata=" + observationMetadata +
", observationName='" + observationName + '\'' +
", observationEnabled=" + observationEnabled +
'}';
case "equals":
if (args != null && args.length > 0) {View on GitHub (pinned to f82da0b50f)