gnodet-bot commented on code in PR #26488:
URL: https://github.com/apache/camel/pull/26488#discussion_r4023266311


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/EndpointChecks.java:
##########
@@ -191,6 +200,36 @@ public static List<String> validateYamlEndpoints(String 
content, CamelCatalog ca
         return errors;
     }
 
+    private static volatile CamelCatalog defaultCatalog;
+
+    /**
+     * The message for a component the catalog of a runtime (Camel Quarkus, 
Camel Spring Boot) does not have while Camel
+     * has it: the runtime has no extension or starter for it. Null for the 
default catalog, whose unknown components
+     * are not reported: a project can register a component of its own 
(CAMEL-24711).
+     */
+    static String missingInRuntime(CamelCatalog catalog, String scheme) {
+        RuntimeProvider provider = catalog.getRuntimeProvider();
+        String name = provider != null ? provider.getProviderName() : null;
+        if (name == null || "default".equals(name)) {
+            return null;
+        }
+        CamelCatalog plain = defaultCatalog;
+        if (plain == null) {
+            plain = new DefaultCamelCatalog();
+            defaultCatalog = plain;
+        }
+        if (plain.componentModel(scheme) == null) {
+            return null;

Review Comment:
   ⚠️ **Concurrency: check-then-act without synchronization.**
   
   `defaultCatalog` is `volatile`, so the read on line 219 is safe — but two 
threads that both observe `null` will both construct a `DefaultCamelCatalog` 
and one's instance will be silently overwritten. `DefaultCamelCatalog` 
construction loads the full catalog from the classpath; this is not cheap. The 
MCP server runs in a multi-threaded context, so `missingInRuntime` can be 
entered concurrently.
   
   The same PR uses proper DCL for `VERSION_VALIDATORS` in 
`SourceValidator.yamlValidator(CamelCatalog)`. Apply the same pattern here:
   
   ```suggestion
           CamelCatalog plain = defaultCatalog;
           if (plain == null) {
               synchronized (EndpointChecks.class) {
                   plain = defaultCatalog;
                   if (plain == null) {
                       defaultCatalog = plain = new DefaultCamelCatalog();
                   }
               }
           }
   ```



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