Skip to content

Commit 8b5a013

Browse files
committed
Polishing
1 parent a73d9bb commit 8b5a013

File tree

12 files changed

+108
-128
lines changed

12 files changed

+108
-128
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -1384,8 +1384,8 @@ public Class<?> run() throws Exception {
13841384
catch (ClassNotFoundException ex) {
13851385
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex);
13861386
}
1387-
catch (LinkageError ex) {
1388-
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex);
1387+
catch (LinkageError err) {
1388+
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err);
13891389
}
13901390
}
13911391

spring-context/src/main/java/org/springframework/cache/interceptor/CacheProxyFactoryBean.java

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.beans.factory.BeanFactory;
2323
import org.springframework.beans.factory.BeanFactoryAware;
2424
import org.springframework.beans.factory.SmartInitializingSingleton;
25-
import org.springframework.cache.CacheManager;
2625

2726
/**
2827
* Proxy factory bean for simplified declarative caching handling.
@@ -54,50 +53,17 @@ public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean
5453

5554

5655
/**
57-
* Set the sources used to find cache operations.
56+
* Set one or more sources to find cache operations.
5857
* @see CacheInterceptor#setCacheOperationSources
5958
*/
6059
public void setCacheOperationSources(CacheOperationSource... cacheOperationSources) {
6160
this.cacheInterceptor.setCacheOperationSources(cacheOperationSources);
6261
}
6362

6463
/**
65-
* Set the default {@link KeyGenerator} that this cache aspect should delegate to
66-
* if no specific key generator has been set for the operation.
67-
* <p>The default is a {@link SimpleKeyGenerator}.
68-
* @since 5.0.3
69-
* @see CacheInterceptor#setKeyGenerator
70-
*/
71-
public void setKeyGenerator(KeyGenerator keyGenerator) {
72-
this.cacheInterceptor.setKeyGenerator(keyGenerator);
73-
}
74-
75-
/**
76-
* Set the default {@link CacheResolver} that this cache aspect should delegate
77-
* to if no specific cache resolver has been set for the operation.
78-
* <p>The default resolver resolves the caches against their names and the
79-
* default cache manager.
80-
* @since 5.0.3
81-
* @see CacheInterceptor#setCacheResolver
82-
*/
83-
public void setCacheResolver(CacheResolver cacheResolver) {
84-
this.cacheInterceptor.setCacheResolver(cacheResolver);
85-
}
86-
87-
/**
88-
* Set the {@link CacheManager} to use to create a default {@link CacheResolver}.
89-
* Replace the current {@link CacheResolver}, if any.
90-
* @since 5.0.3
91-
* @see CacheInterceptor#setCacheManager
92-
*/
93-
public void setCacheManager(CacheManager cacheManager) {
94-
this.cacheInterceptor.setCacheManager(cacheManager);
95-
}
96-
97-
/**
98-
* Set a pointcut, i.e a bean that can cause conditional invocation
99-
* of the CacheInterceptor depending on method and attributes passed.
100-
* Note: Additional interceptors are always invoked.
64+
* Set a pointcut, i.e. a bean that triggers conditional invocation of the
65+
* {@link CacheInterceptor} depending on the method and attributes passed.
66+
* <p>Note: Additional interceptors are always invoked.
10167
* @see #setPreInterceptors
10268
* @see #setPostInterceptors
10369
*/

spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java

Lines changed: 6 additions & 5 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-2018 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.
@@ -84,7 +84,8 @@
8484
* @see ResourceBundleMessageSource
8585
* @see java.util.ResourceBundle
8686
*/
87-
public class ReloadableResourceBundleMessageSource extends AbstractResourceBasedMessageSource implements ResourceLoaderAware {
87+
public class ReloadableResourceBundleMessageSource extends AbstractResourceBasedMessageSource
88+
implements ResourceLoaderAware {
8889

8990
private static final String PROPERTIES_SUFFIX = ".properties";
9091

@@ -99,15 +100,15 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
99100

100101
private ResourceLoader resourceLoader = new DefaultResourceLoader();
101102

102-
/** Cache to hold filename lists per Locale */
103+
// Cache to hold filename lists per Locale
103104
private final ConcurrentMap<String, Map<Locale, List<String>>> cachedFilenames =
104105
new ConcurrentHashMap<String, Map<Locale, List<String>>>();
105106

106-
/** Cache to hold already loaded properties per filename */
107+
// Cache to hold already loaded properties per filename
107108
private final ConcurrentMap<String, PropertiesHolder> cachedProperties =
108109
new ConcurrentHashMap<String, PropertiesHolder>();
109110

110-
/** Cache to hold merged loaded properties per locale */
111+
// Cache to hold merged loaded properties per locale
111112
private final ConcurrentMap<Locale, PropertiesHolder> cachedMergedProperties =
112113
new ConcurrentHashMap<Locale, PropertiesHolder>();
113114

spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java

Lines changed: 7 additions & 3 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-2018 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.
@@ -387,9 +387,13 @@ public long getTimeToLive(String baseName, Locale locale) {
387387
}
388388

389389
@Override
390-
public boolean needsReload(String baseName, Locale locale, String format, ClassLoader loader, ResourceBundle bundle, long loadTime) {
390+
public boolean needsReload(
391+
String baseName, Locale locale, String format, ClassLoader loader, ResourceBundle bundle, long loadTime) {
392+
391393
if (super.needsReload(baseName, locale, format, loader, bundle, loadTime)) {
392-
cachedBundleMessageFormats.remove(bundle);
394+
synchronized (cachedBundleMessageFormats) {
395+
cachedBundleMessageFormats.remove(bundle);
396+
}
393397
return true;
394398
}
395399
else {

spring-context/src/main/java/org/springframework/context/weaving/DefaultContextLoadTimeWeaver.java

Lines changed: 19 additions & 12 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-2018 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.
@@ -67,6 +67,7 @@ public DefaultContextLoadTimeWeaver(ClassLoader beanClassLoader) {
6767
setBeanClassLoader(beanClassLoader);
6868
}
6969

70+
7071
@Override
7172
public void setBeanClassLoader(ClassLoader classLoader) {
7273
LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
@@ -84,8 +85,10 @@ else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
8485
else {
8586
try {
8687
this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
87-
logger.info("Using a reflective load-time weaver for class loader: " +
88-
this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
88+
if (logger.isInfoEnabled()) {
89+
logger.info("Using a reflective load-time weaver for class loader: " +
90+
this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
91+
}
8992
}
9093
catch (IllegalStateException ex) {
9194
throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
@@ -106,33 +109,37 @@ else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
106109
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
107110
String name = classLoader.getClass().getName();
108111
try {
109-
if (name.startsWith("weblogic")) {
110-
return new WebLogicLoadTimeWeaver(classLoader);
112+
if (name.startsWith("org.apache.catalina")) {
113+
return new TomcatLoadTimeWeaver(classLoader);
111114
}
112115
else if (name.startsWith("org.glassfish")) {
113116
return new GlassFishLoadTimeWeaver(classLoader);
114117
}
115-
else if (name.startsWith("org.apache.catalina")) {
116-
return new TomcatLoadTimeWeaver(classLoader);
117-
}
118118
else if (name.startsWith("org.jboss")) {
119119
return new JBossLoadTimeWeaver(classLoader);
120120
}
121121
else if (name.startsWith("com.ibm")) {
122122
return new WebSphereLoadTimeWeaver(classLoader);
123123
}
124+
else if (name.startsWith("weblogic")) {
125+
return new WebLogicLoadTimeWeaver(classLoader);
126+
}
124127
}
125-
catch (IllegalStateException ex) {
126-
logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
128+
catch (Exception ex) {
129+
if (logger.isInfoEnabled()) {
130+
logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
131+
}
127132
}
128133
return null;
129134
}
130135

131136
@Override
132137
public void destroy() {
133138
if (this.loadTimeWeaver instanceof InstrumentationLoadTimeWeaver) {
134-
logger.info("Removing all registered transformers for class loader: " +
135-
this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
139+
if (logger.isInfoEnabled()) {
140+
logger.info("Removing all registered transformers for class loader: " +
141+
this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
142+
}
136143
((InstrumentationLoadTimeWeaver) this.loadTimeWeaver).removeTransformers();
137144
}
138145
}

spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -23,6 +23,8 @@
2323
import joptsimple.OptionSet;
2424
import joptsimple.OptionSpec;
2525

26+
import org.springframework.util.StringUtils;
27+
2628
/**
2729
* {@link CommandLinePropertySource} implementation backed by a JOpt {@link OptionSet}.
2830
*
@@ -84,13 +86,13 @@ protected boolean containsOption(String name) {
8486
public String[] getPropertyNames() {
8587
List<String> names = new ArrayList<String>();
8688
for (OptionSpec<?> spec : this.source.specs()) {
87-
List<String> aliases = new ArrayList<String>(spec.options());
89+
List<String> aliases = spec.options();
8890
if (!aliases.isEmpty()) {
8991
// Only the longest name is used for enumerating
9092
names.add(aliases.get(aliases.size() - 1));
9193
}
9294
}
93-
return names.toArray(new String[names.size()]);
95+
return StringUtils.toStringArray(names);
9496
}
9597

9698
@Override

spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java

Lines changed: 4 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-2018 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.
@@ -149,10 +149,8 @@ public void exitCompilationScope() {
149149
* Return the descriptor for the item currently on top of the stack (in the current scope).
150150
*/
151151
public String lastDescriptor() {
152-
if (this.compilationScopes.peek().isEmpty()) {
153-
return null;
154-
}
155-
return this.compilationScopes.peek().get(this.compilationScopes.peek().size() - 1);
152+
ArrayList<String> scopes = this.compilationScopes.peek();
153+
return (!scopes.isEmpty() ? scopes.get(scopes.size() - 1) : null);
156154
}
157155

158156
/**
@@ -161,7 +159,7 @@ public String lastDescriptor() {
161159
* @param mv the visitor into which new instructions should be inserted
162160
*/
163161
public void unboxBooleanIfNecessary(MethodVisitor mv) {
164-
if (lastDescriptor().equals("Ljava/lang/Boolean")) {
162+
if ("Ljava/lang/Boolean".equals(lastDescriptor())) {
165163
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
166164
}
167165
}

spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
7070
if (value == TypedValue.NULL) {
7171
throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_NOT_DEFINED, this.name);
7272
}
73-
74-
// Two possibilities: a lambda function or a Java static method registered as a function
7573
if (!(value.getValue() instanceof Method)) {
74+
// Two possibilities: a lambda function or a Java static method registered as a function
7675
throw new SpelEvaluationException(
7776
SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass());
7877
}
@@ -96,11 +95,13 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
9695
private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException {
9796
Object[] functionArgs = getArguments(state);
9897

99-
if (!method.isVarArgs() && method.getParameterCount() != functionArgs.length) {
100-
throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
101-
functionArgs.length, method.getParameterCount());
98+
if (!method.isVarArgs()) {
99+
int declaredParamCount = method.getParameterTypes().length;
100+
if (declaredParamCount != functionArgs.length) {
101+
throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
102+
functionArgs.length, declaredParamCount);
103+
}
102104
}
103-
// Only static methods can be called in this way
104105
if (!Modifier.isStatic(method.getModifiers())) {
105106
throw new SpelEvaluationException(getStartPosition(),
106107
SpelMessage.FUNCTION_MUST_BE_STATIC, ClassUtils.getQualifiedMethodName(method), this.name);

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -51,43 +51,43 @@
5151
*/
5252
public class CallMetaDataContext {
5353

54-
/** Logger available to subclasses */
54+
// Logger available to subclasses
5555
protected final Log logger = LogFactory.getLog(getClass());
5656

57-
/** name of procedure to call **/
57+
// Name of procedure to call
5858
private String procedureName;
5959

60-
/** name of catalog for call **/
60+
// Name of catalog for call
6161
private String catalogName;
6262

63-
/** name of schema for call **/
63+
// Name of schema for call
6464
private String schemaName;
6565

66-
/** List of SqlParameter objects to be used in call execution */
66+
// List of SqlParameter objects to be used in call execution
6767
private List<SqlParameter> callParameters = new ArrayList<SqlParameter>();
6868

69-
/** Actual name to use for the return value in the output map */
69+
// Actual name to use for the return value in the output map
7070
private String actualFunctionReturnName;
7171

72-
/** Set of in parameter names to exclude use for any not listed */
72+
// Set of in parameter names to exclude use for any not listed
7373
private Set<String> limitedInParameterNames = new HashSet<String>();
7474

75-
/** List of SqlParameter names for out parameters */
75+
// List of SqlParameter names for out parameters
7676
private List<String> outParameterNames = new ArrayList<String>();
7777

78-
/** Indicates whether this is a procedure or a function **/
78+
// Indicates whether this is a procedure or a function
7979
private boolean function = false;
8080

81-
/** Indicates whether this procedure's return value should be included **/
81+
// Indicates whether this procedure's return value should be included
8282
private boolean returnValueRequired = false;
8383

84-
/** Should we access call parameter meta data info or not */
84+
// Should we access call parameter meta data info or not
8585
private boolean accessCallParameterMetaData = true;
8686

87-
/** Should we bind parameter by name **/
87+
// Should we bind parameter by name
8888
private boolean namedBinding;
8989

90-
/** The provider of call meta data */
90+
// The provider of call meta data
9191
private CallMetaDataProvider metaDataProvider;
9292

9393

0 commit comments

Comments
 (0)