Consistent handling of null array for arguments

Issue: SPR-16075

(cherry picked from commit c29b6f5)
This commit is contained in:
Juergen Hoeller
2017-10-16 15:34:18 +02:00
parent 4daf685eee
commit 03be8095ca
3 changed files with 40 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -140,7 +140,7 @@ public class MethodInvokingFactoryBeanTests {
mcfb.setTargetMethod("voidRetvalMethod");
mcfb.afterPropertiesSet();
Class<?> objType = mcfb.getObjectType();
assertTrue(objType.equals(void.class));
assertSame(objType, void.class);
// verify that we can call a method with args that are subtypes of the
// target method arg types
@@ -148,7 +148,7 @@ public class MethodInvokingFactoryBeanTests {
mcfb = new MethodInvokingFactoryBean();
mcfb.setTargetClass(TestClass1.class);
mcfb.setTargetMethod("supertypes");
mcfb.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello"});
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello");
mcfb.afterPropertiesSet();
mcfb.getObjectType();
@@ -157,7 +157,7 @@ public class MethodInvokingFactoryBeanTests {
mcfb.registerCustomEditor(String.class, new StringTrimmerEditor(false));
mcfb.setTargetClass(TestClass1.class);
mcfb.setTargetMethod("supertypes");
mcfb.setArguments(new Object[] {"1", new Object()});
mcfb.setArguments("1", new Object());
try {
mcfb.afterPropertiesSet();
fail("Should have thrown NoSuchMethodException");
@@ -225,7 +225,7 @@ public class MethodInvokingFactoryBeanTests {
mcfb = new MethodInvokingFactoryBean();
mcfb.setTargetClass(TestClass1.class);
mcfb.setTargetMethod("supertypes");
mcfb.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello"});
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello");
// should pass
mcfb.afterPropertiesSet();
}
@@ -235,7 +235,7 @@ public class MethodInvokingFactoryBeanTests {
MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean();
mcfb.setTargetClass(TestClass1.class);
mcfb.setTargetMethod("supertypes");
mcfb.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello", "bogus"});
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello", "bogus");
try {
mcfb.afterPropertiesSet();
fail("Matched method with wrong number of args");
@@ -247,7 +247,7 @@ public class MethodInvokingFactoryBeanTests {
mcfb = new MethodInvokingFactoryBean();
mcfb.setTargetClass(TestClass1.class);
mcfb.setTargetMethod("supertypes");
mcfb.setArguments(new Object[] {1, new Object()});
mcfb.setArguments(1, new Object());
try {
mcfb.afterPropertiesSet();
mcfb.getObject();
@@ -260,14 +260,14 @@ public class MethodInvokingFactoryBeanTests {
mcfb = new MethodInvokingFactoryBean();
mcfb.setTargetClass(TestClass1.class);
mcfb.setTargetMethod("supertypes2");
mcfb.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello", "bogus"});
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello", "bogus");
mcfb.afterPropertiesSet();
assertEquals("hello", mcfb.getObject());
mcfb = new MethodInvokingFactoryBean();
mcfb.setTargetClass(TestClass1.class);
mcfb.setTargetMethod("supertypes2");
mcfb.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), new Object()});
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), new Object());
try {
mcfb.afterPropertiesSet();
fail("Matched method when shouldn't have matched");
@@ -292,14 +292,14 @@ public class MethodInvokingFactoryBeanTests {
ArgumentConvertingMethodInvoker methodInvoker = new ArgumentConvertingMethodInvoker();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArgument");
methodInvoker.setArguments(new Object[] {5});
methodInvoker.setArguments(5);
methodInvoker.prepare();
methodInvoker.invoke();
methodInvoker = new ArgumentConvertingMethodInvoker();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArgument");
methodInvoker.setArguments(new Object[] {"5"});
methodInvoker.setArguments(5);
methodInvoker.prepare();
methodInvoker.invoke();
}
@@ -309,37 +309,37 @@ public class MethodInvokingFactoryBeanTests {
MethodInvokingBean methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new Object[]{new Integer[] {5, 10}});
methodInvoker.setArguments(new Object[] {new Integer[] {5, 10}});
methodInvoker.afterPropertiesSet();
methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new Object[]{new String[]{"5", "10"}});
methodInvoker.setArguments(new Object[] {new String[] {"5", "10"}});
methodInvoker.afterPropertiesSet();
methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new Object[]{new Integer[] {5, 10}});
methodInvoker.setArguments(new Object[] {new Integer[] {5, 10}});
methodInvoker.afterPropertiesSet();
methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new String[]{"5", "10"});
methodInvoker.setArguments("5", "10");
methodInvoker.afterPropertiesSet();
methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new Object[]{new Integer[] {5, 10}});
methodInvoker.setArguments(new Object[] {new Integer[] {5, 10}});
methodInvoker.afterPropertiesSet();
methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new Object[]{"5", "10"});
methodInvoker.setArguments("5", "10");
methodInvoker.afterPropertiesSet();
}