Skip to content

Commit c734c3a

Browse files
committed
Polishing
1 parent a48a956 commit c734c3a

File tree

6 files changed

+59
-64
lines changed

6 files changed

+59
-64
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -214,7 +214,7 @@ public Object getProxy(ClassLoader classLoader) {
214214
"Common causes of this problem include using a final class or a non-visible class",
215215
ex);
216216
}
217-
catch (Exception ex) {
217+
catch (Throwable ex) {
218218
// TargetSource.getTarget() failed
219219
throw new AopConfigException("Unexpected AOP exception", ex);
220220
}
@@ -256,7 +256,7 @@ private void validateClassIfNecessary(Class<?> proxySuperClass, ClassLoader prox
256256
* methods across ClassLoaders, and writes warnings to the log for each one found.
257257
*/
258258
private void doValidateClass(Class<?> proxySuperClass, ClassLoader proxyClassLoader) {
259-
if (Object.class != proxySuperClass) {
259+
if (proxySuperClass != Object.class) {
260260
Method[] methods = proxySuperClass.getDeclaredMethods();
261261
for (Method method : methods) {
262262
int mod = method.getModifiers();

spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,17 @@
6666
*/
6767
public class ConfigurationClassPostProcessorTests {
6868

69-
private DefaultListableBeanFactory beanFactory;
69+
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
7070

7171

7272
@Before
73-
public void setUp() {
74-
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
73+
public void setup() {
7574
QualifierAnnotationAutowireCandidateResolver acr = new QualifierAnnotationAutowireCandidateResolver();
76-
acr.setBeanFactory(bf);
77-
bf.setAutowireCandidateResolver(acr);
78-
this.beanFactory = bf;
75+
acr.setBeanFactory(this.beanFactory);
76+
this.beanFactory.setAutowireCandidateResolver(acr);
7977
}
8078

79+
8180
/**
8281
* Enhanced {@link Configuration} classes are only necessary for respecting
8382
* certain bean semantics, like singleton-scoping, scoped proxies, etc.
@@ -950,7 +949,6 @@ public String toString() {
950949
}
951950
}
952951

953-
954952
@Configuration
955953
public static class RawRepositoryConfiguration {
956954

spring-context/src/test/java/org/springframework/context/annotation/Spr11202Tests.java

Lines changed: 13 additions & 16 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-2017 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.
@@ -22,11 +22,11 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25-
import org.junit.After;
2625
import org.junit.Test;
2726

2827
import org.springframework.beans.factory.FactoryBean;
2928
import org.springframework.beans.factory.InitializingBean;
29+
import org.springframework.context.ApplicationContext;
3030
import org.springframework.core.type.AnnotatedTypeMetadata;
3131
import org.springframework.core.type.AnnotationMetadata;
3232
import org.springframework.util.Assert;
@@ -38,24 +38,15 @@
3838
*/
3939
public class Spr11202Tests {
4040

41-
private AnnotationConfigApplicationContext context;
42-
43-
@After
44-
public void close() {
45-
if (context != null) {
46-
context.close();
47-
}
48-
}
49-
50-
@Test // Fails
41+
@Test
5142
public void testWithImporter() {
52-
context = new AnnotationConfigApplicationContext(Wrapper.class);
43+
ApplicationContext context = new AnnotationConfigApplicationContext(Wrapper.class);
5344
assertEquals("foo", context.getBean("value"));
5445
}
5546

56-
@Test // Passes
47+
@Test
5748
public void testWithoutImporter() {
58-
context = new AnnotationConfigApplicationContext(Config.class);
49+
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
5950
assertEquals("foo", context.getBean("value"));
6051
}
6152

@@ -65,6 +56,7 @@ public void testWithoutImporter() {
6556
protected static class Wrapper {
6657
}
6758

59+
6860
protected static class Selector implements ImportSelector {
6961

7062
@Override
@@ -73,6 +65,7 @@ public String[] selectImports(AnnotationMetadata importingClassMetadata) {
7365
}
7466
}
7567

68+
7669
@Configuration
7770
protected static class Config {
7871

@@ -95,6 +88,7 @@ public String bar() throws Exception {
9588
}
9689
}
9790

91+
9892
protected static class NoBarCondition implements Condition {
9993

10094
@Override
@@ -106,12 +100,14 @@ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata)
106100
}
107101
}
108102

103+
109104
@Retention(RetentionPolicy.RUNTIME)
110105
@Documented
111106
@Target(ElementType.TYPE)
112-
protected static @interface Bar {
107+
protected @interface Bar {
113108
}
114109

110+
115111
protected static class FooFactoryBean implements FactoryBean<Foo>, InitializingBean {
116112

117113
private Foo foo = new Foo();
@@ -137,6 +133,7 @@ public void afterPropertiesSet() throws Exception {
137133
}
138134
}
139135

136+
140137
protected static class Foo {
141138

142139
private String name;

spring-context/src/test/java/org/springframework/context/annotation/Spr6602Tests.java

Lines changed: 9 additions & 2 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-2017 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.
@@ -32,6 +32,7 @@
3232
* @author Chris Beams
3333
*/
3434
public class Spr6602Tests {
35+
3536
@Test
3637
public void testXmlBehavior() throws Exception {
3738
doAssertions(new ClassPathXmlApplicationContext("Spr6602Tests-context.xml", Spr6602Tests.class));
@@ -59,8 +60,10 @@ private void doAssertions(ApplicationContext ctx) throws Exception {
5960
assertThat(bar3, is(not(bar4)));
6061
}
6162

63+
6264
@Configuration
6365
public static class FooConfig {
66+
6467
@Bean
6568
public Foo foo() throws Exception {
6669
return new Foo(barFactory().getObject());
@@ -72,17 +75,21 @@ public BarFactory barFactory() {
7275
}
7376
}
7477

78+
7579
public static class Foo {
80+
7681
final Bar bar;
7782

7883
public Foo(Bar bar) {
7984
this.bar = bar;
8085
}
8186
}
8287

88+
8389
public static class Bar {
8490
}
8591

92+
8693
public static class BarFactory implements FactoryBean<Bar> {
8794

8895
@Override
@@ -102,4 +109,4 @@ public boolean isSingleton() {
102109

103110
}
104111

105-
}
112+
}

spring-context/src/test/java/org/springframework/context/annotation/configuration/ConfigurationClassProcessingTests.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -63,39 +63,15 @@
6363
import static org.junit.Assert.*;
6464

6565
/**
66-
* Miscellaneous system tests covering {@link Bean} naming, aliases, scoping and error
67-
* handling within {@link Configuration} class definitions.
66+
* Miscellaneous system tests covering {@link Bean} naming, aliases, scoping and
67+
* error handling within {@link Configuration} class definitions.
6868
*
6969
* @author Chris Beams
7070
* @author Juergen Hoeller
7171
* @author Sam Brannen
7272
*/
7373
public class ConfigurationClassProcessingTests {
7474

75-
/**
76-
* Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition} for
77-
* each of the given {@link Configuration} <var>configClasses</var>, and then
78-
* post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
79-
* When complete, the factory is ready to service requests for any {@link Bean} methods
80-
* declared by <var>configClasses</var>.
81-
*/
82-
private DefaultListableBeanFactory initBeanFactory(Class<?>... configClasses) {
83-
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
84-
for (Class<?> configClass : configClasses) {
85-
String configBeanName = configClass.getName();
86-
factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
87-
}
88-
ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
89-
ccpp.postProcessBeanDefinitionRegistry(factory);
90-
ccpp.postProcessBeanFactory(factory);
91-
RequiredAnnotationBeanPostProcessor rapp = new RequiredAnnotationBeanPostProcessor();
92-
rapp.setBeanFactory(factory);
93-
factory.addBeanPostProcessor(rapp);
94-
factory.freezeConfiguration();
95-
return factory;
96-
}
97-
98-
9975
@Rule
10076
public final ExpectedException exception = ExpectedException.none();
10177

@@ -267,6 +243,30 @@ public void configurationWithPostProcessor() {
267243
}
268244

269245

246+
/**
247+
* Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition}
248+
* for each of the given {@link Configuration} {@code configClasses}, and then
249+
* post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
250+
* When complete, the factory is ready to service requests for any {@link Bean} methods
251+
* declared by {@code configClasses}.
252+
*/
253+
private DefaultListableBeanFactory initBeanFactory(Class<?>... configClasses) {
254+
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
255+
for (Class<?> configClass : configClasses) {
256+
String configBeanName = configClass.getName();
257+
factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
258+
}
259+
ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
260+
ccpp.postProcessBeanDefinitionRegistry(factory);
261+
ccpp.postProcessBeanFactory(factory);
262+
RequiredAnnotationBeanPostProcessor rapp = new RequiredAnnotationBeanPostProcessor();
263+
rapp.setBeanFactory(factory);
264+
factory.addBeanPostProcessor(rapp);
265+
factory.freezeConfiguration();
266+
return factory;
267+
}
268+
269+
270270
@Configuration
271271
static class ConfigWithBeanWithCustomName {
272272

spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -1543,14 +1543,8 @@ public void synthesizeAnnotationWithArrayOfChars() throws Exception {
15431543
assertArrayEquals(new char[] { 'x', 'y', 'z' }, chars);
15441544
}
15451545

1546+
15461547
@SafeVarargs
1547-
// The following "varargs" suppression is necessary for javac from OpenJDK
1548-
// (1.8.0_60-b27); however, Eclipse warns that it's unnecessary. See the following
1549-
// Eclipse issues for details.
1550-
//
1551-
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=344783
1552-
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=349669#c10
1553-
// @SuppressWarnings("varargs")
15541548
static <T> T[] asArray(T... arr) {
15551549
return arr;
15561550
}
@@ -1996,7 +1990,6 @@ static class SimpleConfigTestCase {
19961990
static class GroupOfCharsClass {
19971991
}
19981992

1999-
20001993
@Retention(RetentionPolicy.RUNTIME)
20011994
@interface AliasForWithMissingAttributeDeclaration {
20021995

0 commit comments

Comments
 (0)