Skip to content

Commit b0ef80c

Browse files
committed
Polishing
1 parent 7ed4884 commit b0ef80c

File tree

30 files changed

+203
-238
lines changed

30 files changed

+203
-238
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java

Lines changed: 9 additions & 5 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.
@@ -1478,17 +1478,21 @@ private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinitio
14781478

14791479

14801480
/**
1481-
* Get the namespace URI for the supplied node. The default implementation uses {@link Node#getNamespaceURI}.
1482-
* Subclasses may override the default implementation to provide a different namespace identification mechanism.
1481+
* Get the namespace URI for the supplied node.
1482+
* <p>The default implementation uses {@link Node#getNamespaceURI}.
1483+
* Subclasses may override the default implementation to provide a
1484+
* different namespace identification mechanism.
14831485
* @param node the node
14841486
*/
14851487
public String getNamespaceURI(Node node) {
14861488
return node.getNamespaceURI();
14871489
}
14881490

14891491
/**
1490-
* Ges the local name for the supplied {@link Node}. The default implementation calls {@link Node#getLocalName}.
1491-
* Subclasses may override the default implementation to provide a different mechanism for getting the local name.
1492+
* Get the local name for the supplied {@link Node}.
1493+
* <p>The default implementation calls {@link Node#getLocalName}.
1494+
* Subclasses may override the default implementation to provide a
1495+
* different mechanism for getting the local name.
14921496
* @param node the {@code Node}
14931497
*/
14941498
public String getLocalName(Node node) {

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ protected final void parse(AnnotationMetadata metadata, String beanName) throws
197197
processConfigurationClass(new ConfigurationClass(metadata, beanName));
198198
}
199199

200+
/**
201+
* Validate each {@link ConfigurationClass} object.
202+
* @see ConfigurationClass#validate
203+
*/
204+
public void validate() {
205+
for (ConfigurationClass configClass : this.configurationClasses.keySet()) {
206+
configClass.validate(this.problemReporter);
207+
}
208+
}
209+
210+
public Set<ConfigurationClass> getConfigurationClasses() {
211+
return this.configurationClasses.keySet();
212+
}
213+
200214

201215
protected void processConfigurationClass(ConfigurationClass configClass) throws IOException {
202216
if (this.conditionEvaluator.shouldSkip(configClass.getMetadata(), ConfigurationPhase.PARSE_CONFIGURATION)) {
@@ -390,6 +404,7 @@ private Set<MethodMetadata> retrieveBeanMethodMetadata(SourceClass sourceClass)
390404
return beanMethods;
391405
}
392406

407+
393408
/**
394409
* Process the given <code>@PropertySource</code> annotation metadata.
395410
* @param propertySource metadata for the <code>@PropertySource</code> annotation found
@@ -608,30 +623,15 @@ private boolean isChainedImportOnStack(ConfigurationClass configClass) {
608623
return false;
609624
}
610625

611-
612-
/**
613-
* Validate each {@link ConfigurationClass} object.
614-
* @see ConfigurationClass#validate
615-
*/
616-
public void validate() {
617-
for (ConfigurationClass configClass : this.configurationClasses.keySet()) {
618-
configClass.validate(this.problemReporter);
619-
}
620-
}
621-
622-
public Set<ConfigurationClass> getConfigurationClasses() {
623-
return this.configurationClasses.keySet();
624-
}
625-
626-
627626
ImportRegistry getImportRegistry() {
628627
return this.importStack;
629628
}
630629

630+
631631
/**
632632
* Factory method to obtain a {@link SourceClass} from a {@link ConfigurationClass}.
633633
*/
634-
public SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException {
634+
private SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException {
635635
AnnotationMetadata metadata = configurationClass.getMetadata();
636636
if (metadata instanceof StandardAnnotationMetadata) {
637637
return asSourceClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
@@ -642,7 +642,7 @@ public SourceClass asSourceClass(ConfigurationClass configurationClass) throws I
642642
/**
643643
* Factory method to obtain a {@link SourceClass} from a {@link Class}.
644644
*/
645-
public SourceClass asSourceClass(Class<?> classType) throws IOException {
645+
SourceClass asSourceClass(Class<?> classType) throws IOException {
646646
try {
647647
// Sanity test that we can read annotations, if not fall back to ASM
648648
classType.getAnnotations();
@@ -657,8 +657,8 @@ public SourceClass asSourceClass(Class<?> classType) throws IOException {
657657
/**
658658
* Factory method to obtain {@link SourceClass}s from class names.
659659
*/
660-
public Collection<SourceClass> asSourceClasses(String[] classNames) throws IOException {
661-
List<SourceClass> annotatedClasses = new ArrayList<SourceClass>();
660+
private Collection<SourceClass> asSourceClasses(String[] classNames) throws IOException {
661+
List<SourceClass> annotatedClasses = new ArrayList<SourceClass>(classNames.length);
662662
for (String className : classNames) {
663663
annotatedClasses.add(asSourceClass(className));
664664
}
@@ -668,7 +668,7 @@ public Collection<SourceClass> asSourceClasses(String[] classNames) throws IOExc
668668
/**
669669
* Factory method to obtain a {@link SourceClass} from a class name.
670670
*/
671-
public SourceClass asSourceClass(String className) throws IOException {
671+
SourceClass asSourceClass(String className) throws IOException {
672672
if (className.startsWith("java")) {
673673
// Never use ASM for core java types
674674
try {

spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaver.java

Lines changed: 6 additions & 11 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.
@@ -37,7 +37,8 @@
3737
*/
3838
public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
3939

40-
private static final String INSTRUMENTABLE_LOADER_CLASS_NAME = "org.glassfish.api.deployment.InstrumentableClassLoader";
40+
private static final String INSTRUMENTABLE_LOADER_CLASS_NAME =
41+
"org.glassfish.api.deployment.InstrumentableClassLoader";
4142

4243

4344
private final ClassLoader classLoader;
@@ -57,16 +58,10 @@ public GlassFishLoadTimeWeaver(ClassLoader classLoader) {
5758
Class<?> instrumentableLoaderClass;
5859
try {
5960
instrumentableLoaderClass = classLoader.loadClass(INSTRUMENTABLE_LOADER_CLASS_NAME);
60-
}
61-
catch (ClassNotFoundException ex) {
62-
throw new IllegalStateException(
63-
"Could not initialize GlassFishLoadTimeWeaver because GlassFish API classes are not available", ex);
64-
}
65-
try {
6661
this.addTransformerMethod = instrumentableLoaderClass.getMethod("addTransformer", ClassFileTransformer.class);
6762
this.copyMethod = instrumentableLoaderClass.getMethod("copy");
6863
}
69-
catch (Exception ex) {
64+
catch (Throwable ex) {
7065
throw new IllegalStateException(
7166
"Could not initialize GlassFishLoadTimeWeaver because GlassFish API classes are not available", ex);
7267
}
@@ -97,7 +92,7 @@ public void addTransformer(ClassFileTransformer transformer) {
9792
catch (InvocationTargetException ex) {
9893
throw new IllegalStateException("GlassFish addTransformer method threw exception", ex.getCause());
9994
}
100-
catch (Exception ex) {
95+
catch (Throwable ex) {
10196
throw new IllegalStateException("Could not invoke GlassFish addTransformer method", ex);
10297
}
10398
}
@@ -115,7 +110,7 @@ public ClassLoader getThrowawayClassLoader() {
115110
catch (InvocationTargetException ex) {
116111
throw new IllegalStateException("GlassFish copy method threw exception", ex.getCause());
117112
}
118-
catch (Exception ex) {
113+
catch (Throwable ex) {
119114
throw new IllegalStateException("Could not invoke GlassFish copy method", ex);
120115
}
121116
}

spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossMCAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public JBossMCAdapter(ClassLoader classLoader) {
7878
this.translatorClass = classLoader.loadClass(TRANSLATOR_NAME);
7979
this.addTranslator = this.target.getClass().getMethod("addTranslator", this.translatorClass);
8080
}
81-
catch (Exception ex) {
81+
catch (Throwable ex) {
8282
throw new IllegalStateException(
8383
"Could not initialize JBoss LoadTimeWeaver because the JBoss 6 API classes are not available", ex);
8484
}
@@ -92,7 +92,7 @@ public void addTransformer(ClassFileTransformer transformer) {
9292
try {
9393
this.addTranslator.invoke(this.target, adapterInstance);
9494
}
95-
catch (Exception ex) {
95+
catch (Throwable ex) {
9696
throw new IllegalStateException("Could not add transformer on JBoss 6 ClassLoader " + this.classLoader, ex);
9797
}
9898
}

spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossMCTranslatorAdapter.java

Lines changed: 2 additions & 5 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.
@@ -78,10 +78,7 @@ public void unregisterClassLoader(ClassLoader loader) {
7878

7979
@Override
8080
public String toString() {
81-
StringBuilder builder = new StringBuilder(getClass().getName());
82-
builder.append(" for transformer: ");
83-
builder.append(this.transformer);
84-
return builder.toString();
81+
return getClass().getName() + " for transformer: " + this.transformer;
8582
}
8683

8784
}

spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossModulesAdapter.java

Lines changed: 19 additions & 9 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.
@@ -43,22 +43,32 @@ class JBossModulesAdapter implements JBossClassLoaderAdapter {
4343
private final Object delegatingTransformer;
4444

4545

46-
public JBossModulesAdapter(ClassLoader loader) {
47-
this.classLoader = loader;
46+
public JBossModulesAdapter(ClassLoader classLoader) {
47+
this.classLoader = classLoader;
4848
try {
49-
Field transformer = ReflectionUtils.findField(loader.getClass(), "transformer");
49+
Field transformer = ReflectionUtils.findField(classLoader.getClass(), "transformer");
50+
if (transformer == null) {
51+
throw new IllegalArgumentException("Could not find 'transformer' field on JBoss ClassLoader: " +
52+
classLoader.getClass().getName());
53+
}
5054
transformer.setAccessible(true);
51-
this.delegatingTransformer = transformer.get(loader);
55+
this.delegatingTransformer = transformer.get(classLoader);
5256
if (!this.delegatingTransformer.getClass().getName().equals(DELEGATING_TRANSFORMER_CLASS_NAME)) {
53-
throw new IllegalStateException("Transformer not of the expected type DelegatingClassFileTransformer: " +
57+
throw new IllegalStateException(
58+
"Transformer not of the expected type DelegatingClassFileTransformer: " +
5459
this.delegatingTransformer.getClass().getName());
5560
}
5661
this.addTransformer = ReflectionUtils.findMethod(this.delegatingTransformer.getClass(),
5762
"addTransformer", ClassFileTransformer.class);
63+
if (this.addTransformer == null) {
64+
throw new IllegalArgumentException(
65+
"Could not find 'addTransformer' method on JBoss DelegatingClassFileTransformer: " +
66+
this.delegatingTransformer.getClass().getName());
67+
}
5868
this.addTransformer.setAccessible(true);
5969
}
60-
catch (Exception ex) {
61-
throw new IllegalStateException("Could not initialize JBoss 7 LoadTimeWeaver", ex);
70+
catch (Throwable ex) {
71+
throw new IllegalStateException("Could not initialize JBoss LoadTimeWeaver", ex);
6272
}
6373
}
6474

@@ -67,7 +77,7 @@ public void addTransformer(ClassFileTransformer transformer) {
6777
try {
6878
this.addTransformer.invoke(this.delegatingTransformer, transformer);
6979
}
70-
catch (Exception ex) {
80+
catch (Throwable ex) {
7181
throw new IllegalStateException("Could not add transformer on JBoss 7 ClassLoader " + this.classLoader, ex);
7282
}
7383
}

spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/TomcatLoadTimeWeaver.java

Lines changed: 4 additions & 4 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.
@@ -76,7 +76,7 @@ public TomcatLoadTimeWeaver(ClassLoader classLoader) {
7676
}
7777
this.copyMethod = copyMethod;
7878
}
79-
catch (Exception ex) {
79+
catch (Throwable ex) {
8080
throw new IllegalStateException(
8181
"Could not initialize TomcatLoadTimeWeaver because Tomcat API classes are not available", ex);
8282
}
@@ -91,7 +91,7 @@ public void addTransformer(ClassFileTransformer transformer) {
9191
catch (InvocationTargetException ex) {
9292
throw new IllegalStateException("Tomcat addTransformer method threw exception", ex.getCause());
9393
}
94-
catch (Exception ex) {
94+
catch (Throwable ex) {
9595
throw new IllegalStateException("Could not invoke Tomcat addTransformer method", ex);
9696
}
9797
}
@@ -109,7 +109,7 @@ public ClassLoader getThrowawayClassLoader() {
109109
catch (InvocationTargetException ex) {
110110
throw new IllegalStateException("Tomcat copy method threw exception", ex.getCause());
111111
}
112-
catch (Exception ex) {
112+
catch (Throwable ex) {
113113
throw new IllegalStateException("Could not invoke Tomcat copy method", ex);
114114
}
115115
}

spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereClassLoaderAdapter.java

Lines changed: 6 additions & 6 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.
@@ -28,7 +28,6 @@
2828
import org.springframework.util.Assert;
2929

3030
/**
31-
*
3231
* Reflective wrapper around a WebSphere 7+ class loader. Used to
3332
* encapsulate the classloader-specific methods (discovered and
3433
* called through reflection) from the load-time weaver.
@@ -45,6 +44,7 @@ class WebSphereClassLoaderAdapter {
4544

4645
private static final String PLUGINS_FIELD = "preDefinePlugins";
4746

47+
4848
private ClassLoader classLoader;
4949

5050
private Class<?> wsPreProcessorClass;
@@ -68,13 +68,13 @@ public WebSphereClassLoaderAdapter(ClassLoader classLoader) {
6868
this.transformerList = wsCompoundClassLoaderClass.getDeclaredField(PLUGINS_FIELD);
6969
this.transformerList.setAccessible(true);
7070
}
71-
catch (Exception ex) {
71+
catch (Throwable ex) {
7272
throw new IllegalStateException(
7373
"Could not initialize WebSphere LoadTimeWeaver because WebSphere API classes are not available", ex);
7474
}
7575

7676
if (!wsCompoundClassLoaderClass.isInstance(classLoader)) {
77-
throw new IllegalArgumentException("ClassLoader must be instance of [" + COMPOUND_CLASS_LOADER_NAME + "]");
77+
throw new IllegalArgumentException("ClassLoader must be instance of " + COMPOUND_CLASS_LOADER_NAME);
7878
}
7979
this.classLoader = classLoader;
8080
}
@@ -95,7 +95,7 @@ public void addTransformer(ClassFileTransformer transformer) {
9595
catch (InvocationTargetException ex) {
9696
throw new IllegalStateException("WebSphere addPreDefinePlugin method threw exception", ex.getCause());
9797
}
98-
catch (Exception ex) {
98+
catch (Throwable ex) {
9999
throw new IllegalStateException("Could not invoke WebSphere addPreDefinePlugin method", ex);
100100
}
101101
}
@@ -111,7 +111,7 @@ public ClassLoader getThrowawayClassLoader() {
111111
catch (InvocationTargetException ex) {
112112
throw new IllegalStateException("WebSphere CompoundClassLoader constructor failed", ex.getCause());
113113
}
114-
catch (Exception ex) {
114+
catch (Throwable ex) {
115115
throw new IllegalStateException("Could not construct WebSphere CompoundClassLoader", ex);
116116
}
117117
}

0 commit comments

Comments
 (0)