diff --git a/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java b/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java index 09048cbe1f..dfc3c2dbba 100644 --- a/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java @@ -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. @@ -113,9 +113,9 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life * Add a new BeanFactoryPostProcessor that will get applied to the internal * bean factory of this application context on refresh, before any of the * bean definitions get evaluated. To be invoked during context configuration. - * @param beanFactoryPostProcessor the factory processor to register + * @param postProcessor the factory processor to register */ - void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor); + void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor); /** * Add a new ApplicationListener that will be notified on context events diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index d21d28177b..791ed80ce8 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -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. @@ -47,6 +47,7 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.EmbeddedValueResolverAware; import org.springframework.context.EnvironmentAware; import org.springframework.context.HierarchicalMessageSource; import org.springframework.context.LifecycleProcessor; @@ -461,8 +462,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader } @Override - public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor) { - this.beanFactoryPostProcessors.add(beanFactoryPostProcessor); + public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor) { + Assert.notNull(postProcessor, "BeanFactoryPostProcessor must not be null"); + this.beanFactoryPostProcessors.add(postProcessor); } @@ -476,6 +478,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader @Override public void addApplicationListener(ApplicationListener listener) { + Assert.notNull(listener, "ApplicationListener must not be null"); if (this.applicationEventMulticaster != null) { this.applicationEventMulticaster.addApplicationListener(listener); } @@ -627,11 +630,12 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader // Configure the bean factory with context callbacks. beanFactory.addBeanPostProcessor(new ApplicationContextAwareProcessor(this)); + beanFactory.ignoreDependencyInterface(EnvironmentAware.class); + beanFactory.ignoreDependencyInterface(EmbeddedValueResolverAware.class); beanFactory.ignoreDependencyInterface(ResourceLoaderAware.class); beanFactory.ignoreDependencyInterface(ApplicationEventPublisherAware.class); beanFactory.ignoreDependencyInterface(MessageSourceAware.class); beanFactory.ignoreDependencyInterface(ApplicationContextAware.class); - beanFactory.ignoreDependencyInterface(EnvironmentAware.class); // BeanFactory interface not registered as resolvable type in a plain factory. // MessageSource registered (and found for autowiring) as a bean. diff --git a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java index 342607ed34..6e37317b6f 100644 --- a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java +++ b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java @@ -98,8 +98,8 @@ public class FormattingConversionService extends GenericConversionService static Class getFieldType(Formatter formatter) { Class fieldType = GenericTypeResolver.resolveTypeArgument(formatter.getClass(), Formatter.class); if (fieldType == null) { - throw new IllegalArgumentException("Unable to extract parameterized field type argument from Formatter [" + - formatter.getClass().getName() + "]; does the formatter parameterize the generic type?"); + throw new IllegalArgumentException("Unable to extract the parameterized field type from Formatter [" + + formatter.getClass().getName() + "]; does the class parameterize the generic type?"); } return fieldType; } diff --git a/spring-context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java b/spring-context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java index 48efe37957..000135a65e 100644 --- a/spring-context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java +++ b/spring-context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java @@ -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. @@ -82,6 +82,7 @@ public class CustomNamespaceHandlerTests { private GenericApplicationContext beanFactory; + @Before public void setUp() throws Exception { NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS); @@ -114,7 +115,7 @@ public class CustomNamespaceHandlerTests { assertTrue(AopUtils.isAopProxy(bean)); Advisor[] advisors = ((Advised) bean).getAdvisors(); assertEquals("Incorrect number of advisors", 1, advisors.length); - assertEquals("Incorrect advice class.", DebugInterceptor.class, advisors[0].getAdvice().getClass()); + assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass()); } @Test @@ -138,8 +139,8 @@ public class CustomNamespaceHandlerTests { assertTrue(AopUtils.isAopProxy(bean)); Advisor[] advisors = ((Advised) bean).getAdvisors(); assertEquals("Incorrect number of advisors", 2, advisors.length); - assertEquals("Incorrect advice class.", DebugInterceptor.class, advisors[0].getAdvice().getClass()); - assertEquals("Incorrect advice class.", NopInterceptor.class, advisors[1].getAdvice().getClass()); + assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass()); + assertEquals("Incorrect advice class", NopInterceptor.class, advisors[1].getAdvice().getClass()); } @Test @@ -148,30 +149,21 @@ public class CustomNamespaceHandlerTests { assertEquals("foo", beanDefinition.getAttribute("objectName")); } - /** - * http://opensource.atlassian.com/projects/spring/browse/SPR-2728 - */ - @Test + @Test // SPR-2728 public void testCustomElementNestedWithinUtilList() throws Exception { List things = (List) this.beanFactory.getBean("list.of.things"); assertNotNull(things); assertEquals(2, things.size()); } - /** - * http://opensource.atlassian.com/projects/spring/browse/SPR-2728 - */ - @Test + @Test // SPR-2728 public void testCustomElementNestedWithinUtilSet() throws Exception { Set things = (Set) this.beanFactory.getBean("set.of.things"); assertNotNull(things); assertEquals(2, things.size()); } - /** - * http://opensource.atlassian.com/projects/spring/browse/SPR-2728 - */ - @Test + @Test // SPR-2728 public void testCustomElementNestedWithinUtilMap() throws Exception { Map things = (Map) this.beanFactory.getBean("map.of.things"); assertNotNull(things); @@ -229,6 +221,7 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionDecoratorForAttribute("object-name", new ObjectNameBeanDefinitionDecorator()); } + private static class TestBeanDefinitionParser implements BeanDefinitionParser { @Override @@ -242,11 +235,11 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport { definition.setPropertyValues(mpvs); parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), definition); - return null; } } + private static final class PersonDefinitionParser extends AbstractSingleBeanDefinitionParser { @Override @@ -261,6 +254,7 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport { } } + private static class PropertyModifyingBeanDefinitionDecorator implements BeanDefinitionDecorator { @Override @@ -277,6 +271,7 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport { } } + private static class DebugBeanDefinitionDecorator extends AbstractInterceptorDrivenBeanDefinitionDecorator { @Override @@ -285,6 +280,7 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport { } } + private static class NopInterceptorBeanDefinitionDecorator extends AbstractInterceptorDrivenBeanDefinitionDecorator { @Override @@ -293,6 +289,7 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport { } } + private static class ObjectNameBeanDefinitionDecorator implements BeanDefinitionDecorator { @Override @@ -302,5 +299,5 @@ final class TestNamespaceHandler extends NamespaceHandlerSupport { return definition; } } -} +} diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 21b367dc07..2d03ed810b 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -83,9 +83,8 @@ public class TypeDescriptor implements Serializable { Assert.notNull(methodParameter, "MethodParameter must not be null"); this.resolvableType = ResolvableType.forMethodParameter(methodParameter); this.type = this.resolvableType.resolve(methodParameter.getParameterType()); - this.annotations = (methodParameter.getParameterIndex() == -1 ? - nullSafeAnnotations(methodParameter.getMethodAnnotations()) : - nullSafeAnnotations(methodParameter.getParameterAnnotations())); + this.annotations = nullSafeAnnotations(methodParameter.getParameterIndex() == -1 ? + methodParameter.getMethodAnnotations() :methodParameter.getParameterAnnotations()); } /** @@ -384,7 +383,7 @@ public class TypeDescriptor implements Serializable { * @throws IllegalStateException if this type is not a {@code java.util.Map} */ public TypeDescriptor getMapKeyTypeDescriptor() { - Assert.state(isMap(), "Not a java.util.Map"); + Assert.state(isMap(), "Not a [java.util.Map]"); return getRelatedIfResolvable(this, this.resolvableType.asMap().getGeneric(0)); } @@ -419,7 +418,7 @@ public class TypeDescriptor implements Serializable { * @throws IllegalStateException if this type is not a {@code java.util.Map} */ public TypeDescriptor getMapValueTypeDescriptor() { - Assert.state(isMap(), "Not a java.util.Map"); + Assert.state(isMap(), "Not a [java.util.Map]"); return getRelatedIfResolvable(this, this.resolvableType.asMap().getGeneric(1)); } @@ -529,9 +528,9 @@ public class TypeDescriptor implements Serializable { * @return the collection type descriptor */ public static TypeDescriptor collection(Class collectionType, TypeDescriptor elementTypeDescriptor) { - Assert.notNull(collectionType, "collectionType must not be null"); + Assert.notNull(collectionType, "Collection type must not be null"); if (!Collection.class.isAssignableFrom(collectionType)) { - throw new IllegalArgumentException("collectionType must be a java.util.Collection"); + throw new IllegalArgumentException("Collection type must be a [java.util.Collection]"); } ResolvableType element = (elementTypeDescriptor != null ? elementTypeDescriptor.resolvableType : null); return new TypeDescriptor(ResolvableType.forClassWithGenerics(collectionType, element), null, null); diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java b/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java index 9280c4eac3..5331ed6191 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 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,15 +27,16 @@ public interface ConverterRegistry { /** * Add a plain converter to this registry. - * The convertible sourceType/targetType pair is derived from the Converter's parameterized types. + * The convertible source/target type pair is derived from the Converter's parameterized types. * @throws IllegalArgumentException if the parameterized types could not be resolved */ void addConverter(Converter converter); /** * Add a plain converter to this registry. - * The convertible sourceType/targetType pair is specified explicitly. - * Allows for a Converter to be reused for multiple distinct pairs without having to create a Converter class for each pair. + * The convertible source/target type pair is specified explicitly. + *

Allows for a Converter to be reused for multiple distinct pairs without + * having to create a Converter class for each pair. * @since 3.1 */ void addConverter(Class sourceType, Class targetType, Converter converter); @@ -47,13 +48,13 @@ public interface ConverterRegistry { /** * Add a ranged converter factory to this registry. - * The convertible sourceType/rangeType pair is derived from the ConverterFactory's parameterized types. - * @throws IllegalArgumentException if the parameterized types could not be resolved. + * The convertible source/target type pair is derived from the ConverterFactory's parameterized types. + * @throws IllegalArgumentException if the parameterized types could not be resolved */ - void addConverterFactory(ConverterFactory converterFactory); + void addConverterFactory(ConverterFactory factory); /** - * Remove any converters from sourceType to targetType. + * Remove any converters from {@code sourceType} to {@code targetType}. * @param sourceType the source type * @param targetType the target type */ diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index 52df6a7766..17868a3765 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -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. @@ -97,8 +97,10 @@ public class GenericConversionService implements ConfigurableConversionService { @Override public void addConverter(Converter converter) { ResolvableType[] typeInfo = getRequiredTypeInfo(converter, Converter.class); - Assert.notNull(typeInfo, "Unable to the determine sourceType and targetType " + - " which your Converter converts between; declare these generic types."); + if (typeInfo == null) { + throw new IllegalArgumentException("Unable to determine source type and target type for your " + + "Converter [" + converter.getClass().getName() + "]; does the class parameterize those types?"); + } addConverter(new ConverterAdapter(converter, typeInfo[0], typeInfo[1])); } @@ -115,11 +117,13 @@ public class GenericConversionService implements ConfigurableConversionService { } @Override - public void addConverterFactory(ConverterFactory converterFactory) { - ResolvableType[] typeInfo = getRequiredTypeInfo(converterFactory, ConverterFactory.class); - Assert.notNull(typeInfo, "Unable to the determine source type and target range type R which your " + - "ConverterFactory converts between; declare these generic types."); - addConverter(new ConverterFactoryAdapter(converterFactory, + public void addConverterFactory(ConverterFactory factory) { + ResolvableType[] typeInfo = getRequiredTypeInfo(factory, ConverterFactory.class); + if (typeInfo == null) { + throw new IllegalArgumentException("Unable to determine source type and target type for your " + + "ConverterFactory [" + factory.getClass().getName() + "]; does the class parameterize those types?"); + } + addConverter(new ConverterFactoryAdapter(factory, new ConvertiblePair(typeInfo[0].resolve(), typeInfo[1].resolve()))); } diff --git a/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java b/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java index 73c9b158b2..7f1c730517 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java @@ -37,6 +37,7 @@ import org.springframework.util.ObjectUtils; * @author Juergen Hoeller * @author Sam Brannen * @since 1.2.6 + * @see Resource#getInputStream() * @see java.io.Reader * @see java.nio.charset.Charset */ @@ -142,8 +143,8 @@ public class EncodedResource implements InputStreamSource { } /** - * Open a {@code java.io.InputStream} for the specified resource, ignoring any - * specified {@link #getCharset() Charset} or {@linkplain #getEncoding() encoding}. + * Open an {@code InputStream} for the specified resource, ignoring any specified + * {@link #getCharset() Charset} or {@linkplain #getEncoding() encoding}. * @throws IOException if opening the InputStream failed * @see #requiresReader() * @see #getReader() diff --git a/spring-core/src/test/java/org/springframework/tests/TestResourceUtils.java b/spring-core/src/test/java/org/springframework/tests/TestResourceUtils.java index 66be13072e..0144f65d79 100644 --- a/spring-core/src/test/java/org/springframework/tests/TestResourceUtils.java +++ b/spring-core/src/test/java/org/springframework/tests/TestResourceUtils.java @@ -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. @@ -18,29 +18,22 @@ package org.springframework.tests; import org.springframework.core.io.ClassPathResource; -import static java.lang.String.*; - /** * Convenience utilities for common operations with test resources. * * @author Chris Beams */ -public class TestResourceUtils { +public abstract class TestResourceUtils { /** - * Loads a {@link ClassPathResource} qualified by the simple name of clazz, + * Load a {@link ClassPathResource} qualified by the simple name of clazz, * and relative to the package for clazz. - * *

Example: given a clazz 'com.foo.BarTests' and a resourceSuffix of 'context.xml', * this method will return a ClassPathResource representing com/foo/BarTests-context.xml - * *

Intended for use loading context configuration XML files within JUnit tests. - * - * @param clazz - * @param resourceSuffix */ public static ClassPathResource qualifiedResource(Class clazz, String resourceSuffix) { - return new ClassPathResource(format("%s-%s", clazz.getSimpleName(), resourceSuffix), clazz); + return new ClassPathResource(String.format("%s-%s", clazz.getSimpleName(), resourceSuffix), clazz); } } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java index 73ad67603e..f40bbf3014 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java @@ -58,8 +58,8 @@ public class OpEQ extends Operator { String leftDesc = left.exitTypeDescriptor; String rightDesc = right.exitTypeDescriptor; - DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, - this.leftActualDescriptor, this.rightActualDescriptor); + DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility( + leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor); return (!dc.areNumbers || dc.areCompatible); } @@ -73,17 +73,15 @@ public class OpEQ extends Operator { boolean leftPrim = CodeFlow.isPrimitive(leftDesc); boolean rightPrim = CodeFlow.isPrimitive(rightDesc); - DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, - this.leftActualDescriptor, this.rightActualDescriptor); + DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility( + leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor); if (dc.areNumbers && dc.areCompatible) { char targetType = dc.compatibleType; - getLeftOperand().generateCode(mv, cf); if (!leftPrim) { CodeFlow.insertUnboxInsns(mv, targetType, leftDesc); } - cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.exitCompilationScope(); @@ -91,23 +89,23 @@ public class OpEQ extends Operator { CodeFlow.insertUnboxInsns(mv, targetType, rightDesc); } // assert: SpelCompiler.boxingCompatible(leftDesc, rightDesc) - if (targetType=='D') { + if (targetType == 'D') { mv.visitInsn(DCMPL); mv.visitJumpInsn(IFNE, elseTarget); } - else if (targetType=='F') { + else if (targetType == 'F') { mv.visitInsn(FCMPL); mv.visitJumpInsn(IFNE, elseTarget); } - else if (targetType=='J') { + else if (targetType == 'J') { mv.visitInsn(LCMP); mv.visitJumpInsn(IFNE, elseTarget); } - else if (targetType=='I' || targetType=='Z') { + else if (targetType == 'I' || targetType == 'Z') { mv.visitJumpInsn(IF_ICMPNE, elseTarget); } else { - throw new IllegalStateException("Unexpected descriptor "+leftDesc); + throw new IllegalStateException("Unexpected descriptor " + leftDesc); } } else { @@ -120,11 +118,11 @@ public class OpEQ extends Operator { CodeFlow.insertBoxIfNecessary(mv, rightDesc.charAt(0)); } Label leftNotNull = new Label(); - mv.visitInsn(DUP_X1); // Dup right on the top of the stack - mv.visitJumpInsn(IFNONNULL,leftNotNull); + mv.visitInsn(DUP_X1); // dup right on the top of the stack + mv.visitJumpInsn(IFNONNULL, leftNotNull); // Right is null! mv.visitInsn(SWAP); - mv.visitInsn(POP); // remove it + mv.visitInsn(POP); // remove it Label rightNotNull = new Label(); mv.visitJumpInsn(IFNONNULL, rightNotNull); // Left is null too @@ -132,7 +130,7 @@ public class OpEQ extends Operator { mv.visitJumpInsn(GOTO, endOfIf); mv.visitLabel(rightNotNull); mv.visitInsn(ICONST_0); - mv.visitJumpInsn(GOTO,endOfIf); + mv.visitJumpInsn(GOTO, endOfIf); mv.visitLabel(leftNotNull); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false); mv.visitLabel(endOfIf); @@ -140,7 +138,7 @@ public class OpEQ extends Operator { return; } mv.visitInsn(ICONST_1); - mv.visitJumpInsn(GOTO,endOfIf); + mv.visitJumpInsn(GOTO, endOfIf); mv.visitLabel(elseTarget); mv.visitInsn(ICONST_0); mv.visitLabel(endOfIf); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpNE.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpNE.java index 543e459ebe..4f96b3bbdd 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpNE.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpNE.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -36,12 +36,13 @@ public class OpNE extends Operator { this.exitTypeDescriptor = "Z"; } + @Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); - leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); - rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); + this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); + this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); return BooleanTypedValue.forValue(!equalityCheck(state, left, right)); } @@ -57,7 +58,8 @@ public class OpNE extends Operator { String leftDesc = left.exitTypeDescriptor; String rightDesc = right.exitTypeDescriptor; - DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, leftActualDescriptor, rightActualDescriptor); + DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility( + leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor); return (!dc.areNumbers || dc.areCompatible); } @@ -70,16 +72,15 @@ public class OpNE extends Operator { boolean leftPrim = CodeFlow.isPrimitive(leftDesc); boolean rightPrim = CodeFlow.isPrimitive(rightDesc); - DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, leftActualDescriptor, rightActualDescriptor); + DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility( + leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor); if (dc.areNumbers && dc.areCompatible) { char targetType = dc.compatibleType; - getLeftOperand().generateCode(mv, cf); if (!leftPrim) { CodeFlow.insertUnboxInsns(mv, targetType, leftDesc); } - cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.exitCompilationScope(); @@ -103,7 +104,7 @@ public class OpNE extends Operator { mv.visitJumpInsn(IF_ICMPEQ, elseTarget); } else { - throw new IllegalStateException("Unexpected descriptor "+leftDesc); + throw new IllegalStateException("Unexpected descriptor " + leftDesc); } } else { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java index 7172dd966b..73ed4a75c7 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -84,6 +84,7 @@ public abstract class Operator extends SpelNodeImpl { return sb.toString(); } + protected boolean isCompilableOperatorUsingNumerics() { SpelNodeImpl left = getLeftOperand(); SpelNodeImpl right= getRightOperand(); @@ -94,8 +95,8 @@ public abstract class Operator extends SpelNodeImpl { // Supported operand types for equals (at the moment) String leftDesc = left.exitTypeDescriptor; String rightDesc = right.exitTypeDescriptor; - DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, - this.leftActualDescriptor, this.rightActualDescriptor); + DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility( + leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor); return (dc.areNumbers && dc.areCompatible); } @@ -109,9 +110,9 @@ public abstract class Operator extends SpelNodeImpl { boolean unboxLeft = !CodeFlow.isPrimitive(leftDesc); boolean unboxRight = !CodeFlow.isPrimitive(rightDesc); - DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, - this.leftActualDescriptor, this.rightActualDescriptor); - char targetType = dc.compatibleType;//CodeFlow.toPrimitiveTargetDesc(leftDesc); + DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility( + leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor); + char targetType = dc.compatibleType; // CodeFlow.toPrimitiveTargetDesc(leftDesc); getLeftOperand().generateCode(mv, cf); if (unboxLeft) { @@ -128,23 +129,23 @@ public abstract class Operator extends SpelNodeImpl { // assert: SpelCompiler.boxingCompatible(leftDesc, rightDesc) Label elseTarget = new Label(); Label endOfIf = new Label(); - if (targetType=='D') { + if (targetType == 'D') { mv.visitInsn(DCMPG); mv.visitJumpInsn(compInstruction1, elseTarget); } - else if (targetType=='F') { + else if (targetType == 'F') { mv.visitInsn(FCMPG); mv.visitJumpInsn(compInstruction1, elseTarget); } - else if (targetType=='J') { + else if (targetType == 'J') { mv.visitInsn(LCMP); mv.visitJumpInsn(compInstruction1, elseTarget); } - else if (targetType=='I') { + else if (targetType == 'I') { mv.visitJumpInsn(compInstruction2, elseTarget); } else { - throw new IllegalStateException("Unexpected descriptor "+leftDesc); + throw new IllegalStateException("Unexpected descriptor " + leftDesc); } // Other numbers are not yet supported (isCompilable will not have returned true) @@ -215,8 +216,8 @@ public abstract class Operator extends SpelNodeImpl { /** - * A descriptor comparison encapsulates the result of comparing descriptor for two operands and - * describes at what level they are compatible. + * A descriptor comparison encapsulates the result of comparing descriptor + * for two operands and describes at what level they are compatible. */ protected static class DescriptorComparison { @@ -224,12 +225,12 @@ public abstract class Operator extends SpelNodeImpl { static DescriptorComparison INCOMPATIBLE_NUMBERS = new DescriptorComparison(true, false, ' '); - final boolean areNumbers; // Were the two compared descriptor both for numbers? + final boolean areNumbers; // Were the two compared descriptor both for numbers? - final boolean areCompatible; // If they were numbers, were they compatible? + final boolean areCompatible; // If they were numbers, were they compatible? + + final char compatibleType; // When compatible, what is the descriptor of the common type - final char compatibleType; // When compatible, what is the descriptor of the common type - private DescriptorComparison(boolean areNumbers, boolean areCompatible, char compatibleType) { this.areNumbers = areNumbers; this.areCompatible = areCompatible; @@ -237,12 +238,13 @@ public abstract class Operator extends SpelNodeImpl { } /** - * Returns an object that indicates whether the input descriptors are compatible. A declared descriptor - * is what could statically be determined (e.g. from looking at the return value of a property accessor - * method) whilst an actual descriptor is the type of an actual object that was returned, which may differ. - * For generic types with unbound type variables the declared descriptor discovered may be 'Object' but - * from the actual descriptor it is possible to observe that the objects are really numeric values (e.g. - * ints). + * Return an object that indicates whether the input descriptors are compatible. + *

A declared descriptor is what could statically be determined (e.g. from looking + * at the return value of a property accessor method) whilst an actual descriptor + * is the type of an actual object that was returned, which may differ. + *

For generic types with unbound type variables, the declared descriptor + * discovered may be 'Object' but from the actual descriptor it is possible to + * observe that the objects are really numeric values (e.g. ints). * @param leftDeclaredDescriptor the statically determinable left descriptor * @param rightDeclaredDescriptor the statically determinable right descriptor * @param leftActualDescriptor the dynamic/runtime left object descriptor diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.java index 31fb497c8a..e153f3790d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -40,8 +40,8 @@ public abstract class DatabasePopulatorUtils { * @throws DataAccessException if an error occurs, specifically a {@link ScriptException} */ public static void execute(DatabasePopulator populator, DataSource dataSource) throws DataAccessException { - Assert.notNull(populator, "DatabasePopulator must be provided"); - Assert.notNull(dataSource, "DataSource must be provided"); + Assert.notNull(populator, "DatabasePopulator must not be null"); + Assert.notNull(dataSource, "DataSource must not be null"); try { Connection connection = DataSourceUtils.getConnection(dataSource); try { @@ -53,11 +53,10 @@ public abstract class DatabasePopulatorUtils { } } } - catch (Exception ex) { + catch (Throwable ex) { if (ex instanceof ScriptException) { throw (ScriptException) ex; } - throw new UncategorizedScriptException("Failed to execute database script", ex); } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java index 75a668d516..513a9c6085 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java @@ -52,7 +52,7 @@ import org.springframework.util.StringUtils; */ public class ResourceDatabasePopulator implements DatabasePopulator { - private List scripts = new ArrayList(); + List scripts = new ArrayList(); private String sqlScriptEncoding; @@ -117,7 +117,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator { */ public void addScript(Resource script) { Assert.notNull(script, "Script must not be null"); - getScripts().add(script); + this.scripts.add(script); } /** @@ -126,7 +126,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator { */ public void addScripts(Resource... scripts) { assertContentsOfScriptArray(scripts); - getScripts().addAll(Arrays.asList(scripts)); + this.scripts.addAll(Arrays.asList(scripts)); } /** @@ -140,6 +140,11 @@ public class ResourceDatabasePopulator implements DatabasePopulator { this.scripts = new ArrayList(Arrays.asList(scripts)); } + private void assertContentsOfScriptArray(Resource... scripts) { + Assert.notNull(scripts, "Scripts array must not be null"); + Assert.noNullElements(scripts, "Scripts array must not contain null elements"); + } + /** * Specify the encoding for the configured SQL scripts, if different from the * platform encoding. @@ -220,6 +225,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator { this.ignoreFailedDrops = ignoreFailedDrops; } + /** * {@inheritDoc} * @see #execute(DataSource) @@ -227,10 +233,10 @@ public class ResourceDatabasePopulator implements DatabasePopulator { @Override public void populate(Connection connection) throws ScriptException { Assert.notNull(connection, "Connection must not be null"); - for (Resource script : getScripts()) { - ScriptUtils.executeSqlScript(connection, encodeScript(script), this.continueOnError, - this.ignoreFailedDrops, this.commentPrefix, this.separator, this.blockCommentStartDelimiter, - this.blockCommentEndDelimiter); + for (Resource script : this.scripts) { + EncodedResource encodedScript = new EncodedResource(script, this.sqlScriptEncoding); + ScriptUtils.executeSqlScript(connection, encodedScript, this.continueOnError, this.ignoreFailedDrops, + this.commentPrefix, this.separator, this.blockCommentStartDelimiter, this.blockCommentEndDelimiter); } } @@ -244,28 +250,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator { * @see #populate(Connection) */ public void execute(DataSource dataSource) throws ScriptException { - Assert.notNull(dataSource, "DataSource must not be null"); DatabasePopulatorUtils.execute(this, dataSource); } - final List getScripts() { - return this.scripts; - } - - /** - * {@link EncodedResource} is not a sub-type of {@link Resource}. Thus we - * always need to wrap each script resource in an {@code EncodedResource} - * using the configured {@linkplain #setSqlScriptEncoding encoding}. - * @param script the script to wrap (never {@code null}) - */ - private EncodedResource encodeScript(Resource script) { - Assert.notNull(script, "Script must not be null"); - return new EncodedResource(script, this.sqlScriptEncoding); - } - - private void assertContentsOfScriptArray(Resource... scripts) { - Assert.notNull(scripts, "Scripts must not be null"); - Assert.noNullElements(scripts, "Scripts array must not contain null elements"); - } - } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorTests.java index 0dcaf48283..50a84f9677 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -50,22 +50,22 @@ public class ResourceDatabasePopulatorTests { @Test public void constructWithResource() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1); - assertEquals(1, databasePopulator.getScripts().size()); + assertEquals(1, databasePopulator.scripts.size()); } @Test public void constructWithMultipleResources() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2); - assertEquals(2, databasePopulator.getScripts().size()); + assertEquals(2, databasePopulator.scripts.size()); } @Test public void constructWithMultipleResourcesAndThenAddScript() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2); - assertEquals(2, databasePopulator.getScripts().size()); + assertEquals(2, databasePopulator.scripts.size()); databasePopulator.addScript(script3); - assertEquals(3, databasePopulator.getScripts().size()); + assertEquals(3, databasePopulator.scripts.size()); } @Test(expected = IllegalArgumentException.class) @@ -95,13 +95,13 @@ public class ResourceDatabasePopulatorTests { @Test public void setScriptsAndThenAddScript() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); - assertEquals(0, databasePopulator.getScripts().size()); + assertEquals(0, databasePopulator.scripts.size()); databasePopulator.setScripts(script1, script2); - assertEquals(2, databasePopulator.getScripts().size()); + assertEquals(2, databasePopulator.scripts.size()); databasePopulator.addScript(script3); - assertEquals(3, databasePopulator.getScripts().size()); + assertEquals(3, databasePopulator.scripts.size()); } } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/MessageChannel.java b/spring-messaging/src/main/java/org/springframework/messaging/MessageChannel.java index f64ff0bf49..d871290019 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/MessageChannel.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/MessageChannel.java @@ -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. @@ -27,7 +27,7 @@ public interface MessageChannel { /** * Constant for sending a message without a prescribed timeout. */ - public static final long INDEFINITE_TIMEOUT = -1; + long INDEFINITE_TIMEOUT = -1; /** diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java index 8e016f2533..cdff08625c 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java @@ -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. @@ -19,10 +19,11 @@ package org.springframework.transaction.interceptor; import org.springframework.transaction.support.DefaultTransactionDefinition; /** - * Transaction attribute that takes the EJB approach to rolling - * back on runtime, but not checked, exceptions. + * Spring's common transaction attribute implementation. + * Rolls back on runtime, but not checked, exceptions by default. * * @author Rod Johnson + * @author Juergen Hoeller * @since 16.03.2003 */ @SuppressWarnings("serial") @@ -57,7 +58,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im } /** - * Create a new DefaultTransactionAttribute with the the given + * Create a new DefaultTransactionAttribute with the given * propagation behavior. Can be modified through bean property setters. * @param propagationBehavior one of the propagation constants in the * TransactionDefinition interface @@ -74,6 +75,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im * Associate a qualifier value with this transaction attribute. *

This may be used for choosing a corresponding transaction manager * to process this specific transaction. + * @since 3.0 */ public void setQualifier(String qualifier) { this.qualifier = qualifier; @@ -81,6 +83,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im /** * Return a qualifier value associated with this transaction attribute. + * @since 3.0 */ @Override public String getQualifier() {