Repository: quarkusio/quarkus
Issue: NettyProcessor marks http2 related classes for runtime initialization even if they are not on the classpath

**Describe the bug**
The NettyProcessor performs some checks to determine what classes should be initialized at runtime :

https://github.com/quarkusio/quarkus/blob/0ecb901c14242e2d31ab44e2480f66931671d84c/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java#L82-L95

but this code is flawed as http and http2 classes are provided by different artefacts so in case the http2 codec is non on the classpath, the native image build would fail with something like:

```
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Running Quarkus native-image plugin on GraalVM Version 19.3.1 CE
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] /opt/data/sfw/lang/java/8-graal/bin/native-image -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -H:+JNI -jar camel-k-runtime-example-quarkus-yaml-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http -H:NativeLinkerOption=-no-pie --no-server -H:-UseServiceLoaderFeature -H:+StackTrace camel-k-runtime-example-quarkus-yaml-runner
[camel-k-runtime-example-quarkus-yaml-runner:67685]    classlist:   6,783.16 ms
16:29:35,484 INFO  [org.apa.cam.sup.LRUCacheFactory] Detected and using LURCacheFactory: camel-caffeine-lrucache
[camel-k-runtime-example-quarkus-yaml-runner:67685]        (cap):     801.63 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]        setup:   2,291.49 ms
java.lang.ClassNotFoundException: io.netty.handler.codec.http2.Http2ClientUpgradeCodec
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at io.quarkus.runner.AutoFeature.beforeAnalysis(AutoFeature.zig:12746)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$7(NativeImageGenerator.java:669)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:669)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:530)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
java.lang.ClassNotFoundException: io.netty.handler.codec.http2.DefaultHttp2FrameWriter
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at io.quarkus.runner.AutoFeature.beforeAnalysis(AutoFeature.zig:12861)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$7(NativeImageGenerator.java:669)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:669)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:530)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
java.lang.ClassNotFoundException: io.netty.handler.codec.http2.Http2ConnectionHandler
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at io.quarkus.runner.AutoFeature.beforeAnalysis(AutoFeature.zig:12976)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$7(NativeImageGenerator.java:669)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:669)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:530)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
java.lang.ClassNotFoundException: io.netty.handler.codec.http2.Http2CodecUtil
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at io.quarkus.runner.AutoFeature.beforeAnalysis(AutoFeature.zig:13206)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$7(NativeImageGenerator.java:669)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:669)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:530)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
java.lang.NullPointerException
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.initializeAtRunTime(ConfigurableClassInitialization.java:249)
	at org.graalvm.nativeimage.hosted.RuntimeClassInitialization.initializeAtRunTime(RuntimeClassInitialization.java:99)
	at io.quarkus.runner.AutoFeature.beforeAnalysis(AutoFeature.zig:13249)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$7(NativeImageGenerator.java:669)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:669)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:530)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
16:29:39,632 INFO  [org.jbo.threads] JBoss Threads version 3.0.1.Final
[camel-k-runtime-example-quarkus-yaml-runner:67685]   (typeflow):  16,398.23 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]    (objects):  10,305.35 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]   (features):     469.17 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]     analysis:  28,557.61 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]     (clinit):     753.17 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]     universe:   2,014.83 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]      (parse):   2,746.83 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]     (inline):   3,935.75 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]    (compile):  25,660.12 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]      compile:  33,949.94 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]        image:   2,269.54 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]        write:     417.88 ms
[camel-k-runtime-example-quarkus-yaml-runner:67685]      [total]:  76,643.82 ms
```

**Expected behavior**
The NettyProcessor should register only classes that are available on the classpath.

**Actual behavior**
The NettyProcessor marks http2 related classes for runtime initialization even if they are not on the classpath

**Additional context**
I'll provide a PR


Changed files:
extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java

diff --git a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java
index 700741feba8..c1914208df5 100644
--- a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java
+++ b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java
@@ -83,10 +83,6 @@ NativeImageConfigBuildItem build() {
             Class.forName("io.netty.handler.codec.http.HttpObjectEncoder");
             builder
                     .addRuntimeInitializedClass("io.netty.handler.codec.http.HttpObjectEncoder")
-                    .addRuntimeInitializedClass("io.netty.handler.codec.http2.Http2CodecUtil")
-                    .addRuntimeInitializedClass("io.netty.handler.codec.http2.Http2ClientUpgradeCodec")
-                    .addRuntimeInitializedClass("io.netty.handler.codec.http2.DefaultHttp2FrameWriter")
-                    .addRuntimeInitializedClass("io.netty.handler.codec.http2.Http2ConnectionHandler")
                     .addRuntimeInitializedClass("io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder")
                     .addRuntimeInitializedClass("io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder");
         } catch (ClassNotFoundException e) {
@@ -94,6 +90,18 @@ NativeImageConfigBuildItem build() {
             log.debug("Not registering Netty HTTP classes as they were not found");
         }
 
+        try {
+            Class.forName("io.netty.handler.codec.http2.Http2CodecUtil");
+            builder
+                    .addRuntimeInitializedClass("io.netty.handler.codec.http2.Http2CodecUtil")
+                    .addRuntimeInitializedClass("io.netty.handler.codec.http2.Http2ClientUpgradeCodec")
+                    .addRuntimeInitializedClass("io.netty.handler.codec.http2.DefaultHttp2FrameWriter")
+                    .addRuntimeInitializedClass("io.netty.handler.codec.http2.Http2ConnectionHandler");
+        } catch (ClassNotFoundException e) {
+            //ignore
+            log.debug("Not registering Netty HTTP2 classes as they were not found");
+        }
+
         try {
             Class.forName("io.netty.channel.unix.UnixChannel");
             builder.addRuntimeInitializedClass("io.netty.channel.unix.Errors")