Skip to content

Commit ad91610

Browse files
committed
Polishing
(cherry picked from commit 426f52b)
1 parent f558396 commit ad91610

File tree

5 files changed

+80
-73
lines changed

5 files changed

+80
-73
lines changed

spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java

Lines changed: 13 additions & 15 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-2014 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.
@@ -155,8 +155,8 @@ void hidden() {
155155
assertTrue(ex.getCause() instanceof CodeGenerationException ||
156156
ex.getCause() instanceof IllegalArgumentException);
157157
// Check that error message is helpful
158-
assertTrue(ex.getMessage().indexOf("final") != -1);
159-
assertTrue(ex.getMessage().indexOf("visible") != -1);
158+
assertTrue(ex.getMessage().contains("final"));
159+
assertTrue(ex.getMessage().contains("visible"));
160160
}
161161
}
162162

@@ -171,9 +171,7 @@ public void testMethodInvocationDuringConstructor() {
171171
AopProxy aop = new CglibAopProxy(as);
172172

173173
CglibTestBean proxy = (CglibTestBean) aop.getProxy();
174-
175-
assertEquals("The name property has been overwritten by the constructor",
176-
"Rob Harrop", proxy.getName());
174+
assertEquals("The name property has been overwritten by the constructor", "Rob Harrop", proxy.getName());
177175
}
178176

179177
@Test
@@ -186,9 +184,7 @@ public void testUnadvisedProxyCreationWithCallDuringConstructor() throws Excepti
186184
pc.setTarget(target);
187185

188186
CglibAopProxy aop = new CglibAopProxy(pc);
189-
190187
CglibTestBean proxy = (CglibTestBean) aop.getProxy();
191-
192188
assertNotNull("Proxy should not be null", proxy);
193189
assertEquals("Constructor overrode the value of name", "Rob Harrop", proxy.getName());
194190

@@ -218,15 +214,18 @@ private ITestBean getAdvisedProxy(TestBean target) {
218214
public ClassFilter getClassFilter() {
219215
return ClassFilter.TRUE;
220216
}
221-
222217
@Override
223218
public MethodMatcher getMethodMatcher() {
224219
return MethodMatcher.TRUE;
225220
}
226-
221+
@Override
227222
public boolean equals(Object obj) {
228223
return true;
229224
}
225+
@Override
226+
public int hashCode() {
227+
return 0;
228+
}
230229
};
231230
pf.addAdvisor(new DefaultPointcutAdvisor(pointcut, advice));
232231

@@ -250,7 +249,7 @@ public void testMultipleProxiesForIntroductionAdvisor() {
250249
}
251250

252251
private ITestBean getIntroductionAdvisorProxy(TestBean target) {
253-
ProxyFactory pf = new ProxyFactory(new Class<?>[]{ITestBean.class});
252+
ProxyFactory pf = new ProxyFactory(new Class<?>[] {ITestBean.class});
254253
pf.setProxyTargetClass(true);
255254

256255
pf.addAdvisor(new LockMixinAdvisor());
@@ -270,8 +269,7 @@ public void testWithNoArgConstructor() {
270269
AdvisedSupport pc = new AdvisedSupport(new Class<?>[]{});
271270
pc.setTargetSource(mockTargetSource);
272271
CglibAopProxy aop = new CglibAopProxy(pc);
273-
aop.setConstructorArguments(new Object[] {"Rob Harrop", new Integer(22)},
274-
new Class<?>[] {String.class, int.class});
272+
aop.setConstructorArguments(new Object[] {"Rob Harrop", 22}, new Class<?>[] {String.class, int.class});
275273

276274
NoArgCtorTestBean proxy = (NoArgCtorTestBean) aop.getProxy();
277275
proxy = (NoArgCtorTestBean) aop.getProxy();
@@ -347,9 +345,9 @@ public void testExceptionHandling() {
347345
}
348346

349347
@Test
348+
@SuppressWarnings("resource")
350349
public void testWithDependencyChecking() {
351-
ApplicationContext ctx =
352-
new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass());
350+
ApplicationContext ctx = new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass());
353351
ctx.getBean("testBean");
354352
}
355353

spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java

Lines changed: 15 additions & 6 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-2014 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.
@@ -132,6 +132,15 @@ public ConcurrentReferenceHashMap(int initialCapacity, int concurrencyLevel) {
132132
this(initialCapacity, DEFAULT_LOAD_FACTOR, concurrencyLevel, DEFAULT_REFERENCE_TYPE);
133133
}
134134

135+
/**
136+
* Create a new {@code ConcurrentReferenceHashMap} instance.
137+
* @param initialCapacity the initial capacity of the map
138+
* @param referenceType the reference type used for entries (soft or weak)
139+
*/
140+
public ConcurrentReferenceHashMap(int initialCapacity, ReferenceType referenceType) {
141+
this(initialCapacity, DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL, referenceType);
142+
}
143+
135144
/**
136145
* Create a new {@code ConcurrentReferenceHashMap} instance.
137146
* @param initialCapacity the initial capacity of the map
@@ -151,7 +160,7 @@ public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int con
151160
* table exceeds this value, resize will be attempted.
152161
* @param concurrencyLevel the expected number of threads that will concurrently
153162
* write to the map
154-
* @param referenceType the reference type used for entries
163+
* @param referenceType the reference type used for entries (soft or weak)
155164
*/
156165
@SuppressWarnings("unchecked")
157166
public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel,
@@ -165,10 +174,10 @@ public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int con
165174
this.shift = calculateShift(concurrencyLevel, MAXIMUM_CONCURRENCY_LEVEL);
166175
int size = 1 << this.shift;
167176
this.referenceType = referenceType;
168-
int roundedUpSegmentCapactity = (int) ((initialCapacity + size - 1L) / size);
177+
int roundedUpSegmentCapacity = (int) ((initialCapacity + size - 1L) / size);
169178
this.segments = (Segment[]) Array.newInstance(Segment.class, size);
170179
for (int i = 0; i < this.segments.length; i++) {
171-
this.segments[i] = new Segment(roundedUpSegmentCapactity);
180+
this.segments[i] = new Segment(roundedUpSegmentCapacity);
172181
}
173182
}
174183

@@ -186,8 +195,8 @@ protected final Segment getSegment(int index) {
186195
}
187196

188197
/**
189-
* Factory method that returns the {@link ReferenceManager}. This method will be
190-
* called once for each {@link Segment}.
198+
* Factory method that returns the {@link ReferenceManager}.
199+
* This method will be called once for each {@link Segment}.
191200
* @return a new reference manager
192201
*/
193202
protected ReferenceManager createReferenceManager() {

spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java

Lines changed: 15 additions & 16 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-2014 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.
@@ -19,8 +19,8 @@
1919
import java.io.Serializable;
2020

2121
/**
22-
* Simple customizable helper class for creating threads. Provides various
23-
* bean properties, such as thread name prefix, thread priority, etc.
22+
* Simple customizable helper class for creating new {@link Thread} instances.
23+
* Provides various bean properties: thread name prefix, thread priority, etc.
2424
*
2525
* <p>Serves as base class for thread factories such as
2626
* {@link org.springframework.scheduling.concurrent.CustomizableThreadFactory}.
@@ -96,11 +96,11 @@ public int getThreadPriority() {
9696
/**
9797
* Set whether this factory is supposed to create daemon threads,
9898
* just executing as long as the application itself is running.
99-
* <p>Default is "false": Concrete factories usually support explicit
100-
* cancelling. Hence, if the application shuts down, Runnables will
101-
* by default finish their execution.
102-
* <p>Specify "true" for eager shutdown of threads which still
103-
* actively execute a Runnable.
99+
* <p>Default is "false": Concrete factories usually support explicit cancelling.
100+
* Hence, if the application shuts down, Runnables will by default finish their
101+
* execution.
102+
* <p>Specify "true" for eager shutdown of threads which still actively execute
103+
* a {@link Runnable} at the time that the application itself shuts down.
104104
* @see java.lang.Thread#setDaemon
105105
*/
106106
public void setDaemon(boolean daemon) {
@@ -132,17 +132,17 @@ public void setThreadGroup(ThreadGroup threadGroup) {
132132

133133
/**
134134
* Return the thread group that threads should be created in
135-
* (or {@code null}) for the default group.
135+
* (or {@code null} for the default group).
136136
*/
137137
public ThreadGroup getThreadGroup() {
138138
return this.threadGroup;
139139
}
140140

141141

142142
/**
143-
* Template method for the creation of a Thread.
144-
* <p>Default implementation creates a new Thread for the given
145-
* Runnable, applying an appropriate thread name.
143+
* Template method for the creation of a new {@link Thread}.
144+
* <p>The default implementation creates a new Thread for the given
145+
* {@link Runnable}, applying an appropriate thread name.
146146
* @param runnable the Runnable to execute
147147
* @see #nextThreadName()
148148
*/
@@ -154,10 +154,9 @@ public Thread createThread(Runnable runnable) {
154154
}
155155

156156
/**
157-
* Return the thread name to use for a newly created thread.
158-
* <p>Default implementation returns the specified thread name prefix
159-
* with an increasing thread count appended: for example,
160-
* "SimpleAsyncTaskExecutor-0".
157+
* Return the thread name to use for a newly created {@link Thread}.
158+
* <p>The default implementation returns the specified thread name prefix
159+
* with an increasing thread count appended: e.g. "SimpleAsyncTaskExecutor-0".
161160
* @see #getThreadNamePrefix()
162161
*/
163162
protected String nextThreadName() {

spring-core/src/main/java/org/springframework/util/ReflectionUtils.java

Lines changed: 17 additions & 10 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-2014 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.
@@ -44,8 +44,13 @@
4444
*/
4545
public abstract class ReflectionUtils {
4646

47+
/**
48+
* Pattern for detecting CGLIB-renamed methods.
49+
* @see #isCglibRenamedMethod
50+
*/
4751
private static final Pattern CGLIB_RENAMED_METHOD_PATTERN = Pattern.compile("CGLIB\\$(.+)\\$\\d+");
4852

53+
4954
/**
5055
* Attempt to find a {@link Field field} on the supplied {@link Class} with the
5156
* supplied {@code name}. Searches all superclasses up to {@link Object}.
@@ -133,7 +138,7 @@ public static Object getField(Field field, Object target) {
133138
* @return the Method object, or {@code null} if none found
134139
*/
135140
public static Method findMethod(Class<?> clazz, String name) {
136-
return findMethod(clazz, name, new Class[0]);
141+
return findMethod(clazz, name, new Class<?>[0]);
137142
}
138143

139144
/**
@@ -373,19 +378,21 @@ public static boolean isToStringMethod(Method method) {
373378
* Determine whether the given method is originally declared by {@link java.lang.Object}.
374379
*/
375380
public static boolean isObjectMethod(Method method) {
381+
if (method == null) {
382+
return false;
383+
}
376384
try {
377385
Object.class.getDeclaredMethod(method.getName(), method.getParameterTypes());
378386
return true;
379-
} catch (SecurityException ex) {
380-
return false;
381-
} catch (NoSuchMethodException ex) {
387+
}
388+
catch (Exception ex) {
382389
return false;
383390
}
384391
}
385392

386393
/**
387-
* Determine whether the given method is a CGLIB 'renamed' method, following
388-
* the pattern "CGLIB$methodName$0".
394+
* Determine whether the given method is a CGLIB 'renamed' method,
395+
* following the pattern "CGLIB$methodName$0".
389396
* @param renamedMethod the method to check
390397
* @see org.springframework.cglib.proxy.Enhancer#rename
391398
*/
@@ -512,15 +519,15 @@ public static Method[] getUniqueDeclaredMethods(Class<?> leafClass) throws Illeg
512519
public void doWith(Method method) {
513520
boolean knownSignature = false;
514521
Method methodBeingOverriddenWithCovariantReturnType = null;
515-
516522
for (Method existingMethod : methods) {
517523
if (method.getName().equals(existingMethod.getName()) &&
518524
Arrays.equals(method.getParameterTypes(), existingMethod.getParameterTypes())) {
519-
// is this a covariant return type situation?
525+
// Is this a covariant return type situation?
520526
if (existingMethod.getReturnType() != method.getReturnType() &&
521527
existingMethod.getReturnType().isAssignableFrom(method.getReturnType())) {
522528
methodBeingOverriddenWithCovariantReturnType = existingMethod;
523-
} else {
529+
}
530+
else {
524531
knownSignature = true;
525532
}
526533
break;

0 commit comments

Comments
 (0)