Repository: quarkusio/quarkus
Issue: Qute collection access requires restart of quarkus:dev

**Describe the bug**
When coding Qute templates in `quarkus:dev`, the first time we access a `list.get(index)` fails with a `java.lang.ClassNotFoundException: io.quarkus.qute.runtime.extensions.CollectionTemplateExtensions_Extension_ValueResolver_get_646e8480881185b6bc78b6698eeafb5d7b01c85c$$function$$2`

Once we restart `quarkus:dev` and then the resolver is "known" once, it works as expected (even we remove the access and add it again).

**Reproducer**

1. Start `quarkus:dev` with an empty template
2. Add a template that accesses a list, similar to this:
	```
	{#if ! entries.isEmpty}
		First title: {entries.get(0).title}
	{/}
	```
3. It fails with:
	```
	java.lang.NoClassDefFoundError: io.quarkus.qute.runtime.extensions.CollectionTemplateExtensions_Extension_ValueResolver_get_646e8480881185b6bc78b6698eeafb5d7b01c85c$$function$$2
		at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
		at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1190)
		at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2299)
		at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:143)
		at io.quarkus.qute.EvaluatorImpl.resolveReference(EvaluatorImpl.java:76)
		at io.quarkus.qute.EvaluatorImpl.evaluate(EvaluatorImpl.java:48)
		at io.quarkus.qute.ResolutionContextImpl.evaluate(ResolutionContextImpl.java:31)
		at io.quarkus.qute.ExpressionNode.resolve(ExpressionNode.java:25)
		at io.quarkus.qute.SectionNode$SectionResolutionContextImpl.execute(SectionNode.java:126)
		at io.quarkus.qute.IfSectionHelper.lambda$resolveCondition$0(IfSectionHelper.java:55)
		at io.quarkus.qute.IfSectionHelper$$Lambda$844/0000000000000000.apply(Unknown Source)
		at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1183)
		at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2299)
		at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:143)
		at io.quarkus.qute.IfSectionHelper.resolveCondition(IfSectionHelper.java:53)
		at io.quarkus.qute.IfSectionHelper.resolve(IfSectionHelper.java:43)
		at io.quarkus.qute.SectionNode.resolve(SectionNode.java:34)
		at io.quarkus.qute.SectionNode$SectionResolutionContextImpl.execute(SectionNode.java:126)
		at io.quarkus.qute.SectionHelper$SectionResolutionContext.execute(SectionHelper.java:33)
		at io.quarkus.qute.Parser$1$1.resolve(Parser.java:80)
		at io.quarkus.qute.SectionNode.resolve(SectionNode.java:34)
		at io.quarkus.qute.TemplateImpl.renderData(TemplateImpl.java:99)
		at io.quarkus.qute.TemplateImpl.access$200(TemplateImpl.java:14)
		at io.quarkus.qute.TemplateImpl$TemplateInstanceImpl.renderAsync(TemplateImpl.java:80)
		at io.quarkus.resteasy.qute.runtime.TemplateResponseFilter.filter(TemplateResponseFilter.java:58)
		at org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl.filter(ContainerResponseContextImpl.java:360)
		at org.jboss.resteasy.core.ServerResponseWriter.executeFilters(ServerResponseWriter.java:251)
		at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:101)
		at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:74)
		at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:590)
		... 58 more
	Caused by: java.lang.NoClassDefFoundError: io.quarkus.qute.runtime.extensions.CollectionTemplateExtensions_Extension_ValueResolver_get_646e8480881185b6bc78b6698eeafb5d7b01c85c$$function$$2
		at io.quarkus.qute.runtime.extensions.CollectionTemplateExtensions_Extension_ValueResolver_get_646e8480881185b6bc78b6698eeafb5d7b01c85c.resolve(CollectionTemplateExtensions_Extension_ValueResolver_get_646e8480881185b6bc78b6698eeafb5d7b01c85c.zig:70)
		at io.quarkus.qute.EvaluatorImpl.resolve(EvaluatorImpl.java:100)
		at io.quarkus.qute.EvaluatorImpl.resolve(EvaluatorImpl.java:109)
		at io.quarkus.qute.EvaluatorImpl.resolve(EvaluatorImpl.java:109)
		at io.quarkus.qute.EvaluatorImpl.resolve(EvaluatorImpl.java:109)
		at io.quarkus.qute.EvaluatorImpl.resolve(EvaluatorImpl.java:109)
		at io.quarkus.qute.EvaluatorImpl.resolve(EvaluatorImpl.java:109)
		at io.quarkus.qute.EvaluatorImpl.resolve(EvaluatorImpl.java:109)
		at io.quarkus.qute.EvaluatorImpl.resolveReference(EvaluatorImpl.java:75)
		at io.quarkus.qute.EvaluatorImpl.lambda$resolveReference$1(EvaluatorImpl.java:78)
		at io.quarkus.qute.EvaluatorImpl$$Lambda$904/0000000000000000.apply(Unknown Source)
		at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1183)
		... 86 more
	Caused by: java.lang.ClassNotFoundException: io.quarkus.qute.runtime.extensions.CollectionTemplateExtensions_Extension_ValueResolver_get_646e8480881185b6bc78b6698eeafb5d7b01c85c$$function$$2
		at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:788)
		at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
		at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:1081)
		at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:318)
		at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:274)
		... 98 more
	```
4. If we stop and restart `quarkus:dev`, it works.

Btw, in the same case (empty template when starting then adding the code only once `quarkus:dev` is running) `list[index]` doesn't fail with an error but silently returns no element:

```
{#if ! entries.isEmpty}
    Entries has {entries.size} elements
    First title: {entries[0].title}
{/}
```

```
<!-- output -->
Entries has 3 elements
First title: NOT_FOUND
```

Tested with Quarkus version `1.3.1.Final`.


Changed files:
independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/MemoryClassPathElement.java

diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/MemoryClassPathElement.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/MemoryClassPathElement.java
index 84a9856e7f4..b6769276f91 100644
--- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/MemoryClassPathElement.java
+++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/MemoryClassPathElement.java
@@ -10,6 +10,7 @@
 import java.security.CodeSource;
 import java.security.ProtectionDomain;
 import java.security.cert.Certificate;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -22,7 +23,21 @@ public MemoryClassPathElement(Map<String, byte[]> resources) {
     }
 
     public void reset(Map<String, byte[]> resources) {
-        this.resources = resources;
+        Map<String, byte[]> newResources = new HashMap<>(resources);
+        //we can't delete .class files from the loader
+        //gizmo may not generate the same function names on restart
+        //so if we delete them already loaded classes may have problems, as functions they reference
+        //may have been removed
+        //see https://github.com/quarkusio/quarkus/issues/8301
+        for (Map.Entry<String, byte[]> e : this.resources.entrySet()) {
+            if (newResources.containsKey(e.getKey())) {
+                continue;
+            }
+            if (e.getKey().endsWith(".class")) {
+                newResources.put(e.getKey(), e.getValue());
+            }
+        }
+        this.resources = newResources;
     }
 
     @Override