Skip to content

Commit

Permalink
WELD-2761 Fix BeanManager not returning empty set if there are no con…
Browse files Browse the repository at this point in the history
…texts for given scope via getContexts() methods
  • Loading branch information
manovotn committed Oct 3, 2023
1 parent d6729a0 commit 58b0065
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ public Context getContext(Class<? extends Annotation> scopeType) {

@Override
public Collection<Context> getContexts(Class<? extends Annotation> scopeType) {
return Collections.unmodifiableList(contexts.get(scopeType));
List<Context> found = this.contexts.get(scopeType);
return found != null ? Collections.unmodifiableList(found) : Collections.EMPTY_LIST;
}

public Context getUnwrappedContext(Class<? extends Annotation> scopeType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.jboss.weld.tests.contexts.retrieval;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import jakarta.enterprise.context.NormalScope;

@NormalScope
@Inherited
@Target({ TYPE, METHOD, FIELD })
@Retention(RUNTIME)
public @interface CustomScope {
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,9 @@ public void testContextObjectRetrieval() {
contexts = weldManager.getContexts(RequestScoped.class);
Assert.assertEquals(4, contexts.size());
Assert.assertEquals(1, contexts.stream().filter(c -> c.isActive()).count());

// try to get contexts for scope that has none registered
contexts = weldManager.getContexts(CustomScope.class);
Assert.assertEquals(0, contexts.size());
}
}

0 comments on commit 58b0065

Please sign in to comment.