Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WELD-2761 Fix BeanManager not returning empty set if there are no con… #2889

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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());
}
}