From beb843d8189b46f3ab9a5feb06244c9688bdcb76 Mon Sep 17 00:00:00 2001 From: Johan Westerlund Date: Wed, 7 Apr 2021 13:43:18 +0200 Subject: [PATCH] fix 16268 --- .../arc/impl/AbstractInvocationContext.java | 2 +- .../interceptors/parameters/ParamInterceptor.java | 6 +++++- .../parameters/ParamInterceptorTest.java | 10 ++++++++++ .../test/interceptors/parameters/SimpleBean.java | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractInvocationContext.java b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractInvocationContext.java index ef917d0f9e647..fc79e1279d2dd 100644 --- a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractInvocationContext.java +++ b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractInvocationContext.java @@ -77,7 +77,7 @@ protected void validateParameters(Object[] params) { + ", type: " + parameterTypes[i] + "]"); } if (params[i] != null) { - if (!parameterTypes[i].isAssignableFrom(params[i].getClass())) { + if (!Types.boxedClass(parameterTypes[i]).isAssignableFrom(Types.boxedClass(params[i].getClass()))) { throw new IllegalArgumentException("The parameter type [" + params[i].getClass() + "] can not be assigned to the type for the target method [" + parameterTypes[i] + "]"); } diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/ParamInterceptor.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/ParamInterceptor.java index 6e63f18fc2423..3363ddbd90111 100644 --- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/ParamInterceptor.java +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/ParamInterceptor.java @@ -15,7 +15,11 @@ Object interceptParameters(InvocationContext ctx) throws Exception { Object[] params = ctx.getParameters(); if (params.length == 1 && params[0] != null) { - params[0] = params[0].getClass().getSimpleName(); + if (params[0] instanceof CharSequence) { + params[0] = params[0].getClass().getSimpleName(); + } else if (params[0] instanceof Number) { + params[0] = 123456; + } ctx.setParameters(params); } return ctx.proceed(); diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/ParamInterceptorTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/ParamInterceptorTest.java index 30b7059967532..67d18576b286c 100644 --- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/ParamInterceptorTest.java +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/ParamInterceptorTest.java @@ -37,6 +37,16 @@ public void testInterception() { assertThrows(IllegalArgumentException.class, () -> { simpleBean.setStringBuilderVal(new StringBuilder("intercept")); }); + + simpleBean.setPrimitiveIntVal(0); + assertEquals("123456", simpleBean.getVal()); + + simpleBean.setIntVal(1); + assertEquals("123456", simpleBean.getVal()); + + simpleBean.setNumberVal(2L); + assertEquals("123456", simpleBean.getVal()); + handle.destroy(); } } diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/SimpleBean.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/SimpleBean.java index fb638e8e94f0d..e94a82a77fa4e 100644 --- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/SimpleBean.java +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/parameters/SimpleBean.java @@ -17,6 +17,21 @@ void setStringBuilderVal(StringBuilder val) { this.val = val; } + @Simple + void setNumberVal(final Number val) { + this.val = val != null ? val.toString() : null; + } + + @Simple + void setPrimitiveIntVal(final int val) { + this.val = Integer.toString(val); + } + + @Simple + void setIntVal(final Integer val) { + this.val = val != null ? val.toString() : null; + } + String getVal() { return val != null ? val.toString() : null; }