Skip to content

Commit 6f2e61b

Browse files
committed
Polishing
(cherry picked from commit c97c246)
1 parent 63733c4 commit 6f2e61b

File tree

4 files changed

+57
-47
lines changed

4 files changed

+57
-47
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.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-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.
@@ -258,7 +258,7 @@ else if ("custom".equals(filterType)) {
258258

259259
@SuppressWarnings("unchecked")
260260
private Object instantiateUserDefinedStrategy(String className, Class<?> strategyType, ClassLoader classLoader) {
261-
Object result = null;
261+
Object result;
262262
try {
263263
result = classLoader.loadClass(className).newInstance();
264264
}
@@ -268,7 +268,7 @@ private Object instantiateUserDefinedStrategy(String className, Class<?> strateg
268268
}
269269
catch (Exception ex) {
270270
throw new IllegalArgumentException("Unable to instantiate class [" + className + "] for strategy [" +
271-
strategyType.getName() + "]. A zero-argument constructor is required", ex);
271+
strategyType.getName() + "]: a zero-argument constructor is required", ex);
272272
}
273273

274274
if (!strategyType.isAssignableFrom(result.getClass())) {

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

Lines changed: 33 additions & 31 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.
@@ -103,8 +103,8 @@ private Map<Member, String[]> inspectClass(Class<?> clazz) {
103103
// We couldn't load the class file, which is not fatal as it
104104
// simply means this method of discovering parameter names won't work.
105105
if (logger.isDebugEnabled()) {
106-
logger.debug("Cannot find '.class' file for class [" + clazz
107-
+ "] - unable to determine constructors/methods parameter names");
106+
logger.debug("Cannot find '.class' file for class [" + clazz +
107+
"] - unable to determine constructor/method parameter names");
108108
}
109109
return NO_DEBUG_INFO_MAP;
110110
}
@@ -117,14 +117,14 @@ private Map<Member, String[]> inspectClass(Class<?> clazz) {
117117
catch (IOException ex) {
118118
if (logger.isDebugEnabled()) {
119119
logger.debug("Exception thrown while reading '.class' file for class [" + clazz +
120-
"] - unable to determine constructors/methods parameter names", ex);
120+
"] - unable to determine constructor/method parameter names", ex);
121121
}
122122
}
123123
catch (IllegalArgumentException ex) {
124124
if (logger.isDebugEnabled()) {
125125
logger.debug("ASM ClassReader failed to parse class file [" + clazz +
126126
"], probably due to a new Java class file version that isn't supported yet " +
127-
"- unable to determine constructors/methods parameter names", ex);
127+
"- unable to determine constructor/method parameter names", ex);
128128
}
129129
}
130130
finally {
@@ -148,6 +148,7 @@ private static class ParameterNameDiscoveringVisitor extends ClassVisitor {
148148
private static final String STATIC_CLASS_INIT = "<clinit>";
149149

150150
private final Class<?> clazz;
151+
151152
private final Map<Member, String[]> memberMap;
152153

153154
public ParameterNameDiscoveringVisitor(Class<?> clazz, Map<Member, String[]> memberMap) {
@@ -180,12 +181,17 @@ private static class LocalVariableTableVisitor extends MethodVisitor {
180181
private static final String CONSTRUCTOR = "<init>";
181182

182183
private final Class<?> clazz;
184+
183185
private final Map<Member, String[]> memberMap;
186+
184187
private final String name;
188+
185189
private final Type[] args;
190+
191+
private final String[] parameterNames;
192+
186193
private final boolean isStatic;
187194

188-
private String[] parameterNames;
189195
private boolean hasLvtInfo = false;
190196

191197
/*
@@ -194,25 +200,22 @@ private static class LocalVariableTableVisitor extends MethodVisitor {
194200
*/
195201
private final int[] lvtSlotIndex;
196202

197-
public LocalVariableTableVisitor(Class<?> clazz, Map<Member, String[]> map, String name, String desc,
198-
boolean isStatic) {
203+
public LocalVariableTableVisitor(Class<?> clazz, Map<Member, String[]> map, String name, String desc, boolean isStatic) {
199204
super(SpringAsmInfo.ASM_VERSION);
200205
this.clazz = clazz;
201206
this.memberMap = map;
202207
this.name = name;
203-
// determine args
204-
args = Type.getArgumentTypes(desc);
205-
this.parameterNames = new String[args.length];
208+
this.args = Type.getArgumentTypes(desc);
209+
this.parameterNames = new String[this.args.length];
206210
this.isStatic = isStatic;
207-
this.lvtSlotIndex = computeLvtSlotIndices(isStatic, args);
211+
this.lvtSlotIndex = computeLvtSlotIndices(isStatic, this.args);
208212
}
209213

210214
@Override
211-
public void visitLocalVariable(String name, String description, String signature, Label start, Label end,
212-
int index) {
215+
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
213216
this.hasLvtInfo = true;
214-
for (int i = 0; i < lvtSlotIndex.length; i++) {
215-
if (lvtSlotIndex[i] == index) {
217+
for (int i = 0; i < this.lvtSlotIndex.length; i++) {
218+
if (this.lvtSlotIndex[i] == index) {
216219
this.parameterNames[i] = name;
217220
}
218221
}
@@ -225,27 +228,25 @@ public void visitEnd() {
225228
// which doesn't use any local variables.
226229
// This means that hasLvtInfo could be false for that kind of methods
227230
// even if the class has local variable info.
228-
memberMap.put(resolveMember(), parameterNames);
231+
this.memberMap.put(resolveMember(), this.parameterNames);
229232
}
230233
}
231234

232235
private Member resolveMember() {
233-
ClassLoader loader = clazz.getClassLoader();
234-
Class<?>[] classes = new Class<?>[args.length];
235-
236-
// resolve args
237-
for (int i = 0; i < args.length; i++) {
238-
classes[i] = ClassUtils.resolveClassName(args[i].getClassName(), loader);
236+
ClassLoader loader = this.clazz.getClassLoader();
237+
Class<?>[] argTypes = new Class<?>[this.args.length];
238+
for (int i = 0; i < this.args.length; i++) {
239+
argTypes[i] = ClassUtils.resolveClassName(this.args[i].getClassName(), loader);
239240
}
240241
try {
241-
if (CONSTRUCTOR.equals(name)) {
242-
return clazz.getDeclaredConstructor(classes);
242+
if (CONSTRUCTOR.equals(this.name)) {
243+
return this.clazz.getDeclaredConstructor(argTypes);
243244
}
244-
245-
return clazz.getDeclaredMethod(name, classes);
246-
} catch (NoSuchMethodException ex) {
247-
throw new IllegalStateException("Method [" + name
248-
+ "] was discovered in the .class file but cannot be resolved in the class object", ex);
245+
return this.clazz.getDeclaredMethod(this.name, argTypes);
246+
}
247+
catch (NoSuchMethodException ex) {
248+
throw new IllegalStateException("Method [" + this.name +
249+
"] was discovered in the .class file but cannot be resolved in the class object", ex);
249250
}
250251
}
251252

@@ -256,7 +257,8 @@ private static int[] computeLvtSlotIndices(boolean isStatic, Type[] paramTypes)
256257
lvtIndex[i] = nextIndex;
257258
if (isWideType(paramTypes[i])) {
258259
nextIndex += 2;
259-
} else {
260+
}
261+
else {
260262
nextIndex++;
261263
}
262264
}

spring-oxm/src/main/java/org/springframework/oxm/xmlbeans/XmlBeansMarshaller.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public boolean supports(Class<?> clazz) {
125125

126126
@Override
127127
protected void marshalDomNode(Object graph, Node node) throws XmlMappingException {
128-
Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument();
128+
Document document = (node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument());
129129
Node xmlBeansNode = ((XmlObject) graph).newDomNode(getXmlOptions());
130130
NodeList xmlBeansChildNodes = xmlBeansNode.getChildNodes();
131131
for (int i = 0; i < xmlBeansChildNodes.getLength(); i++) {
@@ -277,19 +277,27 @@ protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOEx
277277
*/
278278
protected void validate(XmlObject object) throws ValidationFailureException {
279279
if (isValidating() && object != null) {
280-
// create a temporary xmlOptions just for validation
281-
XmlOptions validateOptions = getXmlOptions() != null ? getXmlOptions() : new XmlOptions();
280+
XmlOptions validateOptions = getXmlOptions();
281+
if (validateOptions == null) {
282+
// Create temporary XmlOptions just for validation
283+
validateOptions = new XmlOptions();
284+
}
282285
List<XmlError> errorsList = new ArrayList<XmlError>();
283286
validateOptions.setErrorListener(errorsList);
284287
if (!object.validate(validateOptions)) {
285-
StringBuilder builder = new StringBuilder("Could not validate XmlObject :");
288+
StringBuilder sb = new StringBuilder("Failed to validate XmlObject: ");
289+
boolean first = true;
286290
for (XmlError error : errorsList) {
287291
if (error instanceof XmlValidationError) {
288-
builder.append(error.toString());
292+
if (!first) {
293+
sb.append("; ");
294+
}
295+
sb.append(error.toString());
296+
first = false;
289297
}
290298
}
291299
throw new ValidationFailureException("XMLBeans validation failure",
292-
new XmlException(builder.toString(), null, errorsList));
300+
new XmlException(sb.toString(), null, errorsList));
293301
}
294302
}
295303
}
@@ -306,7 +314,7 @@ protected void validate(XmlObject object) throws ValidationFailureException {
306314
*/
307315
protected XmlMappingException convertXmlBeansException(Exception ex, boolean marshalling) {
308316
if (ex instanceof XMLStreamValidationException) {
309-
return new ValidationFailureException("XmlBeans validation exception", ex);
317+
return new ValidationFailureException("XMLBeans validation exception", ex);
310318
}
311319
else if (ex instanceof XmlException || ex instanceof SAXException) {
312320
if (marshalling) {

spring-web/src/main/java/org/springframework/web/filter/OncePerRequestFilter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545
* and so on. This mechanism complements and does not replace the need to
4646
* configure a filter in {@code web.xml} with dispatcher types.
4747
*
48-
* <p>Sub-classes may use {@link #isAsyncDispatch(HttpServletRequest)} to
49-
* determine when a filter is invoked as part of an async dispatch, and
50-
* use {@link #isAsyncStarted(HttpServletRequest)} to determine when the
51-
* request has been placed in async mode and therefore the current dispatch
52-
* won't be the last one.
48+
* <p>Subclasses may use {@link #isAsyncDispatch(HttpServletRequest)} to
49+
* determine when a filter is invoked as part of an async dispatch, and use
50+
* {@link #isAsyncStarted(HttpServletRequest)} to determine when the request
51+
* has been placed in async mode and therefore the current dispatch won't be
52+
* the last one for the given request.
5353
*
5454
* <p>Yet another dispatch type that also occurs in its own thread is
55-
* {@link javax.servlet.DispatcherType#ERROR ERROR}. Sub-classes can override
55+
* {@link javax.servlet.DispatcherType#ERROR ERROR}. Subclasses can override
5656
* {@link #shouldNotFilterErrorDispatch()} if they wish to declare statically
5757
* if they should be invoked <em>once</em> during error dispatches.
5858
*

0 commit comments

Comments
 (0)