Consistent use of @Nullable across the codebase (even for internals)
Beyond just formally declaring the current behavior, this revision actually enforces non-null behavior in selected signatures now, not tolerating null values anymore when not explicitly documented. It also changes some utility methods with historic null-in/null-out tolerance towards enforced non-null return values, making them a proper citizen in non-null assignments. Some issues are left as to-do: in particular a thorough revision of spring-test, and a few tests with unclear failures (ignored as "TODO: NULLABLE") to be sorted out in a follow-up commit. Issue: SPR-15540
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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<>(), 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<>(), 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<>(), 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<>(), 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<>(), 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.beans.factory.xml;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
@@ -30,8 +31,6 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
@@ -47,18 +46,6 @@ public class XmlBeanDefinitionReaderTests {
|
||||
new XmlBeanDefinitionReader(registry).setDocumentReaderClass(DefaultBeanDefinitionDocumentReader.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void setParserClassToNull() {
|
||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||
new XmlBeanDefinitionReader(registry).setDocumentReaderClass(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void setParserClassToUnsupportedParserType() throws Exception {
|
||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||
new XmlBeanDefinitionReader(registry).setDocumentReaderClass(String.class);
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionStoreException.class)
|
||||
public void withOpenInputStream() {
|
||||
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -430,11 +430,6 @@ public class CustomEditorTests {
|
||||
assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCustomNumberEditorCtorWithNullNumberType() throws Exception {
|
||||
new CustomNumberEditor(null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomNumberEditorWithAllowEmpty() {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
|
||||
|
||||
Reference in New Issue
Block a user