This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 496a6b0f26d6 CAMEL-24060: Use reflection for optional 
PQCMicrometerMetrics to avoid GraalVM native image failure
496a6b0f26d6 is described below

commit 496a6b0f26d669e312d70a749481d74120ee34d1
Author: JiriOndrusek <[email protected]>
AuthorDate: Tue Jul 14 18:10:19 2026 +0200

    CAMEL-24060: Use reflection for optional PQCMicrometerMetrics to avoid 
GraalVM native image failure
    
    PQCProducer.createMetrics() directly referenced PQCMicrometerMetrics,
    causing GraalVM native image compilation to fail with NoClassDefFoundError
    when micrometer is not on the classpath. Replace the direct class reference
    with reflection via CamelContext.getClassResolver() so GraalVM's static
    analysis never follows the link to micrometer classes.
    
    Closes #24683
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 .../main/java/org/apache/camel/component/pqc/PQCProducer.java | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git 
a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCProducer.java
 
b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCProducer.java
index 6a6006f242fc..8e4ef4592e80 100644
--- 
a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCProducer.java
+++ 
b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCProducer.java
@@ -42,7 +42,6 @@ import 
org.apache.camel.component.pqc.crypto.hybrid.HybridSignature;
 import org.apache.camel.component.pqc.lifecycle.KeyLifecycleManager;
 import org.apache.camel.component.pqc.lifecycle.KeyMetadata;
 import org.apache.camel.component.pqc.metrics.PQCMetrics;
-import org.apache.camel.component.pqc.metrics.PQCMicrometerMetrics;
 import org.apache.camel.component.pqc.stateful.StatefulKeyState;
 import org.apache.camel.health.HealthCheck;
 import org.apache.camel.health.HealthCheckHelper;
@@ -242,12 +241,18 @@ public class PQCProducer extends DefaultProducer {
 
     private PQCMetrics createMetrics() {
         CamelContext camelContext = getEndpoint().getCamelContext();
-        // Only touch Micrometer if it is actually on the classpath, keeping 
it an optional dependency
+        // Only touch Micrometer if it is actually on the classpath, keeping 
it an optional dependency.
+        // Use reflection to avoid a static class reference that GraalVM 
native image would follow.
         if 
(camelContext.getClassResolver().resolveClass("io.micrometer.core.instrument.MeterRegistry")
 == null) {
             return PQCMetrics.NOOP;
         }
         try {
-            return PQCMicrometerMetrics.create(camelContext);
+            Class<?> clazz = camelContext.getClassResolver()
+                    
.resolveClass("org.apache.camel.component.pqc.metrics.PQCMicrometerMetrics");
+            if (clazz == null) {
+                return PQCMetrics.NOOP;
+            }
+            return (PQCMetrics) clazz.getMethod("create", 
CamelContext.class).invoke(null, camelContext);
         } catch (Throwable t) {
             LOG.debug("Micrometer metrics are not available for the PQC 
producer: {}", t.getMessage());
             return PQCMetrics.NOOP;

Reply via email to