oscerd opened a new pull request, #2892:
URL: https://github.com/apache/camel-kamelets/pull/2892

   ## Summary
   
   Defense-in-depth for the `KameletsCatalog` lookup API. `getKameletsByType`, 
`getKameletsByNamespace`, `getKameletsByGroups` and `getKameletByProvider` 
dereferenced `getMetadata().getLabels()` / `getAnnotations().get(key)` directly 
inside their stream filters, so a single Kamelet missing the queried 
label/annotation would throw an NPE and break the **entire** lookup call.
   
   This guards the access through two small helpers (`labelValue` / 
`annotationValue`) that return `null` when the metadata/labels/annotations or 
the key are absent.
   
   - **No behaviour change for the shipped catalog** — the validator guarantees 
every Kamelet has the relevant labels/annotations, so these branches are not 
reachable today; this hardens the public API against edge-case input.
   - The matching semantics (`contains` / `equalsIgnoreCase`) and the 
mutable-list return type are preserved.
   - Also removes the dead `if (!collect.isEmpty()) … else emptyList()` in 
`getKameletByProvider` (it already returns an empty list on no match).
   - Adds a test pinning the "non-null, empty-on-no-match, never NPE" contract.
   
   ## Deliberately not changed
   - `getKameletsByName` uses substring (`contains`) matching — left as-is, as 
it is plausibly an intentional "search" method (returns a `List`).
   - `initCatalog()` logs and skips a Kamelet that fails to parse — left as-is 
(graceful degradation; the `testAllKameletFilesLoaded` test guards against 
missing resources in CI).
   
   ## Verification
   - `mvn -pl library/camel-kamelets-catalog -am install`: **passes** (module 
compiles, all catalog tests green incl. the new one).
   
   ---
   _AI-generated by Claude Code on behalf of Andrea Cosentino (@oscerd)._
   


-- 
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]

Reply via email to