Backported refinements and polishing
This commit is contained in:
@@ -466,7 +466,7 @@ class ConfigurationClassEnhancer {
|
||||
try {
|
||||
fbProxy = fbClass.newInstance();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Unable to instantiate enhanced FactoryBean using Objenesis, " +
|
||||
"and regular FactoryBean instantiation via default constructor fails as well", ex);
|
||||
}
|
||||
|
||||
@@ -379,7 +379,7 @@ class ConfigurationClassParser {
|
||||
|
||||
Class<? extends PropertySourceFactory> factoryClass = propertySource.getClass("factory");
|
||||
PropertySourceFactory factory = (factoryClass == PropertySourceFactory.class ?
|
||||
DEFAULT_PROPERTY_SOURCE_FACTORY : BeanUtils.instantiate(factoryClass));
|
||||
DEFAULT_PROPERTY_SOURCE_FACTORY : BeanUtils.instantiateClass(factoryClass));
|
||||
|
||||
for (String location : locations) {
|
||||
try {
|
||||
|
||||
@@ -135,7 +135,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
|
||||
if (ann == null) {
|
||||
return null;
|
||||
}
|
||||
T bean = BeanUtils.instantiate(beanClass);
|
||||
T bean = BeanUtils.instantiateClass(beanClass);
|
||||
AnnotationBeanUtils.copyPropertiesToBean(ann, bean);
|
||||
return bean;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -72,7 +72,7 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean
|
||||
* @param methodNames an array of method names indicating the methods to use
|
||||
* @see #setMethodMappings
|
||||
*/
|
||||
public void setManagedMethods(String[] methodNames) {
|
||||
public void setManagedMethods(String... methodNames) {
|
||||
this.managedMethods = new HashSet<String>(Arrays.asList(methodNames));
|
||||
}
|
||||
|
||||
|
||||
@@ -94,8 +94,7 @@ public abstract class BshScriptUtils {
|
||||
return clazz.newInstance();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not instantiate script class [" +
|
||||
clazz.getName() + "]. Root cause is " + ex);
|
||||
throw new IllegalStateException("Could not instantiate script class: " + clazz.getName(), ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Mark Fisher
|
||||
* @since 2.5
|
||||
*/
|
||||
public class ScriptingDefaultsParser implements BeanDefinitionParser {
|
||||
class ScriptingDefaultsParser implements BeanDefinitionParser {
|
||||
|
||||
private static final String REFRESH_CHECK_DELAY_ATTRIBUTE = "refresh-check-delay";
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ScriptingDefaultsParser implements BeanDefinitionParser {
|
||||
LangNamespaceUtils.registerScriptFactoryPostProcessorIfNecessary(parserContext.getRegistry());
|
||||
String refreshCheckDelay = element.getAttribute(REFRESH_CHECK_DELAY_ATTRIBUTE);
|
||||
if (StringUtils.hasText(refreshCheckDelay)) {
|
||||
bd.getPropertyValues().add("defaultRefreshCheckDelay", new Long(refreshCheckDelay));
|
||||
bd.getPropertyValues().add("defaultRefreshCheckDelay", Long.valueOf(refreshCheckDelay));
|
||||
}
|
||||
String proxyTargetClass = element.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE);
|
||||
if (StringUtils.hasText(proxyTargetClass)) {
|
||||
|
||||
@@ -266,7 +266,7 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea
|
||||
}
|
||||
catch (InstantiationException ex) {
|
||||
throw new ScriptCompilationException(
|
||||
scriptSource, "Could not instantiate Groovy script class: " + scriptClass.getName(), ex);
|
||||
scriptSource, "Unable to instantiate Groovy script class: " + scriptClass.getName(), ex);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
throw new ScriptCompilationException(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -154,7 +154,7 @@ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAwar
|
||||
}
|
||||
catch (InstantiationException ex) {
|
||||
throw new ScriptCompilationException(
|
||||
scriptSource, "Could not instantiate script class: " + scriptClass.getName(), ex);
|
||||
scriptSource, "Unable to instantiate script class: " + scriptClass.getName(), ex);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
throw new ScriptCompilationException(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -27,18 +27,19 @@ import static org.junit.Assert.*;
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class AnnotationBindingTests {
|
||||
public class AnnotationBindingTests {
|
||||
|
||||
private AnnotatedTestBean testBean;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
testBean = (AnnotatedTestBean) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAnnotationBindingInAroundAdvice() {
|
||||
assertEquals("this value", testBean.doThis());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -182,19 +182,19 @@ public class LocalStatelessSessionProxyFactoryBeanTests {
|
||||
}
|
||||
|
||||
|
||||
public static interface MyHome extends EJBLocalHome {
|
||||
public interface MyHome extends EJBLocalHome {
|
||||
|
||||
MyBusinessMethods create() throws CreateException;
|
||||
}
|
||||
|
||||
|
||||
public static interface MyBusinessMethods {
|
||||
public interface MyBusinessMethods {
|
||||
|
||||
int getValue();
|
||||
}
|
||||
|
||||
|
||||
public static interface MyEjb extends EJBLocalObject, MyBusinessMethods {
|
||||
public interface MyEjb extends EJBLocalObject, MyBusinessMethods {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -279,26 +279,25 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
|
||||
}
|
||||
|
||||
|
||||
protected static interface MyHome extends EJBHome {
|
||||
protected interface MyHome extends EJBHome {
|
||||
|
||||
MyBusinessMethods create() throws CreateException, RemoteException;
|
||||
}
|
||||
|
||||
|
||||
protected static interface MyBusinessMethods {
|
||||
protected interface MyBusinessMethods {
|
||||
|
||||
int getValue() throws RemoteException;
|
||||
}
|
||||
|
||||
|
||||
protected static interface MyLocalBusinessMethods {
|
||||
protected interface MyLocalBusinessMethods {
|
||||
|
||||
int getValue();
|
||||
}
|
||||
|
||||
|
||||
protected static interface MyEjb extends EJBObject, MyBusinessMethods {
|
||||
|
||||
protected interface MyEjb extends EJBObject, MyBusinessMethods {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -218,7 +218,7 @@ public class FormattingConversionServiceTests {
|
||||
assertEquals(new LocalDate(2009, 11, 1), new LocalDate(dates.get(1)));
|
||||
assertEquals(new LocalDate(2009, 11, 2), new LocalDate(dates.get(2)));
|
||||
|
||||
Object model = BeanUtils.instantiate(modelClass);
|
||||
Object model = modelClass.newInstance();
|
||||
ConfigurablePropertyAccessor accessor = directFieldAccess ? PropertyAccessorFactory.forDirectFieldAccess(model) :
|
||||
PropertyAccessorFactory.forBeanPropertyAccess(model);
|
||||
accessor.setConversionService(formattingService);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class MethodNameBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAss
|
||||
public void testWithFallThrough() throws Exception {
|
||||
MethodNameBasedMBeanInfoAssembler assembler =
|
||||
getWithMapping("foobar", "add,myOperation,getName,setName,getAge");
|
||||
assembler.setManagedMethods(new String[]{"getNickName", "setNickName"});
|
||||
assembler.setManagedMethods("getNickName", "setNickName");
|
||||
|
||||
ModelMBeanInfo inf = assembler.getMBeanInfo(getBean(), getObjectName());
|
||||
MBeanAttributeInfo attr = inf.getAttribute("NickName");
|
||||
|
||||
@@ -52,7 +52,7 @@ public class MethodNameBasedMBeanInfoAssemblerTests extends AbstractJmxAssembler
|
||||
@Override
|
||||
protected MBeanInfoAssembler getAssembler() {
|
||||
MethodNameBasedMBeanInfoAssembler assembler = new MethodNameBasedMBeanInfoAssembler();
|
||||
assembler.setManagedMethods(new String[] {"add", "myOperation", "getName", "setName", "getAge"});
|
||||
assembler.setManagedMethods("add", "myOperation", "getName", "setName", "getAge");
|
||||
return assembler;
|
||||
}
|
||||
|
||||
|
||||
@@ -268,7 +268,7 @@ public class GroovyScriptFactoryTests {
|
||||
@Test
|
||||
public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception {
|
||||
ScriptSource script = mock(ScriptSource.class);
|
||||
final String badScript = "class Foo { public Foo(String foo) {}}";
|
||||
String badScript = "class Foo { public Foo(String foo) {}}";
|
||||
given(script.getScriptAsString()).willReturn(badScript);
|
||||
given(script.suggestedClassName()).willReturn("someName");
|
||||
GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX
|
||||
@@ -285,11 +285,10 @@ public class GroovyScriptFactoryTests {
|
||||
@Test
|
||||
public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception {
|
||||
ScriptSource script = mock(ScriptSource.class);
|
||||
final String badScript = "class Foo { protected Foo() {}}";
|
||||
String badScript = "class Foo { protected Foo() {} \n String toString() { 'X' }}";
|
||||
given(script.getScriptAsString()).willReturn(badScript);
|
||||
given(script.suggestedClassName()).willReturn("someName");
|
||||
GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX
|
||||
+ badScript);
|
||||
GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript);
|
||||
try {
|
||||
factory.getScriptedObject(script);
|
||||
fail("Must have thrown a ScriptCompilationException (no oublic no-arg ctor in scripted class).");
|
||||
@@ -562,7 +561,7 @@ public class GroovyScriptFactoryTests {
|
||||
testMetaClass("org/springframework/scripting/groovy/calculators-with-xsd.xml");
|
||||
}
|
||||
|
||||
private void testMetaClass(final String xmlFile) {
|
||||
private void testMetaClass(String xmlFile) {
|
||||
// expect the exception we threw in the custom metaclass to show it got invoked
|
||||
try {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext(xmlFile);
|
||||
|
||||
Reference in New Issue
Block a user