Skip to content

Commit 74b4dd0

Browse files
committed
Polishing
(cherry picked from commit b5127dc)
1 parent 9ec50a2 commit 74b4dd0

File tree

17 files changed

+208
-197
lines changed

17 files changed

+208
-197
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -156,7 +156,7 @@ public BeanWrapper autowireConstructor(
156156
catch (Throwable ex) {
157157
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
158158
"Resolution of declared constructors on bean Class [" + beanClass.getName() +
159-
"] from ClassLoader [" + beanClass.getClassLoader() + "] failed", ex);
159+
"] from ClassLoader [" + beanClass.getClassLoader() + "] failed", ex);
160160
}
161161
}
162162
AutowireUtils.sortConstructors(candidates);
@@ -613,8 +613,8 @@ private int resolveConstructorArguments(
613613
String beanName, RootBeanDefinition mbd, BeanWrapper bw,
614614
ConstructorArgumentValues cargs, ConstructorArgumentValues resolvedValues) {
615615

616-
TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ?
617-
this.beanFactory.getCustomTypeConverter() : bw);
616+
TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();
617+
TypeConverter converter = (customConverter != null ? customConverter : bw);
618618
BeanDefinitionValueResolver valueResolver =
619619
new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
620620

@@ -670,8 +670,8 @@ private ArgumentsHolder createArgumentArray(
670670
boolean autowiring) throws UnsatisfiedDependencyException {
671671

672672
String methodType = (methodOrCtor instanceof Constructor ? "constructor" : "factory method");
673-
TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ?
674-
this.beanFactory.getCustomTypeConverter() : bw);
673+
TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();
674+
TypeConverter converter = (customConverter != null ? customConverter : bw);
675675

676676
ArgumentsHolder args = new ArgumentsHolder(paramTypes.length);
677677
Set<ConstructorArgumentValues.ValueHolder> usedValueHolders =
@@ -772,12 +772,13 @@ private ArgumentsHolder createArgumentArray(
772772
private Object[] resolvePreparedArguments(
773773
String beanName, RootBeanDefinition mbd, BeanWrapper bw, Member methodOrCtor, Object[] argsToResolve) {
774774

775-
Class<?>[] paramTypes = (methodOrCtor instanceof Method ?
776-
((Method) methodOrCtor).getParameterTypes() : ((Constructor<?>) methodOrCtor).getParameterTypes());
777-
TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ?
778-
this.beanFactory.getCustomTypeConverter() : bw);
775+
TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();
776+
TypeConverter converter = (customConverter != null ? customConverter : bw);
779777
BeanDefinitionValueResolver valueResolver =
780778
new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
779+
Class<?>[] paramTypes = (methodOrCtor instanceof Method ?
780+
((Method) methodOrCtor).getParameterTypes() : ((Constructor<?>) methodOrCtor).getParameterTypes());
781+
781782
Object[] resolvedArgs = new Object[argsToResolve.length];
782783
for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
783784
Object argValue = argsToResolve[argIndex];

spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean
7272
* @param methodNames an array of method names indicating the methods to use
7373
* @see #setMethodMappings
7474
*/
75-
public void setManagedMethods(String[] methodNames) {
75+
public void setManagedMethods(String... methodNames) {
7676
this.managedMethods = new HashSet<String>(Arrays.asList(methodNames));
7777
}
7878

@@ -85,7 +85,7 @@ public void setManagedMethods(String[] methodNames) {
8585
*/
8686
public void setMethodMappings(Properties mappings) {
8787
this.methodMappings = new HashMap<String, Set<String>>();
88-
for (Enumeration en = mappings.keys(); en.hasMoreElements();) {
88+
for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) {
8989
String beanKey = (String) en.nextElement();
9090
String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
9191
this.methodMappings.put(beanKey, new HashSet<String>(Arrays.asList(methodNames)));

spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerMappedTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5-
* use this file except in compliance with the License. You may obtain a copy of
6-
* the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations under
14-
* the License.
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616

1717
package org.springframework.jmx.export.assembler;
1818

1919
import java.util.Properties;
20-
2120
import javax.management.MBeanAttributeInfo;
2221
import javax.management.modelmbean.ModelMBeanAttributeInfo;
2322
import javax.management.modelmbean.ModelMBeanInfo;
@@ -34,6 +33,7 @@ public class MethodNameBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAss
3433

3534
protected static final String OBJECT_NAME = "bean:name=testBean4";
3635

36+
3737
@Test
3838
public void testGetAgeIsReadOnly() throws Exception {
3939
ModelMBeanInfo info = getMBeanInfoFromAssembler();
@@ -47,7 +47,7 @@ public void testGetAgeIsReadOnly() throws Exception {
4747
public void testWithFallThrough() throws Exception {
4848
MethodNameBasedMBeanInfoAssembler assembler =
4949
getWithMapping("foobar", "add,myOperation,getName,setName,getAge");
50-
assembler.setManagedMethods(new String[]{"getNickName", "setNickName"});
50+
assembler.setManagedMethods("getNickName", "setNickName");
5151

5252
ModelMBeanInfo inf = assembler.getMBeanInfo(getBean(), getObjectName());
5353
MBeanAttributeInfo attr = inf.getAttribute("NickName");

spring-context/src/test/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssemblerTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5-
* use this file except in compliance with the License. You may obtain a copy of
6-
* the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations under
14-
* the License.
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616

1717
package org.springframework.jmx.export.assembler;
@@ -33,6 +33,7 @@ public class MethodNameBasedMBeanInfoAssemblerTests extends AbstractJmxAssembler
3333

3434
protected static final String OBJECT_NAME = "bean:name=testBean5";
3535

36+
3637
@Override
3738
protected String getObjectName() {
3839
return OBJECT_NAME;
@@ -51,7 +52,7 @@ protected int getExpectedAttributeCount() {
5152
@Override
5253
protected MBeanInfoAssembler getAssembler() {
5354
MethodNameBasedMBeanInfoAssembler assembler = new MethodNameBasedMBeanInfoAssembler();
54-
assembler.setManagedMethods(new String[] {"add", "myOperation", "getName", "setName", "getAge"});
55+
assembler.setManagedMethods("add", "myOperation", "getName", "setName", "getAge");
5556
return assembler;
5657
}
5758

spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import java.io.NotSerializableException;
2222
import java.io.ObjectInputStream;
2323
import java.io.ObjectStreamClass;
24-
import java.lang.reflect.Proxy;
2524

2625
import org.springframework.util.ClassUtils;
2726

@@ -68,7 +67,7 @@ public ConfigurableObjectInputStream(
6867

6968

7069
@Override
71-
protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
70+
protected Class<?> resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
7271
try {
7372
if (this.classLoader != null) {
7473
// Use the specified ClassLoader to resolve local classes.
@@ -85,13 +84,13 @@ protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, Cl
8584
}
8685

8786
@Override
88-
protected Class resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException {
87+
protected Class<?> resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException {
8988
if (!this.acceptProxyClasses) {
9089
throw new NotSerializableException("Not allowed to accept serialized proxy classes");
9190
}
9291
if (this.classLoader != null) {
9392
// Use the specified ClassLoader to resolve local proxy classes.
94-
Class[] resolvedInterfaces = new Class[interfaces.length];
93+
Class<?>[] resolvedInterfaces = new Class<?>[interfaces.length];
9594
for (int i = 0; i < interfaces.length; i++) {
9695
try {
9796
resolvedInterfaces[i] = ClassUtils.forName(interfaces[i], this.classLoader);
@@ -101,7 +100,7 @@ protected Class resolveProxyClass(String[] interfaces) throws IOException, Class
101100
}
102101
}
103102
try {
104-
return Proxy.getProxyClass(this.classLoader, resolvedInterfaces);
103+
return ClassUtils.createCompositeInterface(resolvedInterfaces, this.classLoader);
105104
}
106105
catch (IllegalArgumentException ex) {
107106
throw new ClassNotFoundException(null, ex);
@@ -113,11 +112,11 @@ protected Class resolveProxyClass(String[] interfaces) throws IOException, Class
113112
return super.resolveProxyClass(interfaces);
114113
}
115114
catch (ClassNotFoundException ex) {
116-
Class[] resolvedInterfaces = new Class[interfaces.length];
115+
Class<?>[] resolvedInterfaces = new Class<?>[interfaces.length];
117116
for (int i = 0; i < interfaces.length; i++) {
118117
resolvedInterfaces[i] = resolveFallbackIfPossible(interfaces[i], ex);
119118
}
120-
return Proxy.getProxyClass(getFallbackClassLoader(), resolvedInterfaces);
119+
return ClassUtils.createCompositeInterface(resolvedInterfaces, getFallbackClassLoader());
121120
}
122121
}
123122
}
@@ -131,16 +130,17 @@ protected Class resolveProxyClass(String[] interfaces) throws IOException, Class
131130
* @param ex the original exception thrown when attempting to load the class
132131
* @return the newly resolved class (never {@code null})
133132
*/
134-
protected Class resolveFallbackIfPossible(String className, ClassNotFoundException ex)
133+
protected Class<?> resolveFallbackIfPossible(String className, ClassNotFoundException ex)
135134
throws IOException, ClassNotFoundException{
136135

137136
throw ex;
138137
}
139138

140139
/**
141140
* Return the fallback ClassLoader to use when no ClassLoader was specified
142-
* and ObjectInputStream's own default ClassLoader failed.
143-
* <p>The default implementation simply returns {@code null}.
141+
* and ObjectInputStream's own default class loader failed.
142+
* <p>The default implementation simply returns {@code null}, indicating
143+
* that no specific fallback is available.
144144
*/
145145
protected ClassLoader getFallbackClassLoader() throws IOException {
146146
return null;

spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@ protected File getFileForLastModifiedCheck() throws IOException {
7272
}
7373

7474
/**
75-
* This implementation returns a File reference for the underlying class path
75+
* This implementation returns a File reference for the given URI-identified
7676
* resource, provided that it refers to a file in the file system.
7777
* @see org.springframework.util.ResourceUtils#getFile(java.net.URI, String)
7878
*/

spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
3030

3131
/**
3232
* {@link Resource} implementation for {@code java.io.File} handles.
33-
* Obviously supports resolution as File, and also as URL.
33+
* Supports resolution as a {@code File} and also as a {@code URL}.
3434
* Implements the extended {@link WritableResource} interface.
3535
*
3636
* @author Juergen Hoeller
@@ -85,7 +85,6 @@ public final String getPath() {
8585
return this.path;
8686
}
8787

88-
8988
/**
9089
* This implementation returns whether the underlying file exists.
9190
* @see java.io.File#exists()

spring-core/src/main/java/org/springframework/core/io/Resource.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,25 +37,25 @@
3737
* @see #getFile()
3838
* @see WritableResource
3939
* @see ContextResource
40-
* @see FileSystemResource
41-
* @see ClassPathResource
4240
* @see UrlResource
41+
* @see ClassPathResource
42+
* @see FileSystemResource
4343
* @see ByteArrayResource
4444
* @see InputStreamResource
4545
*/
4646
public interface Resource extends InputStreamSource {
4747

4848
/**
49-
* Return whether this resource actually exists in physical form.
49+
* Determine whether this resource actually exists in physical form.
5050
* <p>This method performs a definitive existence check, whereas the
51-
* existence of a {@code Resource} handle only guarantees a
52-
* valid descriptor handle.
51+
* existence of a {@code Resource} handle only guarantees a valid
52+
* descriptor handle.
5353
*/
5454
boolean exists();
5555

5656
/**
57-
* Return whether the contents of this resource can be read,
58-
* e.g. via {@link #getInputStream()} or {@link #getFile()}.
57+
* Indicate whether the contents of this resource can be read via
58+
* {@link #getInputStream()}.
5959
* <p>Will be {@code true} for typical resource descriptors;
6060
* note that actual content reading may still fail when attempted.
6161
* However, a value of {@code false} is a definitive indication
@@ -65,8 +65,8 @@ public interface Resource extends InputStreamSource {
6565
boolean isReadable();
6666

6767
/**
68-
* Return whether this resource represents a handle with an open
69-
* stream. If true, the InputStream cannot be read multiple times,
68+
* Indicate whether this resource represents a handle with an open stream.
69+
* If {@code true}, the InputStream cannot be read multiple times,
7070
* and must be read and closed to avoid resource leaks.
7171
* <p>Will be {@code false} for typical resource descriptors.
7272
*/
@@ -83,6 +83,7 @@ public interface Resource extends InputStreamSource {
8383
* Return a URI handle for this resource.
8484
* @throws IOException if the resource cannot be resolved as URI,
8585
* i.e. if the resource is not available as descriptor
86+
* @since 2.5
8687
*/
8788
URI getURI() throws IOException;
8889

0 commit comments

Comments
 (0)