Skip to content

Commit 0f0da73

Browse files
committed
Polishing
1 parent 54c1f40 commit 0f0da73

File tree

25 files changed

+180
-194
lines changed

25 files changed

+180
-194
lines changed

spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -209,13 +209,12 @@ public String[] getAliases(String name) {
209209
@SuppressWarnings("unchecked")
210210
private <T> T doGetSingleton(String name, @Nullable Class<T> requiredType) throws NamingException {
211211
synchronized (this.singletonObjects) {
212-
if (this.singletonObjects.containsKey(name)) {
213-
Object jndiObject = this.singletonObjects.get(name);
214-
if (requiredType != null && !requiredType.isInstance(jndiObject)) {
215-
throw new TypeMismatchNamingException(
216-
convertJndiName(name), requiredType, (jndiObject != null ? jndiObject.getClass() : null));
212+
Object singleton = this.singletonObjects.get(name);
213+
if (singleton != null) {
214+
if (requiredType != null && !requiredType.isInstance(singleton)) {
215+
throw new TypeMismatchNamingException(convertJndiName(name), requiredType, singleton.getClass());
217216
}
218-
return (T) jndiObject;
217+
return (T) singleton;
219218
}
220219
T jndiObject = lookup(name, requiredType);
221220
this.singletonObjects.put(name, jndiObject);
@@ -229,14 +228,12 @@ private Class<?> doGetType(String name) throws NamingException {
229228
}
230229
else {
231230
synchronized (this.resourceTypes) {
232-
if (this.resourceTypes.containsKey(name)) {
233-
return this.resourceTypes.get(name);
234-
}
235-
else {
236-
Class<?> type = lookup(name, null).getClass();
231+
Class<?> type = this.resourceTypes.get(name);
232+
if (type == null) {
233+
type = lookup(name, null).getClass();
237234
this.resourceTypes.put(name, type);
238-
return type;
239235
}
236+
return type;
240237
}
241238
}
242239
}

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
*
4242
* <p>By default, depending on classpath availability, adapters are registered
4343
* for Reactor, RxJava 1, RxJava 2 types, {@link CompletableFuture}, and Java 9+
44-
* Flow.Publisher.
44+
* {@code Flow.Publisher}.
4545
*
4646
* @author Rossen Stoyanchev
4747
* @author Sebastien Deleuze
@@ -54,7 +54,7 @@ public class ReactiveAdapterRegistry {
5454

5555
private final boolean reactorPresent;
5656

57-
private final List<ReactiveAdapter> adapters = new ArrayList<>(32);
57+
private final List<ReactiveAdapter> adapters = new ArrayList<>();
5858

5959

6060
/**
@@ -112,13 +112,13 @@ public boolean hasAdapters() {
112112

113113
/**
114114
* Register a reactive type along with functions to adapt to and from a
115-
* Reactive Streams {@link Publisher}. The functions can assume their
116-
* input is never be {@code null} nor {@link Optional}.
115+
* Reactive Streams {@link Publisher}. The function arguments assume that
116+
* their input is neither {@code null} nor {@link Optional}.
117117
*/
118118
public void registerReactiveType(ReactiveTypeDescriptor descriptor,
119119
Function<Object, Publisher<?>> toAdapter, Function<Publisher<?>, Object> fromAdapter) {
120120

121-
if (reactorPresent) {
121+
if (this.reactorPresent) {
122122
this.adapters.add(new ReactorAdapter(descriptor, toAdapter, fromAdapter));
123123
}
124124
else {
@@ -128,6 +128,7 @@ public void registerReactiveType(ReactiveTypeDescriptor descriptor,
128128

129129
/**
130130
* Get the adapter for the given reactive type.
131+
* @return the corresponding adapter, or {@code null} if none available
131132
*/
132133
@Nullable
133134
public ReactiveAdapter getAdapter(Class<?> reactiveType) {
@@ -141,6 +142,7 @@ public ReactiveAdapter getAdapter(Class<?> reactiveType) {
141142
* (may be {@code null} if a concrete source object is given)
142143
* @param source an instance of the reactive type
143144
* (i.e. to adapt from; may be {@code null} if the reactive type is specified)
145+
* @return the corresponding adapter, or {@code null} if none available
144146
*/
145147
@Nullable
146148
public ReactiveAdapter getAdapter(@Nullable Class<?> reactiveType, @Nullable Object source) {
@@ -162,13 +164,13 @@ public ReactiveAdapter getAdapter(@Nullable Class<?> reactiveType, @Nullable Obj
162164

163165

164166
/**
165-
* Return a shared default {@code ReactiveAdapterRegistry} instance, lazily
166-
* building it once needed.
167+
* Return a shared default {@code ReactiveAdapterRegistry} instance,
168+
* lazily building it once needed.
167169
* <p><b>NOTE:</b> We highly recommend passing a long-lived, pre-configured
168170
* {@code ReactiveAdapterRegistry} instance for customization purposes.
169171
* This accessor is only meant as a fallback for code paths that want to
170172
* fall back on a default instance if one isn't provided.
171-
* @return the shared {@code ReactiveAdapterRegistry} instance (never {@code null})
173+
* @return the shared {@code ReactiveAdapterRegistry} instance
172174
* @since 5.0.2
173175
*/
174176
public static ReactiveAdapterRegistry getSharedInstance() {

spring-core/src/main/java/org/springframework/util/Base64Utils.java

Lines changed: 2 additions & 2 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-2019 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.
@@ -89,7 +89,7 @@ public static byte[] decodeUrlSafe(byte[] src) {
8989

9090
/**
9191
* Base64-encode the given byte array to a String.
92-
* @param src the original byte array (may be {@code null})
92+
* @param src the original byte array
9393
* @return the encoded byte array as a UTF-8 String
9494
*/
9595
public static String encodeToString(byte[] src) {

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AsyncHandlerMethodReturnValueHandler.java

Lines changed: 6 additions & 6 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-2019 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,8 +43,8 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur
4343
* {@link #supportsReturnType(org.springframework.core.MethodParameter)}
4444
* is called and it returns {@code true}.
4545
* @param returnValue the value returned from the handler method
46-
* @param returnType the type of the return value.
47-
* @return true if the return value type represents an async value.
46+
* @param returnType the type of the return value
47+
* @return {@code true} if the return value type represents an async value
4848
*/
4949
boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType);
5050

@@ -58,9 +58,9 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur
5858
* {@link #supportsReturnType(org.springframework.core.MethodParameter)}
5959
* is called and it returns {@code true}.
6060
* @param returnValue the value returned from the handler method
61-
* @param returnType the type of the return value.
62-
* @return the resulting ListenableFuture or {@code null} in which case no
63-
* further handling will be performed.
61+
* @param returnType the type of the return value
62+
* @return the resulting ListenableFuture, or {@code null} in which case
63+
* no further handling will be performed
6464
*/
6565
@Nullable
6666
ListenableFuture<?> toListenableFuture(Object returnValue, MethodParameter returnType);

spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.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-2019 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.
@@ -42,10 +42,10 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep
4242

4343
protected final Log logger = LogFactory.getLog(getClass());
4444

45-
private final List<ChannelInterceptor> interceptors = new ArrayList<>(5);
46-
4745
private String beanName;
4846

47+
private final List<ChannelInterceptor> interceptors = new ArrayList<>(5);
48+
4949

5050
public AbstractMessageChannel() {
5151
this.beanName = getClass().getSimpleName() + "@" + ObjectUtils.getIdentityHexString(this);

spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,22 +415,22 @@ public void setMappedClass(Class<?> mappedClass) {
415415
}
416416

417417
/**
418-
* Indicates whether DTD parsing should be supported.
418+
* Indicate whether DTD parsing should be supported.
419419
* <p>Default is {@code false} meaning that DTD is disabled.
420420
*/
421421
public void setSupportDtd(boolean supportDtd) {
422422
this.supportDtd = supportDtd;
423423
}
424424

425425
/**
426-
* Whether DTD parsing is supported.
426+
* Return whether DTD parsing is supported.
427427
*/
428428
public boolean isSupportDtd() {
429429
return this.supportDtd;
430430
}
431431

432432
/**
433-
* Indicates whether external XML entities are processed when unmarshalling.
433+
* Indicate whether external XML entities are processed when unmarshalling.
434434
* <p>Default is {@code false}, meaning that external entities are not resolved.
435435
* Note that processing of external entities will only be enabled/disabled when the
436436
* {@code Source} passed to {@link #unmarshal(Source)} is a {@link SAXSource} or
@@ -442,12 +442,12 @@ public boolean isSupportDtd() {
442442
public void setProcessExternalEntities(boolean processExternalEntities) {
443443
this.processExternalEntities = processExternalEntities;
444444
if (processExternalEntities) {
445-
setSupportDtd(true);
445+
this.supportDtd = true;
446446
}
447447
}
448448

449449
/**
450-
* Returns the configured value for whether XML external entities are allowed.
450+
* Return whether XML external entities are allowed.
451451
*/
452452
public boolean isProcessExternalEntities() {
453453
return this.processExternalEntities;

spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java

Lines changed: 6 additions & 7 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-2019 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,7 +22,6 @@
2222
import java.io.Reader;
2323
import java.io.StringReader;
2424
import java.io.Writer;
25-
2625
import javax.xml.parsers.DocumentBuilder;
2726
import javax.xml.parsers.DocumentBuilderFactory;
2827
import javax.xml.parsers.ParserConfigurationException;
@@ -87,22 +86,22 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
8786

8887

8988
/**
90-
* Indicates whether DTD parsing should be supported.
89+
* Indicate whether DTD parsing should be supported.
9190
* <p>Default is {@code false} meaning that DTD is disabled.
9291
*/
9392
public void setSupportDtd(boolean supportDtd) {
9493
this.supportDtd = supportDtd;
9594
}
9695

9796
/**
98-
* Whether DTD parsing is supported.
97+
* Return whether DTD parsing is supported.
9998
*/
10099
public boolean isSupportDtd() {
101100
return this.supportDtd;
102101
}
103102

104103
/**
105-
* Indicates whether external XML entities are processed when unmarshalling.
104+
* Indicate whether external XML entities are processed when unmarshalling.
106105
* <p>Default is {@code false}, meaning that external entities are not resolved.
107106
* Note that processing of external entities will only be enabled/disabled when the
108107
* {@code Source} passed to {@link #unmarshal(Source)} is a {@link SAXSource} or
@@ -114,12 +113,12 @@ public boolean isSupportDtd() {
114113
public void setProcessExternalEntities(boolean processExternalEntities) {
115114
this.processExternalEntities = processExternalEntities;
116115
if (processExternalEntities) {
117-
setSupportDtd(true);
116+
this.supportDtd = true;
118117
}
119118
}
120119

121120
/**
122-
* Returns the configured value for whether XML external entities are allowed.
121+
* Return whether XML external entities are allowed.
123122
* @see #createXmlReader()
124123
*/
125124
public boolean isProcessExternalEntities() {

spring-test/src/test/java/org/springframework/test/web/client/DefaultRequestExpectationTests.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -26,15 +26,11 @@
2626
import org.springframework.http.HttpMethod;
2727
import org.springframework.http.client.ClientHttpRequest;
2828

29-
import static junit.framework.TestCase.assertFalse;
30-
import static org.junit.Assert.assertTrue;
31-
import static org.springframework.http.HttpMethod.GET;
32-
import static org.springframework.http.HttpMethod.POST;
33-
import static org.springframework.test.web.client.ExpectedCount.once;
34-
import static org.springframework.test.web.client.ExpectedCount.twice;
35-
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
36-
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
37-
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
29+
import static org.junit.Assert.*;
30+
import static org.springframework.http.HttpMethod.*;
31+
import static org.springframework.test.web.client.ExpectedCount.*;
32+
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
33+
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
3834

3935
/**
4036
* Unit tests for {@link DefaultRequestExpectation}.
@@ -86,7 +82,6 @@ public void isSatisfied() {
8682
}
8783

8884

89-
9085
@SuppressWarnings("deprecation")
9186
private ClientHttpRequest createRequest(HttpMethod method, String url) {
9287
try {

spring-test/src/test/java/org/springframework/test/web/client/MockRestServiceServerTests.java

Lines changed: 3 additions & 1 deletion
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-2019 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,7 @@
2323
import org.springframework.test.web.client.MockRestServiceServer.MockRestServiceServerBuilder;
2424
import org.springframework.web.client.RestTemplate;
2525

26+
import static org.junit.Assert.*;
2627
import static org.springframework.http.HttpMethod.*;
2728
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
2829
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
@@ -124,6 +125,7 @@ public void followUpRequestAfterFailure() {
124125

125126
try {
126127
this.restTemplate.getForEntity("/some-service/some-endpoint", String.class);
128+
fail("Expected exception");
127129
}
128130
catch (Exception ex) {
129131
this.restTemplate.postForEntity("/reporting-service/report-error", ex.toString(), String.class);

spring-tx/src/main/java/org/springframework/transaction/annotation/Propagation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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,7 +40,7 @@ public enum Propagation {
4040
* Support a current transaction, execute non-transactionally if none exists.
4141
* Analogous to EJB transaction attribute of the same name.
4242
* <p>Note: For transaction managers with transaction synchronization,
43-
* PROPAGATION_SUPPORTS is slightly different from no transaction at all,
43+
* {@code SUPPORTS} is slightly different from no transaction at all,
4444
* as it defines a transaction scope that synchronization will apply for.
4545
* As a consequence, the same resources (JDBC Connection, Hibernate Session, etc)
4646
* will be shared for the entire specified scope. Note that this depends on
@@ -87,7 +87,7 @@ public enum Propagation {
8787

8888
/**
8989
* Execute within a nested transaction if a current transaction exists,
90-
* behave like PROPAGATION_REQUIRED else. There is no analogous feature in EJB.
90+
* behave like {@code REQUIRED} else. There is no analogous feature in EJB.
9191
* <p>Note: Actual creation of a nested transaction will only work on specific
9292
* transaction managers. Out of the box, this only applies to the JDBC
9393
* DataSourceTransactionManager when working on a JDBC 3.0 driver.

0 commit comments

Comments
 (0)