gnodet-bot commented on code in PR #26639:
URL: https://github.com/apache/camel/pull/26639#discussion_r4058107865
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/PropertiesChecks.java:
##########
@@ -46,6 +47,52 @@ public static List<String> validateProperties(
return validatePropertiesLines(content, line ->
validatePropertyLine(line, catalog, extraPropertyLine));
}
+ /** camel.<group>.<rest>=: the option groups of the main model
(resilience4j, faulttolerance, threadpool...). */
+ static final Pattern GROUP_KEY_PATTERN =
Pattern.compile("^\\s*camel\\.([a-zA-Z0-9-]+)\\.([^=\\s]+)\\s*=");
+
+ /** The camel.* prefixes whose keys legitimately nest, or that other
checks own. */
+ private static final Set<String> NESTING_GROUPS = Set.of("component",
"dataformat", "language", "beans", "variable",
+ "kamelet", "jbang", "route-template", "routeTemplate", "main",
"rest", "server", "management");
+
+ /**
+ *
camel.resilience4j.circuitbreaker.supplierCircuitBreaker.slidingWindowSize=4,
an invented per-id form: the
+ * catalog accepts it and the run dies at startup ("Cannot find getter
method: supplierCircuitBreaker on bean: class
+ * java.lang.String"). The options of a group are global, one segment
after the group; resilience4j is also set per
+ * circuit breaker in the route (CAMEL-24856).
+ */
+ static String nestedGroupKeyHint(String line, CamelCatalog catalog) {
+ Matcher m = GROUP_KEY_PATTERN.matcher(line);
+ if (!m.find()) {
+ return null;
+ }
+ String group = m.group(1);
+ String rest = m.group(2);
+ if (!rest.contains(".") || rest.contains("[") ||
NESTING_GROUPS.contains(group)) {
+ return null;
+ }
+ String prefix = "camel." + group + ".";
+ List<String> options = new ArrayList<>();
+ for (var o : catalog.mainModel().getOptions()) {
Review Comment:
⚠️ **NPE risk — `catalog.mainModel()` is documented to return `null`.**
`CamelCatalog.mainModel()` has the Javadoc: `@return the requested main
model or {@code null} in case it is not available in this CamelCatalog`.
Calling `.getOptions()` on a null model throws NPE.
Unlike `mainOptionHint()`, which wraps its `catalog.mainModel()` calls
inside a `try/catch (Exception e)` block, `nestedGroupKeyHint()` has no such
guard — and it's invoked from `validatePropertyLine` *before* the `try` block.
A null catalog would crash the entire validation.
Fix: add a null guard before dereferencing:
```suggestion
MainModel mm = catalog.mainModel();
if (mm == null) {
return null;
}
List<String> options = new ArrayList<>();
for (var o : mm.getOptions()) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]