Skip to content

Commit

Permalink
ArC - fix disposer method resolution
Browse files Browse the repository at this point in the history
- disposed parameter with wildcard does not match correctly
  • Loading branch information
mkouba committed Mar 24, 2021
1 parent d4828e6 commit e295cb1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ private DisposerInfo findDisposer(BeanInfo declaringBean, AnnotationTarget annot
hasQualifier = false;
}
}
if (hasQualifier && beanResolver.matches(beanType, disposer.getDisposedParameterType())) {
if (hasQualifier && beanResolver.matches(disposer.getDisposedParameterType(), beanType)) {
found.add(disposer);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.quarkus.arc.test.producer.disposer;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.enterprise.util.TypeLiteral;
import javax.inject.Singleton;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.arc.InstanceHandle;
import io.quarkus.arc.test.ArcTestContainer;

public class DisposerWithWildcardTest {

@RegisterExtension
ArcTestContainer container = new ArcTestContainer(Producers.class);

@Test
public void testDisposers() {
ArcContainer container = Arc.container();
InstanceHandle<Map<String, Long>> instanceA = container.instance(new TypeLiteral<Map<String, Long>>() {
});
assertTrue(instanceA.get().containsKey("A"));
instanceA.destroy();

InstanceHandle<Map<String, Integer>> instanceB = container.instance(new TypeLiteral<Map<String, Integer>>() {
});
assertTrue(instanceB.get().containsKey("B"));
instanceB.destroy();

assertEquals(2, Producers.KEYS.size());
}

@Singleton
static class Producers {

static final List<Object> KEYS = new CopyOnWriteArrayList<>();

@Singleton
@Produces
Map<String, Long> produceA() {
return Collections.singletonMap("A", 1l);
}

@Singleton
@Produces
Map<String, Integer> produceB() {
return Collections.singletonMap("B", 1);
}

void dispose(@Disposes Map<?, ?> myMap) {
KEYS.addAll(myMap.keySet());
}

}

}

0 comments on commit e295cb1

Please sign in to comment.