Skip to content

Commit e2784fd

Browse files
mkoubagsmet
authored andcommitted
ArC: fix NPE in InvokerGenerator
- when a primitive param is annotated with a type annotation (cherry picked from commit 1e9dec5)
1 parent 7a6b00e commit e2784fd

File tree

2 files changed

+69
-10
lines changed

2 files changed

+69
-10
lines changed

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InvokerGenerator.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.jboss.jandex.JandexReflection;
2929
import org.jboss.jandex.MethodInfo;
3030
import org.jboss.jandex.PrimitiveType;
31+
import org.jboss.jandex.PrimitiveType.Primitive;
3132
import org.jboss.jandex.Type;
3233
import org.jboss.jandex.TypeVariable;
3334
import org.jboss.logging.Logger;
@@ -405,7 +406,7 @@ private static void assignWithUnboxingAndWideningConversion(BytecodeCreator byte
405406
bytecode = ifNotInstanceOf.trueBranch();
406407
}
407408
// widening conversions
408-
for (ClassType possibleSourceType : WIDENING_CONVERSIONS_TO.get(targetType)) {
409+
for (ClassType possibleSourceType : WIDENING_CONVERSIONS_TO.get(targetType.primitive())) {
409410
ResultHandle isInstance = bytecode.instanceOf(value, possibleSourceType.name().toString());
410411
BranchResult ifNotInstanceOf = bytecode.ifFalse(isInstance);
411412
BytecodeCreator unbox = ifNotInstanceOf.falseBranch();
@@ -431,18 +432,18 @@ private static void assignWithUnboxingAndWideningConversion(BytecodeCreator byte
431432
bytecode.throwException(exception);
432433
}
433434

434-
private static final Map<PrimitiveType, Set<ClassType>> WIDENING_CONVERSIONS_TO = Map.of(
435-
PrimitiveType.BOOLEAN, Set.of(),
436-
PrimitiveType.BYTE, Set.of(),
437-
PrimitiveType.SHORT, Set.of(ClassType.BYTE_CLASS),
438-
PrimitiveType.INT, Set.of(ClassType.BYTE_CLASS, ClassType.SHORT_CLASS, ClassType.CHARACTER_CLASS),
439-
PrimitiveType.LONG, Set.of(ClassType.BYTE_CLASS, ClassType.SHORT_CLASS, ClassType.INTEGER_CLASS,
435+
private static final Map<Primitive, Set<ClassType>> WIDENING_CONVERSIONS_TO = Map.of(
436+
Primitive.BOOLEAN, Set.of(),
437+
Primitive.BYTE, Set.of(),
438+
Primitive.SHORT, Set.of(ClassType.BYTE_CLASS),
439+
Primitive.INT, Set.of(ClassType.BYTE_CLASS, ClassType.SHORT_CLASS, ClassType.CHARACTER_CLASS),
440+
Primitive.LONG, Set.of(ClassType.BYTE_CLASS, ClassType.SHORT_CLASS, ClassType.INTEGER_CLASS,
440441
ClassType.CHARACTER_CLASS),
441-
PrimitiveType.FLOAT, Set.of(ClassType.BYTE_CLASS, ClassType.SHORT_CLASS, ClassType.INTEGER_CLASS,
442+
Primitive.FLOAT, Set.of(ClassType.BYTE_CLASS, ClassType.SHORT_CLASS, ClassType.INTEGER_CLASS,
442443
ClassType.LONG_CLASS, ClassType.CHARACTER_CLASS),
443-
PrimitiveType.DOUBLE, Set.of(ClassType.BYTE_CLASS, ClassType.SHORT_CLASS, ClassType.INTEGER_CLASS,
444+
Primitive.DOUBLE, Set.of(ClassType.BYTE_CLASS, ClassType.SHORT_CLASS, ClassType.INTEGER_CLASS,
444445
ClassType.LONG_CLASS, ClassType.FLOAT_CLASS, ClassType.CHARACTER_CLASS),
445-
PrimitiveType.CHAR, Set.of());
446+
Primitive.CHAR, Set.of());
446447

447448
static class FinisherGenerator {
448449
private final MethodCreator method;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package io.quarkus.arc.test.invoker.basic;
2+
3+
import static java.lang.annotation.ElementType.FIELD;
4+
import static java.lang.annotation.ElementType.METHOD;
5+
import static java.lang.annotation.ElementType.TYPE_USE;
6+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
import java.lang.annotation.Documented;
10+
import java.lang.annotation.Retention;
11+
import java.lang.annotation.Target;
12+
13+
import jakarta.enterprise.invoke.Invoker;
14+
import jakarta.inject.Singleton;
15+
16+
import org.jboss.jandex.MethodInfo;
17+
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.api.extension.RegisterExtension;
19+
20+
import io.quarkus.arc.Arc;
21+
import io.quarkus.arc.InstanceHandle;
22+
import io.quarkus.arc.test.ArcTestContainer;
23+
import io.quarkus.arc.test.invoker.InvokerHelper;
24+
import io.quarkus.arc.test.invoker.InvokerHelperRegistrar;
25+
26+
public class PrimitiveParamWithTypeAnnotationInvokerTest {
27+
@RegisterExtension
28+
public ArcTestContainer container = ArcTestContainer.builder()
29+
.beanClasses(MyService.class, Min.class)
30+
.beanRegistrars(new InvokerHelperRegistrar(MyService.class, (bean, factory, invokers) -> {
31+
MethodInfo hello = bean.getImplClazz().firstMethod("hello");
32+
invokers.put("hello", factory.createInvoker(bean, hello).build());
33+
}))
34+
.build();
35+
36+
@Test
37+
public void test() throws Exception {
38+
InvokerHelper helper = Arc.container().instance(InvokerHelper.class).get();
39+
40+
InstanceHandle<MyService> service = Arc.container().instance(MyService.class);
41+
42+
Invoker<MyService, String> hello = helper.getInvoker("hello");
43+
assertEquals("hello_18", hello.invoke(service.get(), new Object[] { 18 }));
44+
}
45+
46+
@Singleton
47+
public static class MyService {
48+
public String hello(@Min int age) {
49+
return "hello_" + age;
50+
}
51+
}
52+
53+
@Target({ METHOD, FIELD, TYPE_USE })
54+
@Retention(RUNTIME)
55+
@Documented
56+
public @interface Min {
57+
}
58+
}

0 commit comments

Comments
 (0)