Skip to content

Commit 64ec337

Browse files
sunyuhan1998spring-builds
authored andcommitted
Only log class name on ToolCallingAutoConfiguration#ClassNotFoundException in getClassOrNull
Fixes #4205 Fixes #4249 The getClassOrNull method is designed to gracefully handle missing classes by returning null, but was logging full stack traces for ClassNotFoundException which could mislead users into thinking there's an actual problem. Changes: - Log only the class name when ClassNotFoundException occurs - Add type safety check for RuntimeException subclasses - Add separate handling for other exceptions with full stack trace - Improve log message clarity to reduce user confusion This maintains the expected behavior while providing cleaner, less alarming log output for normal class-not-found scenarios. Signed-off-by: Sun Yuhan <[email protected]> (cherry picked from commit befaf87)
1 parent 6f61562 commit 64ec337

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

auto-configurations/models/tool/spring-ai-autoconfigure-model-tool/src/main/java/org/springframework/ai/model/tool/autoconfigure/ToolCallingAutoConfiguration.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,19 @@ ToolCallingContentObservationFilter toolCallingContentObservationFilter() {
125125

126126
private static Class<? extends RuntimeException> getClassOrNull(String className) {
127127
try {
128-
return (Class<? extends RuntimeException>) ClassUtils.forName(className, null);
128+
Class<?> clazz = ClassUtils.forName(className, null);
129+
if (RuntimeException.class.isAssignableFrom(clazz)) {
130+
return (Class<? extends RuntimeException>) clazz;
131+
}
132+
else {
133+
logger.debug("Class {} is not a subclass of RuntimeException", className);
134+
}
129135
}
130136
catch (ClassNotFoundException e) {
131-
logger.debug("Cannot load class", e);
137+
logger.debug("Cannot load class: {}", className);
138+
}
139+
catch (Exception e) {
140+
logger.debug("Error loading class: {}", className, e);
132141
}
133142
return null;
134143
}

0 commit comments

Comments
 (0)