From aa89a579530b5a519d26e54829e8ffc2f8b4115c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 27 Feb 2019 17:57:21 +0100 Subject: [PATCH] Polishing --- .../AutowiredAnnotationBeanPostProcessor.java | 2 +- .../factory/config/BeanExpressionContext.java | 4 +-- .../PreferencesPlaceholderConfigurer.java | 4 +-- .../config/PropertyOverrideConfigurer.java | 9 ++++--- .../AbstractAutowireCapableBeanFactory.java | 8 +++--- .../support/DefaultListableBeanFactory.java | 2 +- .../PropertiesBeanDefinitionReader.java | 26 +++++++++---------- .../support/SimpleInstantiationStrategy.java | 4 +-- .../support/StaticListableBeanFactory.java | 2 +- .../factory/xml/PluggableSchemaResolver.java | 8 +++--- .../SimpleConstructorNamespaceHandler.java | 6 ++--- .../core/AttributeAccessor.java | 4 +-- .../org/springframework/util/ClassUtils.java | 4 +-- .../util/UpdateMessageDigestInputStream.java | 6 ++--- 14 files changed, 46 insertions(+), 43 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index 2ec5eb4dc8..78446b714f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -695,7 +695,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean ReflectionUtils.makeAccessible(method); method.invoke(bean, arguments); } - catch (InvocationTargetException ex){ + catch (InvocationTargetException ex) { throw ex.getTargetException(); } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java index 3e0b4000bb..d3cadc3726 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -59,7 +59,7 @@ public class BeanExpressionContext { if (this.beanFactory.containsBean(key)) { return this.beanFactory.getBean(key); } - else if (this.scope != null){ + else if (this.scope != null) { return this.scope.resolveContextualObject(key); } else { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java index bfdaea4810..5d760a50de 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -121,7 +121,7 @@ public class PreferencesPlaceholderConfigurer extends PropertyPlaceholderConfigu @Nullable protected String resolvePlaceholder(@Nullable String path, String key, Preferences preferences) { if (path != null) { - // Do not create the node if it does not exist... + // Do not create the node if it does not exist... try { if (preferences.nodeExists(path)) { return preferences.node(path).get(key, null); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java index f89593c522..e94b0b0839 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -64,6 +64,9 @@ import org.springframework.beans.factory.BeanInitializationException; */ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer { + /** + * The default bean name separator. + */ public static final String DEFAULT_BEAN_NAME_SEPARATOR = "."; @@ -72,7 +75,7 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer { private boolean ignoreInvalidKeys = false; /** - * Contains names of beans that have overrides + * Contains names of beans that have overrides. */ private final Set beanNames = Collections.newSetFromMap(new ConcurrentHashMap<>(16)); @@ -129,7 +132,7 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer { "': expected 'beanName" + this.beanNameSeparator + "property'"); } String beanName = key.substring(0, separatorIndex); - String beanProperty = key.substring(separatorIndex+1); + String beanProperty = key.substring(separatorIndex + 1); this.beanNames.add(beanName); applyPropertyValue(factory, beanName, beanProperty, value); if (logger.isDebugEnabled()) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index da878cccfb..7b4e1820ce 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -971,7 +971,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac return null; } - Object instance = null; + Object instance; try { // Mark this bean as currently in creation, even if just partially. beforePrototypeCreation(beanName); @@ -1092,7 +1092,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac return obtainFromSupplier(instanceSupplier, beanName); } - if (mbd.getFactoryMethodName() != null) { + if (mbd.getFactoryMethodName() != null) { return instantiateUsingFactoryMethod(beanName, mbd, args); } @@ -1119,7 +1119,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac // Candidate constructors for autowiring? Constructor[] ctors = determineConstructorsFromBeanPostProcessors(beanClass, beanName); if (ctors != null || mbd.getResolvedAutowireMode() == AUTOWIRE_CONSTRUCTOR || - mbd.hasConstructorArgumentValues() || !ObjectUtils.isEmpty(args)) { + mbd.hasConstructorArgumentValues() || !ObjectUtils.isEmpty(args)) { return autowireConstructor(beanName, mbd, ctors, args); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index f9d1ae61a6..17f3961b95 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -572,7 +572,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @Override @Nullable public A findAnnotationOnBean(String beanName, Class annotationType) - throws NoSuchBeanDefinitionException{ + throws NoSuchBeanDefinitionException { A ann = null; Class beanType = getType(beanName); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java index ddc3353c7e..ab5f955588 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java @@ -89,7 +89,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader public static final String SEPARATOR = "."; /** - * Special key to distinguish {@code owner.(class)=com.myapp.MyClass}- + * Special key to distinguish {@code owner.(class)=com.myapp.MyClass}. */ public static final String CLASS_KEY = "(class)"; @@ -299,10 +299,10 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader /** - * Register bean definitions contained in a Map, - * using all property keys (i.e. not filtering by prefix). - * @param map Map: name -> property (String or Object). Property values - * will be strings if coming from a Properties file etc. Property names + * Register bean definitions contained in a Map, using all property keys (i.e. not + * filtering by prefix). + * @param map a map of {@code name} to {@code property} (String or Object). Property + * values will be strings if coming from a Properties file etc. Property names * (keys) must be Strings. Class keys must be Strings. * @return the number of bean definitions found * @throws BeansException in case of loading or parsing errors @@ -315,8 +315,8 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader /** * Register bean definitions contained in a Map. * Ignore ineligible properties. - * @param map Map name -> property (String or Object). Property values - * will be strings if coming from a Properties file etc. Property names + * @param map a map of {@code name} to {@code property} (String or Object). Property + * values will be strings if coming from a Properties file etc. Property names * (keys) must be Strings. Class keys must be Strings. * @param prefix a filter within the keys in the map: e.g. 'beans.' * (can be empty or {@code null}) @@ -330,9 +330,9 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader /** * Register bean definitions contained in a Map. * Ignore ineligible properties. - * @param map Map name -> property (String or Object). Property values - * will be strings if coming from a Properties file etc. Property names - * (keys) must be strings. Class keys must be Strings. + * @param map a map of {@code name} to {@code property} (String or Object). Property + * values will be strings if coming from a Properties file etc. Property names + * (keys) must be Strings. Class keys must be Strings. * @param prefix a filter within the keys in the map: e.g. 'beans.' * (can be empty or {@code null}) * @param resourceDescription description of the resource that the @@ -392,9 +392,9 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader /** * Get all property values, given a prefix (which will be stripped) - * and add the bean they define to the factory with the given name + * and add the bean they define to the factory with the given name. * @param beanName name of the bean to define - * @param map Map containing string pairs + * @param map a Map containing string pairs * @param prefix prefix of each entry, which will be stripped * @param resourceDescription description of the resource that the * Map came from (for logging purposes) @@ -501,7 +501,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader * Reads the value of the entry. Correctly interprets bean references for * values that are prefixed with an asterisk. */ - private Object readValue(Map.Entry entry) { + private Object readValue(Map.Entry entry) { Object val = entry.getValue(); if (val instanceof String) { String strVal = (String) val; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java index 42449980d3..aef93bfcf7 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -75,7 +75,7 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy { (PrivilegedExceptionAction>) clazz::getDeclaredConstructor); } else { - constructorToUse = clazz.getDeclaredConstructor(); + constructorToUse = clazz.getDeclaredConstructor(); } bd.resolvedConstructorOrFactoryMethod = constructorToUse; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java index 193f190cb3..7714663e4a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java @@ -357,7 +357,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory { @Override @Nullable public A findAnnotationOnBean(String beanName, Class annotationType) - throws NoSuchBeanDefinitionException{ + throws NoSuchBeanDefinitionException { Class beanType = getType(beanName); return (beanType != null ? AnnotationUtils.findAnnotation(beanType, annotationType) : null); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java index 0fa2b834c3..4b7c3c2490 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java @@ -44,12 +44,12 @@ import org.springframework.util.CollectionUtils; * *

The format of {@code META-INF/spring.schemas} is a properties file where each line * should be of the form {@code systemId=schema-location} where {@code schema-location} - * should also be a schema file in the classpath. Since systemId is commonly a URL, - * one must be careful to escape any ':' characters which are treated as delimiters + * should also be a schema file in the classpath. Since {@code systemId} is commonly a + * URL, one must be careful to escape any ':' characters which are treated as delimiters * in properties files. * - *

The pattern for the mapping files can be overidden using the - * {@link #PluggableSchemaResolver(ClassLoader, String)} constructor + *

The pattern for the mapping files can be overridden using the + * {@link #PluggableSchemaResolver(ClassLoader, String)} constructor. * * @author Rob Harrop * @author Juergen Hoeller diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java index da1f062dbe..138cdef5cd 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -118,7 +118,7 @@ public class SimpleConstructorNamespaceHandler implements NamespaceHandler { "Constructor argument '" + argName + "' specifies a negative index", attr); } - if (cvs.hasIndexedArgumentValue(index)){ + if (cvs.hasIndexedArgumentValue(index)) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' with index "+ index+" already defined using ." + " Only one approach may be used per argument.", attr); @@ -130,7 +130,7 @@ public class SimpleConstructorNamespaceHandler implements NamespaceHandler { // no escaping -> ctr name else { String name = Conventions.attributeNameToPropertyName(argName); - if (containsArgWithName(name, cvs)){ + if (containsArgWithName(name, cvs)) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' already defined using ." + " Only one approach may be used per argument.", attr); diff --git a/spring-core/src/main/java/org/springframework/core/AttributeAccessor.java b/spring-core/src/main/java/org/springframework/core/AttributeAccessor.java index 9d407f708f..440ae47f02 100644 --- a/spring-core/src/main/java/org/springframework/core/AttributeAccessor.java +++ b/spring-core/src/main/java/org/springframework/core/AttributeAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2018 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.lang.Nullable; public interface AttributeAccessor { /** - * Set the attribute defined by {@code name} to the supplied {@code value}. + * Set the attribute defined by {@code name} to the supplied {@code value}. * If {@code value} is {@code null}, the attribute is {@link #removeAttribute removed}. *

In general, users should take care to prevent overlaps with other * metadata attributes by using fully-qualified names, perhaps using diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index c2ddc7ab16..06af4d9f5f 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -759,9 +759,9 @@ public abstract class ClassUtils { * conflicting method signatures (or a similar constraint is violated) * @see java.lang.reflect.Proxy#getProxyClass */ - @SuppressWarnings("deprecation") + @SuppressWarnings("deprecation") // on JDK 9 public static Class createCompositeInterface(Class[] interfaces, @Nullable ClassLoader classLoader) { - Assert.notEmpty(interfaces, "Interfaces must not be empty"); + Assert.notEmpty(interfaces, "Interface array must not be empty"); return Proxy.getProxyClass(classLoader, interfaces); } diff --git a/spring-core/src/main/java/org/springframework/util/UpdateMessageDigestInputStream.java b/spring-core/src/main/java/org/springframework/util/UpdateMessageDigestInputStream.java index 90bfa4a7e8..875e51bfb3 100644 --- a/spring-core/src/main/java/org/springframework/util/UpdateMessageDigestInputStream.java +++ b/spring-core/src/main/java/org/springframework/util/UpdateMessageDigestInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -38,7 +38,7 @@ abstract class UpdateMessageDigestInputStream extends InputStream { */ public void updateMessageDigest(MessageDigest messageDigest) throws IOException { int data; - while ((data = read()) != -1){ + while ((data = read()) != -1) { messageDigest.update((byte) data); } } @@ -54,7 +54,7 @@ abstract class UpdateMessageDigestInputStream extends InputStream { public void updateMessageDigest(MessageDigest messageDigest, int len) throws IOException { int data; int bytesRead = 0; - while (bytesRead < len && (data = read()) != -1){ + while (bytesRead < len && (data = read()) != -1) { messageDigest.update((byte) data); bytesRead++; }