This is an automated email from the ASF dual-hosted git repository. amichai pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/aries-rsa.git
commit 2018add363071c40dda22dfdf9a477dfc80b32bf Author: Amichai Rothman <[email protected]> AuthorDate: Thu Sep 14 02:08:20 2023 +0300 ARIES-2115 - Fix NPE when any service method parameter is null --- .../org/apache/aries/rsa/provider/tcp/MethodInvoker.java | 15 ++++++--------- .../apache/aries/rsa/provider/tcp/MethodInvokerTest.java | 9 +++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/MethodInvoker.java b/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/MethodInvoker.java index 8ef6a0d3..5ff2f77e 100644 --- a/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/MethodInvoker.java +++ b/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/MethodInvoker.java @@ -19,10 +19,8 @@ package org.apache.aries.rsa.provider.tcp; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.List; public class MethodInvoker { @@ -81,16 +79,15 @@ public class MethodInvoker { if (type.isPrimitive()) { return paramType == primTypes.get(type); } - return type.isAssignableFrom(paramType); + return paramType == null || type.isAssignableFrom(paramType); } private Class<?>[] getTypes(Object[] args) { - List<Class<?>> parameterTypes = new ArrayList<>(); - if (args != null) { - for (Object arg : args) { - parameterTypes.add(arg.getClass()); - } + int len = args == null ? 0 : args.length; + Class<?>[] types = new Class<?>[len]; + for (int i = 0; i < len; i++) { + types[i] = args[i] == null ? null : args[i].getClass(); } - return parameterTypes.toArray(new Class[]{}); + return types; } } diff --git a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/MethodInvokerTest.java b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/MethodInvokerTest.java index 2c2c6e3d..7dcb296f 100644 --- a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/MethodInvokerTest.java +++ b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/MethodInvokerTest.java @@ -55,6 +55,15 @@ public class MethodInvokerTest { assertEquals(UnsupportedOperationException.class, invoker.invoke("returnSomething", null).getClass()); } + @Test + public void testNullParam() throws Exception { + class Tester { + public int f(String s) { return s == null ? 0 : s.length(); } + } + MethodInvoker invoker = new MethodInvoker(new Tester()); + assertEquals(0, invoker.invoke("f", new Object[]{ null })); + } + @Test public void testOverloadedNumberOfParams() throws Exception { class Tester {
