diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java index 7cb8fd1875c..e97652c5650 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.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. @@ -156,7 +156,7 @@ class ConstructorResolver { catch (Throwable ex) { throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Resolution of declared constructors on bean Class [" + beanClass.getName() + - "] from ClassLoader [" + beanClass.getClassLoader() + "] failed", ex); + "] from ClassLoader [" + beanClass.getClassLoader() + "] failed", ex); } } AutowireUtils.sortConstructors(candidates); @@ -613,8 +613,8 @@ class ConstructorResolver { String beanName, RootBeanDefinition mbd, BeanWrapper bw, ConstructorArgumentValues cargs, ConstructorArgumentValues resolvedValues) { - TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ? - this.beanFactory.getCustomTypeConverter() : bw); + TypeConverter customConverter = this.beanFactory.getCustomTypeConverter(); + TypeConverter converter = (customConverter != null ? customConverter : bw); BeanDefinitionValueResolver valueResolver = new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter); @@ -670,8 +670,8 @@ class ConstructorResolver { boolean autowiring) throws UnsatisfiedDependencyException { String methodType = (methodOrCtor instanceof Constructor ? "constructor" : "factory method"); - TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ? - this.beanFactory.getCustomTypeConverter() : bw); + TypeConverter customConverter = this.beanFactory.getCustomTypeConverter(); + TypeConverter converter = (customConverter != null ? customConverter : bw); ArgumentsHolder args = new ArgumentsHolder(paramTypes.length); Set usedValueHolders = @@ -772,12 +772,13 @@ class ConstructorResolver { private Object[] resolvePreparedArguments( String beanName, RootBeanDefinition mbd, BeanWrapper bw, Member methodOrCtor, Object[] argsToResolve) { - Class[] paramTypes = (methodOrCtor instanceof Method ? - ((Method) methodOrCtor).getParameterTypes() : ((Constructor) methodOrCtor).getParameterTypes()); - TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ? - this.beanFactory.getCustomTypeConverter() : bw); + TypeConverter customConverter = this.beanFactory.getCustomTypeConverter(); + TypeConverter converter = (customConverter != null ? customConverter : bw); BeanDefinitionValueResolver valueResolver = new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter); + Class[] paramTypes = (methodOrCtor instanceof Method ? + ((Method) methodOrCtor).getParameterTypes() : ((Constructor) methodOrCtor).getParameterTypes()); + Object[] resolvedArgs = new Object[argsToResolve.length]; for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) { Object argValue = argsToResolve[argIndex]; diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java index c4467ab58ac..30f5da7638b 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.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. @@ -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(Arrays.asList(methodNames)); } @@ -85,7 +85,7 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean */ public void setMethodMappings(Properties mappings) { this.methodMappings = new HashMap>(); - for (Enumeration en = mappings.keys(); en.hasMoreElements();) { + for (Enumeration en = mappings.keys(); en.hasMoreElements();) { String beanKey = (String) en.nextElement(); String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey)); this.methodMappings.put(beanKey, new HashSet(Arrays.asList(methodNames))); diff --git a/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerMappedTests.java b/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerMappedTests.java index 10b1985515b..9b8ec774e06 100644 --- a/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerMappedTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerMappedTests.java @@ -1,23 +1,22 @@ /* - * 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. You may obtain a copy of - * the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.springframework.jmx.export.assembler; import java.util.Properties; - import javax.management.MBeanAttributeInfo; import javax.management.modelmbean.ModelMBeanAttributeInfo; import javax.management.modelmbean.ModelMBeanInfo; @@ -34,6 +33,7 @@ public class MethodNameBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAss protected static final String OBJECT_NAME = "bean:name=testBean4"; + @Test public void testGetAgeIsReadOnly() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); @@ -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"); diff --git a/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerTests.java b/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerTests.java index d85f42b508e..dae9a8a3672 100644 --- a/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerTests.java @@ -1,17 +1,17 @@ /* - * 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. You may obtain a copy of - * the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.springframework.jmx.export.assembler; @@ -33,6 +33,7 @@ public class MethodNameBasedMBeanInfoAssemblerTests extends AbstractJmxAssembler protected static final String OBJECT_NAME = "bean:name=testBean5"; + @Override protected String getObjectName() { return OBJECT_NAME; @@ -51,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; } diff --git a/spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java b/spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java index 4d48b0449d4..70a0a87c88d 100644 --- a/spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java +++ b/spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.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. @@ -21,7 +21,6 @@ import java.io.InputStream; import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectStreamClass; -import java.lang.reflect.Proxy; import org.springframework.util.ClassUtils; @@ -68,7 +67,7 @@ public class ConfigurableObjectInputStream extends ObjectInputStream { @Override - protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException { + protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException { try { if (this.classLoader != null) { // Use the specified ClassLoader to resolve local classes. @@ -85,13 +84,13 @@ public class ConfigurableObjectInputStream extends ObjectInputStream { } @Override - protected Class resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { + protected Class resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { if (!this.acceptProxyClasses) { throw new NotSerializableException("Not allowed to accept serialized proxy classes"); } if (this.classLoader != null) { // Use the specified ClassLoader to resolve local proxy classes. - Class[] resolvedInterfaces = new Class[interfaces.length]; + Class[] resolvedInterfaces = new Class[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { try { resolvedInterfaces[i] = ClassUtils.forName(interfaces[i], this.classLoader); @@ -101,7 +100,7 @@ public class ConfigurableObjectInputStream extends ObjectInputStream { } } try { - return Proxy.getProxyClass(this.classLoader, resolvedInterfaces); + return ClassUtils.createCompositeInterface(resolvedInterfaces, this.classLoader); } catch (IllegalArgumentException ex) { throw new ClassNotFoundException(null, ex); @@ -113,11 +112,11 @@ public class ConfigurableObjectInputStream extends ObjectInputStream { return super.resolveProxyClass(interfaces); } catch (ClassNotFoundException ex) { - Class[] resolvedInterfaces = new Class[interfaces.length]; + Class[] resolvedInterfaces = new Class[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { resolvedInterfaces[i] = resolveFallbackIfPossible(interfaces[i], ex); } - return Proxy.getProxyClass(getFallbackClassLoader(), resolvedInterfaces); + return ClassUtils.createCompositeInterface(resolvedInterfaces, getFallbackClassLoader()); } } } @@ -131,7 +130,7 @@ public class ConfigurableObjectInputStream extends ObjectInputStream { * @param ex the original exception thrown when attempting to load the class * @return the newly resolved class (never {@code null}) */ - protected Class resolveFallbackIfPossible(String className, ClassNotFoundException ex) + protected Class resolveFallbackIfPossible(String className, ClassNotFoundException ex) throws IOException, ClassNotFoundException{ throw ex; @@ -139,8 +138,9 @@ public class ConfigurableObjectInputStream extends ObjectInputStream { /** * Return the fallback ClassLoader to use when no ClassLoader was specified - * and ObjectInputStream's own default ClassLoader failed. - *

The default implementation simply returns {@code null}. + * and ObjectInputStream's own default class loader failed. + *

The default implementation simply returns {@code null}, indicating + * that no specific fallback is available. */ protected ClassLoader getFallbackClassLoader() throws IOException { return null; diff --git a/spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java b/spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java index c58ea9aba43..450e59703c2 100644 --- a/spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.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. @@ -72,7 +72,7 @@ public abstract class AbstractFileResolvingResource extends AbstractResource { } /** - * This implementation returns a File reference for the underlying class path + * This implementation returns a File reference for the given URI-identified * resource, provided that it refers to a file in the file system. * @see org.springframework.util.ResourceUtils#getFile(java.net.URI, String) */ diff --git a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java index 05202a3b096..d2e8f740d4b 100644 --- a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.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. @@ -30,7 +30,7 @@ import org.springframework.util.StringUtils; /** * {@link Resource} implementation for {@code java.io.File} handles. - * Obviously supports resolution as File, and also as URL. + * Supports resolution as a {@code File} and also as a {@code URL}. * Implements the extended {@link WritableResource} interface. * * @author Juergen Hoeller @@ -85,7 +85,6 @@ public class FileSystemResource extends AbstractResource implements WritableReso return this.path; } - /** * This implementation returns whether the underlying file exists. * @see java.io.File#exists() diff --git a/spring-core/src/main/java/org/springframework/core/io/Resource.java b/spring-core/src/main/java/org/springframework/core/io/Resource.java index cc6eef308f7..27bf514260b 100644 --- a/spring-core/src/main/java/org/springframework/core/io/Resource.java +++ b/spring-core/src/main/java/org/springframework/core/io/Resource.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. @@ -37,25 +37,25 @@ import java.net.URL; * @see #getFile() * @see WritableResource * @see ContextResource - * @see FileSystemResource - * @see ClassPathResource * @see UrlResource + * @see ClassPathResource + * @see FileSystemResource * @see ByteArrayResource * @see InputStreamResource */ public interface Resource extends InputStreamSource { /** - * Return whether this resource actually exists in physical form. + * Determine whether this resource actually exists in physical form. *

This method performs a definitive existence check, whereas the - * existence of a {@code Resource} handle only guarantees a - * valid descriptor handle. + * existence of a {@code Resource} handle only guarantees a valid + * descriptor handle. */ boolean exists(); /** - * Return whether the contents of this resource can be read, - * e.g. via {@link #getInputStream()} or {@link #getFile()}. + * Indicate whether the contents of this resource can be read via + * {@link #getInputStream()}. *

Will be {@code true} for typical resource descriptors; * note that actual content reading may still fail when attempted. * However, a value of {@code false} is a definitive indication @@ -65,8 +65,8 @@ public interface Resource extends InputStreamSource { boolean isReadable(); /** - * Return whether this resource represents a handle with an open - * stream. If true, the InputStream cannot be read multiple times, + * Indicate whether this resource represents a handle with an open stream. + * If {@code true}, the InputStream cannot be read multiple times, * and must be read and closed to avoid resource leaks. *

Will be {@code false} for typical resource descriptors. */ @@ -83,6 +83,7 @@ public interface Resource extends InputStreamSource { * Return a URI handle for this resource. * @throws IOException if the resource cannot be resolved as URI, * i.e. if the resource is not available as descriptor + * @since 2.5 */ URI getURI() throws IOException; diff --git a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java index 626f8f70adc..84a07396d3f 100644 --- a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/UrlResource.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. @@ -32,8 +32,8 @@ import org.springframework.util.StringUtils; /** * {@link Resource} implementation for {@code java.net.URL} locators. - * Obviously supports resolution as URL, and also as File in case of - * the "file:" protocol. + * Supports resolution as a {@code URL} and also as a {@code File} in + * case of the {@code "file:"} protocol. * * @author Juergen Hoeller * @since 28.12.2003 @@ -58,9 +58,10 @@ public class UrlResource extends AbstractFileResolvingResource { /** - * Create a new UrlResource based on the given URI object. + * Create a new {@code UrlResource} based on the given URI object. * @param uri a URI * @throws MalformedURLException if the given URL path is not valid + * @since 2.5 */ public UrlResource(URI uri) throws MalformedURLException { Assert.notNull(uri, "URI must not be null"); @@ -70,7 +71,7 @@ public class UrlResource extends AbstractFileResolvingResource { } /** - * Create a new UrlResource based on the given URL object. + * Create a new {@code UrlResource} based on the given URL object. * @param url a URL */ public UrlResource(URL url) { @@ -81,7 +82,7 @@ public class UrlResource extends AbstractFileResolvingResource { } /** - * Create a new UrlResource based on a URL path. + * Create a new {@code UrlResource} based on a URL path. *

Note: The given path needs to be pre-encoded if necessary. * @param path a URL path * @throws MalformedURLException if the given URL path is not valid @@ -95,7 +96,7 @@ public class UrlResource extends AbstractFileResolvingResource { } /** - * Create a new UrlResource based on a URI specification. + * Create a new {@code UrlResource} based on a URI specification. *

The given parts will automatically get encoded if necessary. * @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon); * also known as "scheme" @@ -109,7 +110,7 @@ public class UrlResource extends AbstractFileResolvingResource { } /** - * Create a new UrlResource based on a URI specification. + * Create a new {@code UrlResource} based on a URI specification. *

The given parts will automatically get encoded if necessary. * @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon); * also known as "scheme" @@ -133,6 +134,7 @@ public class UrlResource extends AbstractFileResolvingResource { } } + /** * Determine a cleaned URL for the given original URL. * @param originalUrl the original URL @@ -151,10 +153,9 @@ public class UrlResource extends AbstractFileResolvingResource { } } - /** * This implementation opens an InputStream for the given URL. - * It sets the "UseCaches" flag to {@code false}, + *

It sets the {@code useCaches} flag to {@code false}, * mainly to avoid jar file locking on Windows. * @see java.net.URL#openConnection() * @see java.net.URLConnection#setUseCaches(boolean) @@ -213,7 +214,7 @@ public class UrlResource extends AbstractFileResolvingResource { } /** - * This implementation creates a UrlResource, applying the given path + * This implementation creates a {@code UrlResource}, applying the given path * relative to the path of the underlying URL of this resource descriptor. * @see java.net.URL#URL(java.net.URL, String) */ 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 080611e89a1..952023304e5 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.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. @@ -55,13 +55,16 @@ public abstract class ClassUtils { /** Prefix for internal non-primitive array class names: "[L" */ private static final String NON_PRIMITIVE_ARRAY_PREFIX = "[L"; - /** The package separator character '.' */ + /** The package separator character: '.' */ private static final char PACKAGE_SEPARATOR = '.'; - /** The inner class separator character '$' */ + /** The path separator character: '/' */ + private static final char PATH_SEPARATOR = '/'; + + /** The inner class separator character: '$' */ private static final char INNER_CLASS_SEPARATOR = '$'; - /** The CGLIB class separator character "$$" */ + /** The CGLIB class separator: "$$" */ public static final String CGLIB_CLASS_SEPARATOR = "$$"; /** The ".class" file suffix */ @@ -265,9 +268,10 @@ public abstract class ClassUtils { return (clToUse != null ? clToUse.loadClass(name) : Class.forName(name)); } catch (ClassNotFoundException ex) { - int lastDotIndex = name.lastIndexOf('.'); + int lastDotIndex = name.lastIndexOf(PACKAGE_SEPARATOR); if (lastDotIndex != -1) { - String innerClassName = name.substring(0, lastDotIndex) + '$' + name.substring(lastDotIndex + 1); + String innerClassName = + name.substring(0, lastDotIndex) + INNER_CLASS_SEPARATOR + name.substring(lastDotIndex + 1); try { return (clToUse != null ? clToUse.loadClass(innerClassName) : Class.forName(innerClassName)); } @@ -455,8 +459,8 @@ public abstract class ClassUtils { * @see java.beans.Introspector#decapitalize(String) */ public static String getShortNameAsProperty(Class clazz) { - String shortName = ClassUtils.getShortName(clazz); - int dotIndex = shortName.lastIndexOf('.'); + String shortName = getShortName(clazz); + int dotIndex = shortName.lastIndexOf(PACKAGE_SEPARATOR); shortName = (dotIndex != -1 ? shortName.substring(dotIndex + 1) : shortName); return Introspector.decapitalize(shortName); } @@ -525,7 +529,7 @@ public abstract class ClassUtils { StringBuilder result = new StringBuilder(); while (clazz.isArray()) { clazz = clazz.getComponentType(); - result.append(ClassUtils.ARRAY_SUFFIX); + result.append(ARRAY_SUFFIX); } result.insert(0, clazz.getName()); return result.toString(); @@ -955,7 +959,7 @@ public abstract class ClassUtils { */ public static String convertResourcePathToClassName(String resourcePath) { Assert.notNull(resourcePath, "Resource path must not be null"); - return resourcePath.replace('/', '.'); + return resourcePath.replace(PATH_SEPARATOR, PACKAGE_SEPARATOR); } /** @@ -965,7 +969,7 @@ public abstract class ClassUtils { */ public static String convertClassNameToResourcePath(String className) { Assert.notNull(className, "Class name must not be null"); - return className.replace('.', '/'); + return className.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR); } /** @@ -1011,12 +1015,12 @@ public abstract class ClassUtils { return ""; } String className = clazz.getName(); - int packageEndIndex = className.lastIndexOf('.'); + int packageEndIndex = className.lastIndexOf(PACKAGE_SEPARATOR); if (packageEndIndex == -1) { return ""; } String packageName = className.substring(0, packageEndIndex); - return packageName.replace('.', '/'); + return packageName.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR); } /** @@ -1165,7 +1169,6 @@ public abstract class ClassUtils { */ public static Class createCompositeInterface(Class[] interfaces, ClassLoader classLoader) { Assert.notEmpty(interfaces, "Interfaces must not be empty"); - Assert.notNull(classLoader, "ClassLoader must not be null"); return Proxy.getProxyClass(classLoader, interfaces); } @@ -1229,7 +1232,7 @@ public abstract class ClassUtils { * @see org.springframework.aop.support.AopUtils#isCglibProxy(Object) */ public static boolean isCglibProxy(Object object) { - return ClassUtils.isCglibProxyClass(object.getClass()); + return isCglibProxyClass(object.getClass()); } /** diff --git a/spring-core/src/main/java/org/springframework/util/ResourceUtils.java b/spring-core/src/main/java/org/springframework/util/ResourceUtils.java index ce552eb0bce..14796313205 100644 --- a/spring-core/src/main/java/org/springframework/util/ResourceUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ResourceUtils.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. @@ -126,8 +126,8 @@ public abstract class ResourceUtils { URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path)); if (url == null) { String description = "class path resource [" + path + "]"; - throw new FileNotFoundException( - description + " cannot be resolved to URL because it does not exist"); + throw new FileNotFoundException(description + + " cannot be resolved to URL because it does not exist"); } return url; } @@ -166,9 +166,8 @@ public abstract class ResourceUtils { ClassLoader cl = ClassUtils.getDefaultClassLoader(); URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path)); if (url == null) { - throw new FileNotFoundException( - description + " cannot be resolved to absolute file path " + - "because it does not reside in the file system"); + throw new FileNotFoundException(description + + " cannot be resolved to absolute file path because it does not exist"); } return getFile(url, description); } @@ -227,6 +226,7 @@ public abstract class ResourceUtils { * @return a corresponding File object * @throws FileNotFoundException if the URL cannot be resolved to * a file in the file system + * @since 2.5 */ public static File getFile(URI resourceUri) throws FileNotFoundException { return getFile(resourceUri, "URI"); @@ -241,6 +241,7 @@ public abstract class ResourceUtils { * @return a corresponding File object * @throws FileNotFoundException if the URL cannot be resolved to * a file in the file system + * @since 2.5 */ public static File getFile(URI resourceUri, String description) throws FileNotFoundException { Assert.notNull(resourceUri, "Resource URI must not be null"); diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java index 00bf054a66d..fc5093dd607 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java @@ -74,10 +74,10 @@ public class CollectionToCollectionConverterTests { conversionService.addConverterFactory(new StringToNumberConverterFactory()); assertTrue(conversionService.canConvert(sourceType, targetType)); @SuppressWarnings("unchecked") - List result = (List) conversionService.convert(list, sourceType, targetType); + List result = (List) conversionService.convert(list, sourceType, targetType); assertFalse(list.equals(result)); - assertEquals(9, result.get(0)); - assertEquals(37, result.get(1)); + assertEquals(9, result.get(0).intValue()); + assertEquals(37, result.get(1).intValue()); } @Test @@ -199,7 +199,7 @@ public class CollectionToCollectionConverterTests { public void listToCollectionNoCopyRequired() throws NoSuchFieldException { List input = new ArrayList(Arrays.asList("foo", "bar")); assertSame(input, conversionService.convert(input, TypeDescriptor.forObject(input), - new TypeDescriptor(getClass().getField("wildCardCollection")))); + new TypeDescriptor(getClass().getField("wildcardCollection")))); } @Test @@ -232,7 +232,7 @@ public class CollectionToCollectionConverterTests { assertSame(resources, conversionService.convert(resources, sourceType, new TypeDescriptor(getClass().getField("resources")))); } - @Test(expected=ConverterNotFoundException.class) + @Test(expected = ConverterNotFoundException.class) public void elementTypesNotConvertible() throws Exception { List resources = new ArrayList(); resources.add(null); @@ -241,7 +241,7 @@ public class CollectionToCollectionConverterTests { assertEquals(resources, conversionService.convert(resources, sourceType, new TypeDescriptor(getClass().getField("resources")))); } - @Test(expected=ConversionFailedException.class) + @Test(expected = ConversionFailedException.class) public void nothingInCommon() throws Exception { List resources = new ArrayList(); resources.add(new ClassPathResource("test")); @@ -261,9 +261,9 @@ public class CollectionToCollectionConverterTests { public List strings; - public List list = Collections.emptyList(); + public List list = Collections.emptyList(); - public Collection wildCardCollection = Collections.emptyList(); + public Collection wildcardCollection = Collections.emptyList(); public List resources; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java index 69b9ee716ca..b88a22b1b59 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.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. @@ -37,6 +37,7 @@ import org.springframework.dao.DataRetrievalFailureException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.support.JdbcUtils; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; /** @@ -56,14 +57,14 @@ import org.springframework.util.StringUtils; *

To facilitate mapping between columns and fields that don't have matching names, * try using column aliases in the SQL statement like "select fname as first_name from customer". * - *

For 'null' values read from the databasem, we will attempt to call the setter, but in the case of + *

For 'null' values read from the database, we will attempt to call the setter, but in the case of * Java primitives, this causes a TypeMismatchException. This class can be configured (using the * primitivesDefaultedForNullValue property) to trap this exception and use the primitives default value. * Be aware that if you use the values from the generated bean to update the database the primitive value * will have been set to the primitive's default value instead of null. * *

Please note that this class is designed to provide convenience rather than high performance. - * For best performance consider using a custom RowMapper. + * For best performance, consider using a custom {@link RowMapper} implementation. * * @author Thomas Risberg * @author Juergen Hoeller @@ -91,7 +92,7 @@ public class BeanPropertyRowMapper implements RowMapper { /** - * Create a new BeanPropertyRowMapper for bean-style configuration. + * Create a new {@code BeanPropertyRowMapper} for bean-style configuration. * @see #setMappedClass * @see #setCheckFullyPopulated */ @@ -99,8 +100,8 @@ public class BeanPropertyRowMapper implements RowMapper { } /** - * Create a new BeanPropertyRowMapper, accepting unpopulated properties - * in the target bean. + * Create a new {@code BeanPropertyRowMapper}, accepting unpopulated + * properties in the target bean. *

Consider using the {@link #newInstance} factory method instead, * which allows for specifying the mapped type once only. * @param mappedClass the class that each row should be mapped to @@ -110,7 +111,7 @@ public class BeanPropertyRowMapper implements RowMapper { } /** - * Create a new BeanPropertyRowMapper. + * Create a new {@code BeanPropertyRowMapper}. * @param mappedClass the class that each row should be mapped to * @param checkFullyPopulated whether we're strictly validating that * all bean properties have been mapped from corresponding database fields @@ -136,9 +137,51 @@ public class BeanPropertyRowMapper implements RowMapper { } } + /** + * Get the class that we are mapping to. + */ + public final Class getMappedClass() { + return this.mappedClass; + } + + /** + * Set whether we're strictly validating that all bean properties have been mapped + * from corresponding database fields. + *

Default is {@code false}, accepting unpopulated properties in the target bean. + */ + public void setCheckFullyPopulated(boolean checkFullyPopulated) { + this.checkFullyPopulated = checkFullyPopulated; + } + + /** + * Return whether we're strictly validating that all bean properties have been + * mapped from corresponding database fields. + */ + public boolean isCheckFullyPopulated() { + return this.checkFullyPopulated; + } + + /** + * Set whether we're defaulting Java primitives in the case of mapping a null value + * from corresponding database fields. + *

Default is {@code false}, throwing an exception when nulls are mapped to Java primitives. + */ + public void setPrimitivesDefaultedForNullValue(boolean primitivesDefaultedForNullValue) { + this.primitivesDefaultedForNullValue = primitivesDefaultedForNullValue; + } + + /** + * Return whether we're defaulting Java primitives in the case of mapping a null value + * from corresponding database fields. + */ + public boolean isPrimitivesDefaultedForNullValue() { + return this.primitivesDefaultedForNullValue; + } + + /** * Initialize the mapping metadata for the given class. - * @param mappedClass the mapped class. + * @param mappedClass the mapped class */ protected void initialize(Class mappedClass) { this.mappedClass = mappedClass; @@ -160,7 +203,7 @@ public class BeanPropertyRowMapper implements RowMapper { /** * Convert a name in camelCase to an underscored name in lower case. * Any upper case letters are converted to lower case with a preceding underscore. - * @param name the string containing original name + * @param name the original name * @return the converted name */ private String underscoreName(String name) { @@ -182,48 +225,6 @@ public class BeanPropertyRowMapper implements RowMapper { return result.toString(); } - /** - * Get the class that we are mapping to. - */ - public final Class getMappedClass() { - return this.mappedClass; - } - - /** - * Set whether we're strictly validating that all bean properties have been - * mapped from corresponding database fields. - *

Default is {@code false}, accepting unpopulated properties in the - * target bean. - */ - public void setCheckFullyPopulated(boolean checkFullyPopulated) { - this.checkFullyPopulated = checkFullyPopulated; - } - - /** - * Return whether we're strictly validating that all bean properties have been - * mapped from corresponding database fields. - */ - public boolean isCheckFullyPopulated() { - return this.checkFullyPopulated; - } - - /** - * Set whether we're defaulting Java primitives in the case of mapping a null value - * from corresponding database fields. - *

Default is {@code false}, throwing an exception when nulls are mapped to Java primitives. - */ - public void setPrimitivesDefaultedForNullValue(boolean primitivesDefaultedForNullValue) { - this.primitivesDefaultedForNullValue = primitivesDefaultedForNullValue; - } - - /** - * Return whether we're defaulting Java primitives in the case of mapping a null value - * from corresponding database fields. - */ - public boolean isPrimitivesDefaultedForNullValue() { - return primitivesDefaultedForNullValue; - } - /** * Extract the values for all columns in the current row. @@ -242,26 +243,30 @@ public class BeanPropertyRowMapper implements RowMapper { for (int index = 1; index <= columnCount; index++) { String column = JdbcUtils.lookupColumnName(rsmd, index); - PropertyDescriptor pd = this.mappedFields.get(column.replaceAll(" ", "").toLowerCase()); + String field = column.replaceAll(" ", "").toLowerCase(); + PropertyDescriptor pd = this.mappedFields.get(field); if (pd != null) { try { Object value = getColumnValue(rs, index, pd); - if (logger.isDebugEnabled() && rowNumber == 0) { - logger.debug("Mapping column '" + column + "' to property '" + - pd.getName() + "' of type " + pd.getPropertyType()); + if (rowNumber == 0 && logger.isDebugEnabled()) { + logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + + "' of type [" + ClassUtils.getQualifiedName(pd.getPropertyType()) + "]"); } try { bw.setPropertyValue(pd.getName(), value); } - catch (TypeMismatchException e) { - if (value == null && primitivesDefaultedForNullValue) { - logger.debug("Intercepted TypeMismatchException for row " + rowNumber + - " and column '" + column + "' with value " + value + - " when setting property '" + pd.getName() + "' of type " + pd.getPropertyType() + - " on object: " + mappedObject); + catch (TypeMismatchException ex) { + if (value == null && this.primitivesDefaultedForNullValue) { + if (logger.isDebugEnabled()) { + logger.debug("Intercepted TypeMismatchException for row " + rowNumber + + " and column '" + column + "' with null value when setting property '" + + pd.getName() + "' of type [" + + ClassUtils.getQualifiedName(pd.getPropertyType()) + + "] on object: " + mappedObject, ex); + } } else { - throw e; + throw ex; } } if (populatedProperties != null) { @@ -270,14 +275,21 @@ public class BeanPropertyRowMapper implements RowMapper { } catch (NotWritablePropertyException ex) { throw new DataRetrievalFailureException( - "Unable to map column " + column + " to property " + pd.getName(), ex); + "Unable to map column '" + column + "' to property '" + pd.getName() + "'", ex); + } + } + else { + // No PropertyDescriptor found + if (rowNumber == 0 && logger.isDebugEnabled()) { + logger.debug("No property found for column '" + column + "' mapped to field '" + field + "'"); } } } if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) { throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields " + - "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties); + "necessary to populate object of class [" + this.mappedClass.getName() + "]: " + + this.mappedProperties); } return mappedObject; @@ -312,7 +324,7 @@ public class BeanPropertyRowMapper implements RowMapper { /** - * Static factory method to create a new BeanPropertyRowMapper + * Static factory method to create a new {@code BeanPropertyRowMapper} * (with the mapped class specified only once). * @param mappedClass the class that each row should be mapped to */ diff --git a/spring-web/src/main/java/org/springframework/http/HttpStatus.java b/spring-web/src/main/java/org/springframework/http/HttpStatus.java index 225fbccd9f7..b2fc80ace8e 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpStatus.java +++ b/spring-web/src/main/java/org/springframework/http/HttpStatus.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. @@ -17,11 +17,12 @@ package org.springframework.http; /** - * Java 5 enumeration of HTTP status codes. + * Enumeration of HTTP status codes. * *

The HTTP status code series can be retrieved via {@link #series()}. * * @author Arjen Poutsma + * @since 3.0 * @see HttpStatus.Series * @see HTTP Status Code Registry * @see List of HTTP status codes - Wikipedia @@ -364,17 +365,17 @@ public enum HttpStatus { NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required"); - private final int value; private final String reasonPhrase; - private HttpStatus(int value, String reasonPhrase) { + HttpStatus(int value, String reasonPhrase) { this.value = value; this.reasonPhrase = reasonPhrase; } + /** * Return the integer value of this status code. */ @@ -386,7 +387,7 @@ public enum HttpStatus { * Return the reason phrase of this status code. */ public String getReasonPhrase() { - return reasonPhrase; + return this.reasonPhrase; } /** @@ -402,7 +403,7 @@ public enum HttpStatus { */ @Override public String toString() { - return Integer.toString(value); + return Integer.toString(this.value); } @@ -423,10 +424,10 @@ public enum HttpStatus { /** - * Java 5 enumeration of HTTP status series. + * Enumeration of HTTP status series. *

Retrievable via {@link HttpStatus#series()}. */ - public static enum Series { + public enum Series { INFORMATIONAL(1), SUCCESSFUL(2), @@ -436,7 +437,7 @@ public enum HttpStatus { private final int value; - private Series(int value) { + Series(int value) { this.value = value; } @@ -460,7 +461,6 @@ public enum HttpStatus { public static Series valueOf(HttpStatus status) { return valueOf(status.value); } - } } diff --git a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java index 63cd8693922..3307698bc38 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java +++ b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.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. @@ -243,7 +243,7 @@ public class UrlPathHelper { if (c1 == c2) { continue; } - if (ignoreCase && (Character.toLowerCase(c1) == Character.toLowerCase(c2))) { + else if (ignoreCase && (Character.toLowerCase(c1) == Character.toLowerCase(c2))) { continue; } return null; @@ -251,7 +251,7 @@ public class UrlPathHelper { if (index2 != mapping.length()) { return null; } - if (index1 == requestUri.length()) { + else if (index1 == requestUri.length()) { return ""; } else if (requestUri.charAt(index1) == ';') { @@ -452,8 +452,8 @@ public class UrlPathHelper { * @return the updated URI string */ public String removeSemicolonContent(String requestUri) { - return this.removeSemicolonContent ? - removeSemicolonContentInternal(requestUri) : removeJsessionid(requestUri); + return (this.removeSemicolonContent ? + removeSemicolonContentInternal(requestUri) : removeJsessionid(requestUri)); } private String removeSemicolonContentInternal(String requestUri) { diff --git a/spring-web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd b/spring-web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd index 31aa2524bff..86e8cbab0ce 100644 --- a/spring-web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd +++ b/spring-web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd @@ -1,11 +1,9 @@ - - - - + http://www.w3.org/TR/html4/charset.html. --> +