Skip to content

Commit 34fee1a

Browse files
committed
Polish
1 parent 8ad9bfe commit 34fee1a

File tree

7 files changed

+75
-28
lines changed

7 files changed

+75
-28
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsMetricsExportAutoConfigurationTests.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,7 @@ static class CustomConfigConfiguration {
112112

113113
@Bean
114114
public AppOpticsConfig customConfig() {
115-
return (key) -> {
116-
if ("appoptics.apiToken".equals(key)) {
117-
return "abcde";
118-
}
119-
return null;
120-
};
115+
return (key) -> "appoptics.apiToken".equals(key) ? "abcde" : null;
121116
}
122117

123118
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ protected static class FlywayInitializerJdbcOperationsDependencyConfiguration
324324

325325
public FlywayInitializerJdbcOperationsDependencyConfiguration() {
326326
super("flywayInitializer");
327-
328327
}
329328

330329
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/validation/ValidatorAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ private static Validator getExisting(ApplicationContext applicationContext) {
138138
private static Validator create() {
139139
OptionalValidatorFactoryBean validator = new OptionalValidatorFactoryBean();
140140
try {
141-
validator
142-
.setMessageInterpolator(new MessageInterpolatorFactory().getObject());
141+
MessageInterpolatorFactory factory = new MessageInterpolatorFactory();
142+
validator.setMessageInterpolator(factory.getObject());
143143
}
144144
catch (ValidationException ex) {
145145
// Ignore

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.boot.autoconfigure.web.reactive.error;
1818

19-
import java.util.Arrays;
2019
import java.util.Collections;
2120
import java.util.Date;
2221
import java.util.HashSet;
@@ -63,9 +62,15 @@ public abstract class AbstractErrorWebExceptionHandler
6362
/**
6463
* Currently duplicated from Spring WebFlux HttpWebHandlerAdapter.
6564
*/
66-
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS = new HashSet<>(
67-
Arrays.asList("AbortedException", "ClientAbortException", "EOFException",
68-
"EofException"));
65+
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS;
66+
static {
67+
Set<String> exceptions = new HashSet<>();
68+
exceptions.add("AbortedException");
69+
exceptions.add("ClientAbortException");
70+
exceptions.add("EOFException");
71+
exceptions.add("EofException");
72+
DISCONNECTED_CLIENT_EXCEPTIONS = Collections.unmodifiableSet(exceptions);
73+
}
6974

7075
private static final Log logger = HttpLogging
7176
.forLogName(AbstractErrorWebExceptionHandler.class);
@@ -268,15 +273,15 @@ public Mono<Void> handle(ServerWebExchange exchange, Throwable throwable) {
268273
}
269274

270275
private boolean isDisconnectedClientError(Throwable ex) {
271-
String message = NestedExceptionUtils.getMostSpecificCause(ex).getMessage();
272-
if (message != null) {
273-
String text = message.toLowerCase();
274-
if (text.contains("broken pipe")
275-
|| text.contains("connection reset by peer")) {
276-
return true;
277-
}
278-
}
279-
return DISCONNECTED_CLIENT_EXCEPTIONS.contains(ex.getClass().getSimpleName());
276+
return DISCONNECTED_CLIENT_EXCEPTIONS.contains(ex.getClass().getSimpleName())
277+
|| isDisconnectedClientErrorMessage(
278+
NestedExceptionUtils.getMostSpecificCause(ex).getMessage());
279+
}
280+
281+
private boolean isDisconnectedClientErrorMessage(String message) {
282+
message = message != null ? message.toLowerCase() : "";
283+
return (message.contains("broken pipe")
284+
|| message.contains("connection reset by peer"));
280285
}
281286

282287
private void logError(ServerRequest request, ServerResponse response,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.web.reactive.error;
18+
19+
import org.junit.Test;
20+
21+
import org.springframework.test.util.ReflectionTestUtils;
22+
import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
26+
/**
27+
* Tests for {@link AbstractErrorWebExceptionHandler}.
28+
*
29+
* @author Phillip Webb
30+
*/
31+
public class DefaultErrorWebExceptionHandlerTests {
32+
33+
@Test
34+
public void disconnectedClientExceptionsMatchesFramework() {
35+
Object errorHandlers = ReflectionTestUtils.getField(
36+
AbstractErrorWebExceptionHandler.class, "DISCONNECTED_CLIENT_EXCEPTIONS");
37+
Object webHandlers = ReflectionTestUtils.getField(HttpWebHandlerAdapter.class,
38+
"DISCONNECTED_CLIENT_EXCEPTIONS");
39+
assertThat(errorHandlers).isNotNull().isEqualTo(webHandlers);
40+
}
41+
42+
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public class LoggingApplicationListener implements GenericApplicationListener {
139139
}
140140

141141
private static final Map<LogLevel, List<String>> LOG_LEVEL_LOGGERS;
142-
143142
static {
144143
MultiValueMap<LogLevel, String> loggers = new LinkedMultiValueMap<>();
145144
loggers.add(LogLevel.DEBUG, "sql");
@@ -320,10 +319,17 @@ private void initializeFinalLoggingLevels(ConfigurableEnvironment environment,
320319
}
321320

322321
protected void initializeLogLevel(LoggingSystem system, LogLevel level) {
323-
LOG_LEVEL_LOGGERS.getOrDefault(level, Collections.emptyList()).stream()
324-
.flatMap((logger) -> DEFAULT_GROUP_LOGGERS
325-
.getOrDefault(logger, Collections.singletonList(logger)).stream())
326-
.forEach((logger) -> system.setLogLevel(logger, level));
322+
LOG_LEVEL_LOGGERS.getOrDefault(level, Collections.emptyList())
323+
.forEach((logger) -> initializeLogLevel(system, level, logger));
324+
}
325+
326+
private void initializeLogLevel(LoggingSystem system, LogLevel level, String logger) {
327+
List<String> groupLoggers = DEFAULT_GROUP_LOGGERS.get(logger);
328+
if (groupLoggers == null) {
329+
system.setLogLevel(logger, level);
330+
return;
331+
}
332+
groupLoggers.forEach((groupLogger) -> system.setLogLevel(groupLogger, level));
327333
}
328334

329335
protected void setLogLevels(LoggingSystem system, Environment environment) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public void parseDebugArg() {
263263
}
264264

265265
@Test
266-
public void parseDebugArgExpandGroups() {
266+
public void parseDebugArgExpandsGroups() {
267267
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "debug");
268268
this.initializer.initialize(this.context.getEnvironment(),
269269
this.context.getClassLoader());

0 commit comments

Comments
 (0)