Skip to content

Commit cda9ac0

Browse files
sunyuhan1998Willam2004
authored andcommitted
Only log class name on ToolCallingAutoConfiguration#ClassNotFoundException in getClassOrNull
Fixes spring-projects#4205 Fixes spring-projects#4249 Auto-cherry-pick to 1.0.x 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]> Signed-off-by: 家娃 <[email protected]>
1 parent 58643ee commit cda9ac0

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
@@ -126,10 +126,19 @@ ToolCallingContentObservationFilter toolCallingContentObservationFilter() {
126126

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

0 commit comments

Comments
 (0)