Skip to content

Commit 144f687

Browse files
committed
Polishing
(cherry picked from commit 2f9ed59)
1 parent 0ee8322 commit 144f687

File tree

8 files changed

+47
-71
lines changed

8 files changed

+47
-71
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void registerApplicationContext(ConfigurableApplicationContext applicatio
7171
server.registerMBean(new LiveBeansView(),
7272
new ObjectName(mbeanDomain, MBEAN_APPLICATION_KEY, applicationName));
7373
}
74-
catch (Exception ex) {
74+
catch (Throwable ex) {
7575
throw new ApplicationContextException("Failed to register LiveBeansView MBean", ex);
7676
}
7777
}
@@ -88,7 +88,7 @@ static void unregisterApplicationContext(ConfigurableApplicationContext applicat
8888
String mbeanDomain = applicationContext.getEnvironment().getProperty(MBEAN_DOMAIN_PROPERTY_NAME);
8989
server.unregisterMBean(new ObjectName(mbeanDomain, MBEAN_APPLICATION_KEY, applicationName));
9090
}
91-
catch (Exception ex) {
91+
catch (Throwable ex) {
9292
throw new ApplicationContextException("Failed to unregister LiveBeansView MBean", ex);
9393
} finally {
9494
applicationName = null;

spring-context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class CustomNamespaceHandlerTests {
8282

8383
private GenericApplicationContext beanFactory;
8484

85+
8586
@Before
8687
public void setUp() throws Exception {
8788
NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS);
@@ -148,30 +149,21 @@ public void testDecorationViaAttribute() throws Exception {
148149
assertEquals("foo", beanDefinition.getAttribute("objectName"));
149150
}
150151

151-
/**
152-
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
153-
*/
154-
@Test
152+
@Test // SPR-2728
155153
public void testCustomElementNestedWithinUtilList() throws Exception {
156154
List<?> things = (List<?>) this.beanFactory.getBean("list.of.things");
157155
assertNotNull(things);
158156
assertEquals(2, things.size());
159157
}
160158

161-
/**
162-
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
163-
*/
164-
@Test
159+
@Test // SPR-2728
165160
public void testCustomElementNestedWithinUtilSet() throws Exception {
166161
Set<?> things = (Set<?>) this.beanFactory.getBean("set.of.things");
167162
assertNotNull(things);
168163
assertEquals(2, things.size());
169164
}
170165

171-
/**
172-
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
173-
*/
174-
@Test
166+
@Test // SPR-2728
175167
public void testCustomElementNestedWithinUtilMap() throws Exception {
176168
Map<?, ?> things = (Map<?, ?>) this.beanFactory.getBean("map.of.things");
177169
assertNotNull(things);
@@ -229,6 +221,7 @@ public void init() {
229221
registerBeanDefinitionDecoratorForAttribute("object-name", new ObjectNameBeanDefinitionDecorator());
230222
}
231223

224+
232225
private static class TestBeanDefinitionParser implements BeanDefinitionParser {
233226

234227
@Override
@@ -247,6 +240,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
247240
}
248241
}
249242

243+
250244
private static final class PersonDefinitionParser extends AbstractSingleBeanDefinitionParser {
251245

252246
@Override
@@ -261,6 +255,7 @@ protected void doParse(Element element, BeanDefinitionBuilder builder) {
261255
}
262256
}
263257

258+
264259
private static class PropertyModifyingBeanDefinitionDecorator implements BeanDefinitionDecorator {
265260

266261
@Override
@@ -277,6 +272,7 @@ public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition,
277272
}
278273
}
279274

275+
280276
private static class DebugBeanDefinitionDecorator extends AbstractInterceptorDrivenBeanDefinitionDecorator {
281277

282278
@Override
@@ -285,6 +281,7 @@ protected BeanDefinition createInterceptorDefinition(Node node) {
285281
}
286282
}
287283

284+
288285
private static class NopInterceptorBeanDefinitionDecorator extends AbstractInterceptorDrivenBeanDefinitionDecorator {
289286

290287
@Override
@@ -293,6 +290,7 @@ protected BeanDefinition createInterceptorDefinition(Node node) {
293290
}
294291
}
295292

293+
296294
private static class ObjectNameBeanDefinitionDecorator implements BeanDefinitionDecorator {
297295

298296
@Override
@@ -302,5 +300,5 @@ public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition,
302300
return definition;
303301
}
304302
}
305-
}
306303

304+
}

spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* @author Juergen Hoeller
3838
* @author Sam Brannen
3939
* @since 1.2.6
40+
* @see Resource#getInputStream()
4041
* @see java.io.Reader
4142
* @see java.nio.charset.Charset
4243
*/
@@ -142,8 +143,8 @@ else if (this.encoding != null) {
142143
}
143144

144145
/**
145-
* Open a {@code java.io.InputStream} for the specified resource, ignoring any
146-
* specified {@link #getCharset() Charset} or {@linkplain #getEncoding() encoding}.
146+
* Open an {@code InputStream} for the specified resource, ignoring any specified
147+
* {@link #getCharset() Charset} or {@linkplain #getEncoding() encoding}.
147148
* @throws IOException if opening the InputStream failed
148149
* @see #requiresReader()
149150
* @see #getReader()
Lines changed: 4 additions & 11 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-2016 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.
@@ -18,29 +18,22 @@
1818

1919
import org.springframework.core.io.ClassPathResource;
2020

21-
import static java.lang.String.*;
22-
2321
/**
2422
* Convenience utilities for common operations with test resources.
2523
*
2624
* @author Chris Beams
2725
*/
28-
public class TestResourceUtils {
26+
public abstract class TestResourceUtils {
2927

3028
/**
31-
* Loads a {@link ClassPathResource} qualified by the simple name of clazz,
29+
* Load a {@link ClassPathResource} qualified by the simple name of clazz,
3230
* and relative to the package for clazz.
33-
*
3431
* <p>Example: given a clazz 'com.foo.BarTests' and a resourceSuffix of 'context.xml',
3532
* this method will return a ClassPathResource representing com/foo/BarTests-context.xml
36-
*
3733
* <p>Intended for use loading context configuration XML files within JUnit tests.
38-
*
39-
* @param clazz
40-
* @param resourceSuffix
4134
*/
4235
public static ClassPathResource qualifiedResource(Class<?> clazz, String resourceSuffix) {
43-
return new ClassPathResource(format("%s-%s", clazz.getSimpleName(), resourceSuffix), clazz);
36+
return new ClassPathResource(String.format("%s-%s", clazz.getSimpleName(), resourceSuffix), clazz);
4437
}
4538

4639
}

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -40,8 +40,8 @@ public abstract class DatabasePopulatorUtils {
4040
* @throws DataAccessException if an error occurs, specifically a {@link ScriptException}
4141
*/
4242
public static void execute(DatabasePopulator populator, DataSource dataSource) throws DataAccessException {
43-
Assert.notNull(populator, "DatabasePopulator must be provided");
44-
Assert.notNull(dataSource, "DataSource must be provided");
43+
Assert.notNull(populator, "DatabasePopulator must not be null");
44+
Assert.notNull(dataSource, "DataSource must not be null");
4545
try {
4646
Connection connection = DataSourceUtils.getConnection(dataSource);
4747
try {
@@ -53,11 +53,10 @@ public static void execute(DatabasePopulator populator, DataSource dataSource) t
5353
}
5454
}
5555
}
56-
catch (Exception ex) {
56+
catch (Throwable ex) {
5757
if (ex instanceof ScriptException) {
5858
throw (ScriptException) ex;
5959
}
60-
6160
throw new UncategorizedScriptException("Failed to execute database script", ex);
6261
}
6362
}

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
*/
5353
public class ResourceDatabasePopulator implements DatabasePopulator {
5454

55-
private List<Resource> scripts = new ArrayList<Resource>();
55+
List<Resource> scripts = new ArrayList<Resource>();
5656

5757
private String sqlScriptEncoding;
5858

@@ -117,7 +117,7 @@ public ResourceDatabasePopulator(boolean continueOnError, boolean ignoreFailedDr
117117
*/
118118
public void addScript(Resource script) {
119119
Assert.notNull(script, "Script must not be null");
120-
getScripts().add(script);
120+
this.scripts.add(script);
121121
}
122122

123123
/**
@@ -126,7 +126,7 @@ public void addScript(Resource script) {
126126
*/
127127
public void addScripts(Resource... scripts) {
128128
assertContentsOfScriptArray(scripts);
129-
getScripts().addAll(Arrays.asList(scripts));
129+
this.scripts.addAll(Arrays.asList(scripts));
130130
}
131131

132132
/**
@@ -140,6 +140,11 @@ public void setScripts(Resource... scripts) {
140140
this.scripts = new ArrayList<Resource>(Arrays.asList(scripts));
141141
}
142142

143+
private void assertContentsOfScriptArray(Resource... scripts) {
144+
Assert.notNull(scripts, "Scripts array must not be null");
145+
Assert.noNullElements(scripts, "Scripts array must not contain null elements");
146+
}
147+
143148
/**
144149
* Specify the encoding for the configured SQL scripts, if different from the
145150
* platform encoding.
@@ -220,17 +225,18 @@ public void setIgnoreFailedDrops(boolean ignoreFailedDrops) {
220225
this.ignoreFailedDrops = ignoreFailedDrops;
221226
}
222227

228+
223229
/**
224230
* {@inheritDoc}
225231
* @see #execute(DataSource)
226232
*/
227233
@Override
228234
public void populate(Connection connection) throws ScriptException {
229235
Assert.notNull(connection, "Connection must not be null");
230-
for (Resource script : getScripts()) {
231-
ScriptUtils.executeSqlScript(connection, encodeScript(script), this.continueOnError,
232-
this.ignoreFailedDrops, this.commentPrefix, this.separator, this.blockCommentStartDelimiter,
233-
this.blockCommentEndDelimiter);
236+
for (Resource script : this.scripts) {
237+
EncodedResource encodedScript = new EncodedResource(script, this.sqlScriptEncoding);
238+
ScriptUtils.executeSqlScript(connection, encodedScript, this.continueOnError, this.ignoreFailedDrops,
239+
this.commentPrefix, this.separator, this.blockCommentStartDelimiter, this.blockCommentEndDelimiter);
234240
}
235241
}
236242

@@ -244,28 +250,7 @@ public void populate(Connection connection) throws ScriptException {
244250
* @see #populate(Connection)
245251
*/
246252
public void execute(DataSource dataSource) throws ScriptException {
247-
Assert.notNull(dataSource, "DataSource must not be null");
248253
DatabasePopulatorUtils.execute(this, dataSource);
249254
}
250255

251-
final List<Resource> getScripts() {
252-
return this.scripts;
253-
}
254-
255-
/**
256-
* {@link EncodedResource} is not a sub-type of {@link Resource}. Thus we
257-
* always need to wrap each script resource in an {@code EncodedResource}
258-
* using the configured {@linkplain #setSqlScriptEncoding encoding}.
259-
* @param script the script to wrap (never {@code null})
260-
*/
261-
private EncodedResource encodeScript(Resource script) {
262-
Assert.notNull(script, "Script must not be null");
263-
return new EncodedResource(script, this.sqlScriptEncoding);
264-
}
265-
266-
private void assertContentsOfScriptArray(Resource... scripts) {
267-
Assert.notNull(scripts, "Scripts must not be null");
268-
Assert.noNullElements(scripts, "Scripts array must not contain null elements");
269-
}
270-
271256
}

spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulatorTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -50,22 +50,22 @@ public void constructWithNullResourceArray() {
5050
@Test
5151
public void constructWithResource() {
5252
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1);
53-
assertEquals(1, databasePopulator.getScripts().size());
53+
assertEquals(1, databasePopulator.scripts.size());
5454
}
5555

5656
@Test
5757
public void constructWithMultipleResources() {
5858
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2);
59-
assertEquals(2, databasePopulator.getScripts().size());
59+
assertEquals(2, databasePopulator.scripts.size());
6060
}
6161

6262
@Test
6363
public void constructWithMultipleResourcesAndThenAddScript() {
6464
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(script1, script2);
65-
assertEquals(2, databasePopulator.getScripts().size());
65+
assertEquals(2, databasePopulator.scripts.size());
6666

6767
databasePopulator.addScript(script3);
68-
assertEquals(3, databasePopulator.getScripts().size());
68+
assertEquals(3, databasePopulator.scripts.size());
6969
}
7070

7171
@Test(expected = IllegalArgumentException.class)
@@ -95,13 +95,13 @@ public void setScriptsWithNullResourceArray() {
9595
@Test
9696
public void setScriptsAndThenAddScript() {
9797
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
98-
assertEquals(0, databasePopulator.getScripts().size());
98+
assertEquals(0, databasePopulator.scripts.size());
9999

100100
databasePopulator.setScripts(script1, script2);
101-
assertEquals(2, databasePopulator.getScripts().size());
101+
assertEquals(2, databasePopulator.scripts.size());
102102

103103
databasePopulator.addScript(script3);
104-
assertEquals(3, databasePopulator.getScripts().size());
104+
assertEquals(3, databasePopulator.scripts.size());
105105
}
106106

107107
}

spring-messaging/src/main/java/org/springframework/messaging/MessageChannel.java

Lines changed: 2 additions & 2 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-2016 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.
@@ -27,7 +27,7 @@ public interface MessageChannel {
2727
/**
2828
* Constant for sending a message without a prescribed timeout.
2929
*/
30-
public static final long INDEFINITE_TIMEOUT = -1;
30+
long INDEFINITE_TIMEOUT = -1;
3131

3232

3333
/**

0 commit comments

Comments
 (0)