This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git
The following commit(s) were added to refs/heads/main by this push:
new d8b74ee22 OWB-1155 - InjectionPoint.getQualifiers does not return the
list of selected qualifiers with type and qualifiers programmatic lookup
d8b74ee22 is described below
commit d8b74ee227a170af661365a8ba6ba9cd2acbb92b
Author: tandraschko <[email protected]>
AuthorDate: Wed Apr 15 10:29:03 2026 +0200
OWB-1155 - InjectionPoint.getQualifiers does not return the list of
selected qualifiers with type and qualifiers programmatic lookup
---
.../webbeans/inject/instance/InstanceImpl.java | 47 +++++++++++++++++++++-
.../InstanceQualifierInjectionPointTest.java | 33 +++++++++++++--
2 files changed, 75 insertions(+), 5 deletions(-)
diff --git
a/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
b/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
index c4bb34882..cc7b0fecb 100644
---
a/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
+++
b/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
@@ -18,12 +18,15 @@
*/
package org.apache.webbeans.inject.instance;
+import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
+import java.io.OptionalDataException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
+import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
@@ -46,6 +49,7 @@ import jakarta.enterprise.util.TypeLiteral;
import jakarta.inject.Provider;
import org.apache.webbeans.annotation.DefaultLiteral;
+import org.apache.webbeans.config.OwbParametrizedTypeImpl;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.container.InjectionResolver;
@@ -237,7 +241,30 @@ public class InstanceImpl<T> implements Instance<T>,
Serializable
final Annotation[] effectiveQualifiers = qualifiers != null &&
qualifiers.length > 0
? concatenateQualifiers(qualifiers)
: qualifierAnnotations.toArray(new Annotation[0]);
- return new InstanceImpl<>(sub, injectionPoint, webBeansContext,
effectiveQualifiers);
+ final InjectionPoint nextInjectionPoint = injectionPoint == null ? null
+ : new InstanceInjectionPoint(injectionPoint, effectiveQualifiers,
instanceTypeOverrideForSelectClass(injectionPoint, sub));
+ return new InstanceImpl<>(sub, nextInjectionPoint, webBeansContext,
effectiveQualifiers);
+ }
+
+ /**
+ * OWB-1155: only override {@link InjectionPoint#getType()} to {@code
Instance<subtype>} when the
+ * current injection point already represents an {@code Instance<…>}
dependency. Otherwise
+ * (e.g. {@code BeanConfiguratorImpl#createInstance} uses {@code Object}
with the field's
+ * {@link InjectionPoint}) forcing {@code Instance<subtype>} breaks {@link
org.apache.webbeans.portable.InjectionPointProducer}.
+ */
+ private static Type instanceTypeOverrideForSelectClass(InjectionPoint
injectionPoint, Type sub)
+ {
+ Type t = injectionPoint.getType();
+ if (!ParameterizedType.class.isInstance(t))
+ {
+ return null;
+ }
+ ParameterizedType pt = ParameterizedType.class.cast(t);
+ if (pt.getRawType() != Instance.class)
+ {
+ return null;
+ }
+ return new OwbParametrizedTypeImpl(null, Instance.class, sub);
}
/**
@@ -404,17 +431,24 @@ public class InstanceImpl<T> implements Instance<T>,
Serializable
{
private InjectionPoint delegate;
private Set<Annotation> qualifiers;
+ private Type typeOverride;
protected InstanceInjectionPoint(InjectionPoint injectionPoint,
Annotation[] newQualifiersArray)
+ {
+ this(injectionPoint, newQualifiersArray, null);
+ }
+
+ protected InstanceInjectionPoint(InjectionPoint injectionPoint,
Annotation[] newQualifiersArray, Type typeOverride)
{
this.delegate = injectionPoint;
this.qualifiers = Collections.unmodifiableSet(new
HashSet<>(Arrays.asList(newQualifiersArray)));
+ this.typeOverride = typeOverride;
}
@Override
public Type getType()
{
- return delegate.getType();
+ return typeOverride != null ? typeOverride : delegate.getType();
}
@Override
@@ -458,6 +492,14 @@ public class InstanceImpl<T> implements Instance<T>,
Serializable
OwbCustomObjectInputStream owbCustomObjectInputStream = new
OwbCustomObjectInputStream(inp, WebBeansUtil.getCurrentClassLoader());
qualifiers =
Set.class.cast(owbCustomObjectInputStream.readObject());
delegate =
InjectionPoint.class.cast(owbCustomObjectInputStream.readObject());
+ try
+ {
+ typeOverride =
Type.class.cast(owbCustomObjectInputStream.readObject());
+ }
+ catch (EOFException | OptionalDataException ex)
+ {
+ typeOverride = null;
+ }
}
private void writeObject(ObjectOutputStream op) throws IOException
@@ -465,6 +507,7 @@ public class InstanceImpl<T> implements Instance<T>,
Serializable
ObjectOutputStream out = new ObjectOutputStream(op);
out.writeObject(qualifiers);
out.writeObject(delegate);
+ out.writeObject(typeOverride);
}
}
diff --git
a/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/InstanceQualifierInjectionPointTest.java
b/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/InstanceQualifierInjectionPointTest.java
index 096cfce7a..cce488b9d 100644
---
a/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/InstanceQualifierInjectionPointTest.java
+++
b/webbeans-impl/src/test/java/org/apache/webbeans/test/instance/InstanceQualifierInjectionPointTest.java
@@ -55,10 +55,13 @@ public class InstanceQualifierInjectionPointTest extends
AbstractUnitTest
@Inject
private Instance<ShardContract> instance2;
+ @Inject
+ @Any
+ private Instance<Number> numbers;
@Test
public void checkQualfiers() {
- startContainer(Arrays.<Class<?>>asList(
+ startContainer(Arrays.asList(
Qualifier1.class,
QualifiersHolder.class,
Factory.class), Collections.<String>emptyList(), true);
@@ -74,12 +77,27 @@ public class InstanceQualifierInjectionPointTest extends
AbstractUnitTest
assertNotNull(instance2.get());
assertEquals(1, holder.getQualifiers().size());
assertEquals(Default.class,
holder.getQualifiers().iterator().next().annotationType());
+ }
+ /**
+ * OWB-1155: {@link Instance#select(Class, Annotation...)} must propagate
selected qualifiers to
+ * {@link InjectionPoint} (OWB-1122 fixed only {@link
Instance#select(Annotation...)}).
+ */
+ @Test
+ public void subtypeSelectPropagatesQualifiersToInjectionPointOw1155()
+ {
+ startContainer(Arrays.asList(
+ Qualifier1.class,
+ QualifiersHolder.class,
+ Factory.class), Collections.emptyList(), true);
-
+ assertNotNull(numbers.select(Integer.class, new
AnnotationLiteral<Qualifier1>()
+ {
+ }).get());
+ assertEquals(holder.getQualifiers().toString(), 1,
holder.getQualifiers().size());
+ assertEquals(Qualifier1.class,
holder.getQualifiers().iterator().next().annotationType());
}
-
public static class Factory
{
@Inject
@@ -99,6 +117,15 @@ public class InstanceQualifierInjectionPointTest extends
AbstractUnitTest
{
};
}
+
+ @Produces
+ @Qualifier1
+ @Default
+ public Integer produceNumber(final InjectionPoint ip)
+ {
+ holder.setQualifiers(ip.getQualifiers());
+ return 42;
+ }
}
@Target(METHOD)