Skip to content

Commit

Permalink
ArC: throw NPE when null value is used for AdditionalBeanBuildItem
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Oct 14, 2024
1 parent af494da commit a03e5b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.jboss.jandex.DotName;

Expand Down Expand Up @@ -42,7 +41,7 @@ public static Builder builder() {
*/
@CheckReturnValue
public static AdditionalBeanBuildItem unremovableOf(Class<?> beanClass) {
return new AdditionalBeanBuildItem(Collections.singletonList(beanClass.getName()), false, null);
return new AdditionalBeanBuildItem(List.of(beanClass.getName()), false, null);
}

/**
Expand All @@ -53,29 +52,29 @@ public static AdditionalBeanBuildItem unremovableOf(Class<?> beanClass) {
*/
@CheckReturnValue
public static AdditionalBeanBuildItem unremovableOf(String beanClass) {
return new AdditionalBeanBuildItem(Collections.singletonList(beanClass), false, null);
return new AdditionalBeanBuildItem(List.of(beanClass), false, null);
}

private final List<String> beanClasses;
private final boolean removable;
private final DotName defaultScope;

public AdditionalBeanBuildItem(String... beanClasses) {
this(Arrays.asList(beanClasses), true, null);
this(List.of(beanClasses), true, null);
}

public AdditionalBeanBuildItem(Class<?>... beanClasses) {
this(Arrays.stream(beanClasses).map(Class::getName).collect(Collectors.toList()), true, null);
this(Arrays.stream(beanClasses).map(Class::getName).toArray(String[]::new));
}

AdditionalBeanBuildItem(List<String> beanClasses, boolean removable, DotName defaultScope) {
private AdditionalBeanBuildItem(List<String> beanClasses, boolean removable, DotName defaultScope) {
this.beanClasses = beanClasses;
this.removable = removable;
this.defaultScope = defaultScope;
}

public List<String> getBeanClasses() {
return Collections.unmodifiableList(beanClasses);
return beanClasses;
}

public boolean contains(String beanClass) {
Expand Down Expand Up @@ -151,7 +150,7 @@ public Builder setDefaultScope(DotName defaultScope) {
}

public AdditionalBeanBuildItem build() {
return new AdditionalBeanBuildItem(new ArrayList<>(beanClasses), removable, defaultScope);
return new AdditionalBeanBuildItem(List.copyOf(beanClasses), removable, defaultScope);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.arc.test.deployment;

import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;

public class AdditionalBeanBuildItemTest {

@Test
public void testNullNames() {
assertThrows(NullPointerException.class, () -> AdditionalBeanBuildItem.unremovableOf((String) null));
assertThrows(NullPointerException.class, () -> AdditionalBeanBuildItem.unremovableOf((Class<?>) null));
assertThrows(NullPointerException.class, () -> AdditionalBeanBuildItem.builder().addBeanClasses(null, "Foo").build());
assertThrows(NullPointerException.class, () -> new AdditionalBeanBuildItem("Bar", null));
assertThrows(NullPointerException.class, () -> new AdditionalBeanBuildItem(String.class, null));
}

}

0 comments on commit a03e5b3

Please sign in to comment.