Summary
Fix three non-idiomatic patterns identified by comparison with cds-services conventions.
Changes
1. ActionHandler: Replace raw context.put("result") with context.setResult()
File: cds-feature-ai-core/.../handler/ActionHandler.java:36-37
// Before
context.put("result", result);
context.setCompleted();
// After
context.setResult(result); // setResult() calls setCompleted() automatically
In cds-services, setResult() implicitly calls setCompleted(). The explicit context.put("result", ...) + setCompleted() pattern bypasses this and is non-standard.
2. AICoreSetupHandler: Replace string concatenation with {} placeholders
File: cds-feature-ai-core/.../AICoreSetupHandler.java (3 locations)
// Before (line 44)
throw new ServiceException(ErrorStatuses.SERVER_ERROR,
"Failed to create AI Core resources for tenant: " + tenantId, e);
// After
throw new ServiceException(ErrorStatuses.SERVER_ERROR,
"Failed to create AI Core resources for tenant: {}", tenantId, e);
Same for lines 82 and 106. ServiceException uses MessageFormatter.arrayFormat() internally and detects the last Throwable arg as the cause.
3. AbstractCrudHandler: Replace Collectors.toList() with .toList() and new ArrayList<>() with List.of()
File: cds-feature-ai-core/.../handler/AbstractCrudHandler.java:36-38
// Before
protected static <T, R> List<R> mapResources(List<T> resources, Function<T, R> mapper) {
if (resources == null) return new ArrayList<>();
return resources.stream().map(mapper).collect(Collectors.toList());
}
// After
protected static <T, R> List<R> mapResources(List<T> resources, Function<T, R> mapper) {
if (resources == null) return List.of();
return resources.stream().map(mapper).toList();
}
Remove unused imports: java.util.ArrayList, java.util.stream.Collectors.
Verification
- All existing tests should pass unchanged (return values flow into
context.setResult() which accepts any Iterable).
- The returned lists are never mutated by callers (verified: all go to
context.setResult()).
Rationale
Aligns with idiomatic patterns observed in cds-services:
setResult() is the standard way to complete ON handlers
- SLF4J-style placeholders enable localization and consistent formatting
.toList() is the Java 16+ standard; List.of() signals immutability intent
Summary
Fix three non-idiomatic patterns identified by comparison with
cds-servicesconventions.Changes
1. ActionHandler: Replace raw
context.put("result")withcontext.setResult()File:
cds-feature-ai-core/.../handler/ActionHandler.java:36-37In
cds-services,setResult()implicitly callssetCompleted(). The explicitcontext.put("result", ...)+setCompleted()pattern bypasses this and is non-standard.2. AICoreSetupHandler: Replace string concatenation with
{}placeholdersFile:
cds-feature-ai-core/.../AICoreSetupHandler.java(3 locations)Same for lines 82 and 106.
ServiceExceptionusesMessageFormatter.arrayFormat()internally and detects the lastThrowablearg as the cause.3. AbstractCrudHandler: Replace
Collectors.toList()with.toList()andnew ArrayList<>()withList.of()File:
cds-feature-ai-core/.../handler/AbstractCrudHandler.java:36-38Remove unused imports:
java.util.ArrayList,java.util.stream.Collectors.Verification
context.setResult()which accepts anyIterable).context.setResult()).Rationale
Aligns with idiomatic patterns observed in
cds-services:setResult()is the standard way to complete ON handlers.toList()is the Java 16+ standard;List.of()signals immutability intent