diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/BeanWithInstanceWithWildcardEvent.java b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/BeanWithInstanceWithWildcardEvent.java index eb4e664c2..18ea5a0d5 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/BeanWithInstanceWithWildcardEvent.java +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/BeanWithInstanceWithWildcardEvent.java @@ -23,5 +23,5 @@ public class BeanWithInstanceWithWildcardEvent { @Inject - Instance> veryWildInstance; + Instance> veryWildInstance; } diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/InstanceWithEventWithWildcardTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/InstanceWithEventWithWildcardTest.java index 8b03b9bc8..a4e6816de 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/InstanceWithEventWithWildcardTest.java +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/InstanceWithEventWithWildcardTest.java @@ -21,7 +21,6 @@ import org.jboss.cdi.tck.AbstractTest; import org.jboss.cdi.tck.cdi.Sections; import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; -import org.jboss.cdi.tck.tests.event.broken.wildcard.EventWithWildcardTest; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.test.audit.annotations.SpecAssertion; import org.jboss.test.audit.annotations.SpecVersion; @@ -33,7 +32,7 @@ public class InstanceWithEventWithWildcardTest extends AbstractTest { @ShouldThrowException(DefinitionException.class) @Deployment public static WebArchive createTestArchive() { - return new WebArchiveBuilder().withTestClass(EventWithWildcardTest.class) + return new WebArchiveBuilder().withTestClass(InstanceWithEventWithWildcardTest.class) .withClasses(BeanWithInstanceWithWildcardEvent.class).build(); } diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/InstanceWithWildcardTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/InstanceWithWildcardTest.java index 4e49161dc..952e0694f 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/InstanceWithWildcardTest.java +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/broken/wildcard/InstanceWithWildcardTest.java @@ -21,7 +21,6 @@ import org.jboss.cdi.tck.AbstractTest; import org.jboss.cdi.tck.cdi.Sections; import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; -import org.jboss.cdi.tck.tests.event.broken.wildcard.EventWithWildcardTest; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.test.audit.annotations.SpecAssertion; import org.jboss.test.audit.annotations.SpecVersion; @@ -33,7 +32,7 @@ public class InstanceWithWildcardTest extends AbstractTest { @ShouldThrowException(DefinitionException.class) @Deployment public static WebArchive createTestArchive() { - return new WebArchiveBuilder().withTestClass(EventWithWildcardTest.class) + return new WebArchiveBuilder().withTestClass(InstanceWithWildcardTest.class) .withClasses(BeanWithWildcardInstance.class).build(); } diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/BeanWithInstanceWithWildcardEvent.java b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/BeanWithInstanceWithWildcardEvent.java new file mode 100644 index 000000000..b4acb81ce --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/BeanWithInstanceWithWildcardEvent.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.lookup.dynamic.wildcard; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.event.Event; +import jakarta.enterprise.event.Observes; +import jakarta.enterprise.inject.Instance; +import jakarta.inject.Inject; + +@ApplicationScoped +public class BeanWithInstanceWithWildcardEvent { + static List seen = new ArrayList(); + + @Inject + Instance> instance1; + + @Inject + Instance> instance2; + + public void fire() { + instance1.get().fire("hello"); + instance2.get().fire("world"); + } + + public void observe(@Observes String str) { + seen.add(str); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/BeanWithWildcardInstance.java b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/BeanWithWildcardInstance.java new file mode 100644 index 000000000..fa3bd1c9c --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/BeanWithWildcardInstance.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.lookup.dynamic.wildcard; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.inject.Instance; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Inject; + +@ApplicationScoped +public class BeanWithWildcardInstance { + @Inject + Instance instance; + + public long count() { + return instance.stream().count(); + } + + @Produces + @Dependent + public static Integer produceInteger() { + return 42; + } + + @Produces + @Dependent + public static Double produceDouble() { + return 42.0; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/InstanceWithEventWithWildcardTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/InstanceWithEventWithWildcardTest.java new file mode 100644 index 000000000..e7cfb3525 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/InstanceWithEventWithWildcardTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.lookup.dynamic.wildcard; + +import static org.testng.Assert.assertEquals; + +import java.util.List; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.cdi.Sections; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class InstanceWithEventWithWildcardTest extends AbstractTest { + @Deployment + public static WebArchive createTestArchive() { + return new WebArchiveBuilder().withTestClass(InstanceWithEventWithWildcardTest.class) + .withClasses(BeanWithInstanceWithWildcardEvent.class).build(); + } + + @Test + @SpecAssertion(section = Sections.DYNAMIC_LOOKUP, id = "ca") + public void test() { + getContextualReference(BeanWithInstanceWithWildcardEvent.class).fire(); + assertEquals(BeanWithInstanceWithWildcardEvent.seen, List.of("hello", "world")); + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/InstanceWithWildcardTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/InstanceWithWildcardTest.java new file mode 100644 index 000000000..dd7bdb197 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/lookup/dynamic/wildcard/InstanceWithWildcardTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * Apache Software License 2.0 which is available at: + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.cdi.tck.tests.lookup.dynamic.wildcard; + +import static org.testng.Assert.assertEquals; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.cdi.tck.AbstractTest; +import org.jboss.cdi.tck.cdi.Sections; +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecVersion; +import org.testng.annotations.Test; + +@SpecVersion(spec = "cdi", version = "5.0") +public class InstanceWithWildcardTest extends AbstractTest { + @Deployment + public static WebArchive createTestArchive() { + return new WebArchiveBuilder().withTestClass(InstanceWithWildcardTest.class) + .withClasses(BeanWithWildcardInstance.class) + .build(); + } + + @Test + @SpecAssertion(section = Sections.DYNAMIC_LOOKUP, id = "ca") + public void test() { + assertEquals(getContextualReference(BeanWithWildcardInstance.class).count(), 2L); + } +} diff --git a/impl/src/main/resources/tck-audit-cdi.xml b/impl/src/main/resources/tck-audit-cdi.xml index 1da77a91d..58d6781c6 100644 --- a/impl/src/main/resources/tck-audit-cdi.xml +++ b/impl/src/main/resources/tck-audit-cdi.xml @@ -3615,9 +3615,9 @@ - The required type must not be a wildcard type. - If an injected |Instance| has a required type that is either a wildcard type or an |Event| whose specified type is a wildcard type, the container treats it as a definition error. - If a programmatically obtained |Instance| has a required type that is a wildcard type, non-portable behavior results. + The required type may be a wildcard type only if it does not have a lower bound. + If an injected |Instance| has a required type that is either a wildcard type with lower bound or an |Event| whose specified type is a wildcard type without lower bound, the container treats it as a definition error. + If a programmatically obtained |Instance| has a required type that is a wildcard type with lower bound, non-portable behavior results. @@ -5767,9 +5767,10 @@ - The specified type must not be a wildcard type. - If an injected |Event| has a specified type that is a wildcard type, the container treats it as a definition error. - If a programmatically obtained |Event| has a specified type that is a wildcard type, non-portable behavior results.. + The specified type may be a wildcard type only if it has a lower bound. + If an injected |Event| has a specified type that is a wildcard type without lower bound, the container treats it as a definition error. + If a programmatically obtained |Event| has a specified type that is a wildcard type without lower bound, non-portable behavior results. +