Skip to content

Commit e5e2d2d

Browse files
committed
Polishing (includes minor performance refinements from master)
1 parent bdd9a55 commit e5e2d2d

File tree

25 files changed

+170
-174
lines changed

25 files changed

+170
-174
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.
@@ -254,13 +254,12 @@ public String[] getAliases(String name) {
254254
@SuppressWarnings("unchecked")
255255
private <T> T doGetSingleton(String name, @Nullable Class<T> requiredType) throws NamingException {
256256
synchronized (this.singletonObjects) {
257-
if (this.singletonObjects.containsKey(name)) {
258-
Object jndiObject = this.singletonObjects.get(name);
259-
if (requiredType != null && !requiredType.isInstance(jndiObject)) {
260-
throw new TypeMismatchNamingException(
261-
convertJndiName(name), requiredType, (jndiObject != null ? jndiObject.getClass() : null));
257+
Object singleton = this.singletonObjects.get(name);
258+
if (singleton != null) {
259+
if (requiredType != null && !requiredType.isInstance(singleton)) {
260+
throw new TypeMismatchNamingException(convertJndiName(name), requiredType, singleton.getClass());
262261
}
263-
return (T) jndiObject;
262+
return (T) singleton;
264263
}
265264
T jndiObject = lookup(name, requiredType);
266265
this.singletonObjects.put(name, jndiObject);
@@ -274,14 +273,12 @@ private Class<?> doGetType(String name) throws NamingException {
274273
}
275274
else {
276275
synchronized (this.resourceTypes) {
277-
if (this.resourceTypes.containsKey(name)) {
278-
return this.resourceTypes.get(name);
279-
}
280-
else {
281-
Class<?> type = lookup(name, null).getClass();
276+
Class<?> type = this.resourceTypes.get(name);
277+
if (type == null) {
278+
type = lookup(name, null).getClass();
282279
this.resourceTypes.put(name, type);
283-
return type;
284280
}
281+
return type;
285282
}
286283
}
287284
}

spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
*/
4141
public abstract class AbstractDecoder<T> implements Decoder<T> {
4242

43-
protected Log logger = LogFactory.getLog(getClass());
44-
4543
private final List<MimeType> decodableMimeTypes;
4644

45+
protected Log logger = LogFactory.getLog(getClass());
46+
4747

4848
protected AbstractDecoder(MimeType... supportedMimeTypes) {
4949
this.decodableMimeTypes = Arrays.asList(supportedMimeTypes);

spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
*/
3737
public abstract class AbstractEncoder<T> implements Encoder<T> {
3838

39-
protected Log logger = LogFactory.getLog(getClass());
40-
4139
private final List<MimeType> encodableMimeTypes;
4240

41+
protected Log logger = LogFactory.getLog(getClass());
42+
4343

4444
protected AbstractEncoder(MimeType... supportedMimeTypes) {
4545
this.encodableMimeTypes = Arrays.asList(supportedMimeTypes);

spring-core/src/main/java/org/springframework/core/log/CompositeLog.java

Lines changed: 13 additions & 8 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.
@@ -63,38 +63,43 @@ public CompositeLog(List<Log> loggers) {
6363
}
6464

6565
private static Log initLogger(List<Log> loggers, Predicate<Log> predicate) {
66-
return loggers.stream().filter(predicate).findFirst().orElse(NO_OP_LOG);
66+
for (Log logger : loggers) {
67+
if (predicate.test(logger)) {
68+
return logger;
69+
}
70+
}
71+
return NO_OP_LOG;
6772
}
6873

6974

7075
@Override
7176
public boolean isFatalEnabled() {
72-
return this.fatalLogger != NO_OP_LOG;
77+
return (this.fatalLogger != NO_OP_LOG);
7378
}
7479

7580
@Override
7681
public boolean isErrorEnabled() {
77-
return this.errorLogger != NO_OP_LOG;
82+
return (this.errorLogger != NO_OP_LOG);
7883
}
7984

8085
@Override
8186
public boolean isWarnEnabled() {
82-
return this.warnLogger != NO_OP_LOG;
87+
return (this.warnLogger != NO_OP_LOG);
8388
}
8489

8590
@Override
8691
public boolean isInfoEnabled() {
87-
return this.infoLogger != NO_OP_LOG;
92+
return (this.infoLogger != NO_OP_LOG);
8893
}
8994

9095
@Override
9196
public boolean isDebugEnabled() {
92-
return this.debugLogger != NO_OP_LOG;
97+
return (this.debugLogger != NO_OP_LOG);
9398
}
9499

95100
@Override
96101
public boolean isTraceEnabled() {
97-
return this.traceLogger != NO_OP_LOG;
102+
return (this.traceLogger != NO_OP_LOG);
98103
}
99104

100105
@Override

spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.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.
@@ -58,8 +58,6 @@ public class HandlerMethod {
5858
public static final Log defaultLogger = LogFactory.getLog(HandlerMethod.class);
5959

6060

61-
protected Log logger = defaultLogger;
62-
6361
private final Object bean;
6462

6563
@Nullable
@@ -76,6 +74,8 @@ public class HandlerMethod {
7674
@Nullable
7775
private HandlerMethod resolvedFromHandlerMethod;
7876

77+
protected Log logger = defaultLogger;
78+
7979

8080
/**
8181
* Create an instance from a bean instance and a method.

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/handler/invocation/ReactiveReturnValueHandler.java

Lines changed: 2 additions & 2 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.
@@ -48,7 +48,7 @@ public ReactiveReturnValueHandler(ReactiveAdapterRegistry adapterRegistry) {
4848

4949
@Override
5050
public boolean supportsReturnType(MethodParameter returnType) {
51-
return this.adapterRegistry.getAdapter(returnType.getParameterType()) != null;
51+
return (this.adapterRegistry.getAdapter(returnType.getParameterType()) != null);
5252
}
5353

5454
@Override

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-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.
@@ -42,10 +42,10 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep
4242

4343
protected 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-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java

Lines changed: 5 additions & 5 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.
@@ -70,8 +70,6 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
7070

7171
private static final int PUBLISH_ON_BUFFER_SIZE = 16;
7272

73-
private Log logger = LogFactory.getLog(ReactorNettyTcpClient.class);
74-
7573

7674
private final TcpClient tcpClient;
7775

@@ -81,13 +79,15 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
8179
private final ChannelGroup channelGroup;
8280

8381
@Nullable
84-
private LoopResources loopResources;
82+
private final LoopResources loopResources;
8583

8684
@Nullable
87-
private ConnectionProvider poolResources;
85+
private final ConnectionProvider poolResources;
8886

8987
private final Scheduler scheduler = Schedulers.newParallel("tcp-client-scheduler");
9088

89+
private Log logger = LogFactory.getLog(ReactorNettyTcpClient.class);
90+
9191
private volatile boolean stopping = false;
9292

9393

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 & 6 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.
@@ -86,22 +86,22 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
8686

8787

8888
/**
89-
* Indicates whether DTD parsing should be supported.
89+
* Indicate whether DTD parsing should be supported.
9090
* <p>Default is {@code false} meaning that DTD is disabled.
9191
*/
9292
public void setSupportDtd(boolean supportDtd) {
9393
this.supportDtd = supportDtd;
9494
}
9595

9696
/**
97-
* Whether DTD parsing is supported.
97+
* Return whether DTD parsing is supported.
9898
*/
9999
public boolean isSupportDtd() {
100100
return this.supportDtd;
101101
}
102102

103103
/**
104-
* Indicates whether external XML entities are processed when unmarshalling.
104+
* Indicate whether external XML entities are processed when unmarshalling.
105105
* <p>Default is {@code false}, meaning that external entities are not resolved.
106106
* Note that processing of external entities will only be enabled/disabled when the
107107
* {@code Source} passed to {@link #unmarshal(Source)} is a {@link SAXSource} or
@@ -113,12 +113,12 @@ public boolean isSupportDtd() {
113113
public void setProcessExternalEntities(boolean processExternalEntities) {
114114
this.processExternalEntities = processExternalEntities;
115115
if (processExternalEntities) {
116-
setSupportDtd(true);
116+
this.supportDtd = true;
117117
}
118118
}
119119

120120
/**
121-
* Returns the configured value for whether XML external entities are allowed.
121+
* Return whether XML external entities are allowed.
122122
* @see #createXmlReader()
123123
*/
124124
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 {

0 commit comments

Comments
 (0)