Skip to content

Commit

Permalink
Avoid Class.getPackage() in favor of plain Class.getName() checks
Browse files Browse the repository at this point in the history
Fixes #22306
  • Loading branch information
jhoeller committed Jan 25, 2019
1 parent 4732f83 commit 85ec9b9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -61,15 +61,14 @@ public class DecoderHttpMessageReader<T> implements HttpMessageReader<T> {
*/
public DecoderHttpMessageReader(Decoder<T> decoder) {
Assert.notNull(decoder, "Decoder is required");
initLogger(decoder);
this.decoder = decoder;
this.mediaTypes = MediaType.asMediaTypes(decoder.getDecodableMimeTypes());
initLogger(decoder);
}

private void initLogger(Decoder<T> decoder) {
private static void initLogger(Decoder<?> decoder) {
if (decoder instanceof AbstractDecoder &&
decoder.getClass().getPackage().getName().startsWith("org.springframework.core.codec")) {

decoder.getClass().getName().startsWith("org.springframework.core.codec")) {
Log logger = HttpLogging.forLog(((AbstractDecoder) decoder).getLogger());
((AbstractDecoder) decoder).setLogger(logger);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,16 +67,15 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> {
*/
public EncoderHttpMessageWriter(Encoder<T> encoder) {
Assert.notNull(encoder, "Encoder is required");
initLogger(encoder);
this.encoder = encoder;
this.mediaTypes = MediaType.asMediaTypes(encoder.getEncodableMimeTypes());
this.defaultMediaType = initDefaultMediaType(this.mediaTypes);
initLogger(encoder);
}

private void initLogger(Encoder<T> encoder) {
private static void initLogger(Encoder<?> encoder) {
if (encoder instanceof AbstractEncoder &&
encoder.getClass().getPackage().getName().startsWith("org.springframework.core.codec")) {

encoder.getClass().getName().startsWith("org.springframework.core.codec")) {
Log logger = HttpLogging.forLog(((AbstractEncoder) encoder).getLogger());
((AbstractEncoder) encoder).setLogger(logger);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -215,15 +215,12 @@ protected void detectHandlerMethods(final Object handler) {
}

private String formatMappings(Class<?> userType, Map<Method, T> methods) {

String formattedType = Arrays.stream(userType.getPackage().getName().split("\\."))
String formattedType = Arrays.stream(ClassUtils.getPackageName(userType).split("\\."))
.map(p -> p.substring(0, 1))
.collect(Collectors.joining(".", "", ".")) + userType.getSimpleName();

Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes())
.map(Class::getSimpleName)
.collect(Collectors.joining(",", "(", ")"));

return methods.entrySet().stream()
.map(e -> {
Method method = e.getKey();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -285,15 +285,12 @@ protected void detectHandlerMethods(Object handler) {
}

private String formatMappings(Class<?> userType, Map<Method, T> methods) {

String formattedType = Arrays.stream(userType.getPackage().getName().split("\\."))
String formattedType = Arrays.stream(ClassUtils.getPackageName(userType).split("\\."))
.map(p -> p.substring(0, 1))
.collect(Collectors.joining(".", "", ".")) + userType.getSimpleName();

Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes())
.map(Class::getSimpleName)
.collect(Collectors.joining(",", "(", ")"));

return methods.entrySet().stream()
.map(e -> {
Method method = e.getKey();
Expand Down

0 comments on commit 85ec9b9

Please sign in to comment.