Browse Source

Remove unnecessary loop in SerializableTypeWrapper

Since arbitrary levels of proxies do not occur, this commit replaces
the `while` loop in SerializableTypeWrapper.unwrap() with a simple
`if` statement.

Closes gh-23415
pull/23435/head
Sam Brannen 6 years ago
parent
commit
a43ba052e9
  1. 7
      spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java
  2. 2
      spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java

7
spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java

@ -1,5 +1,5 @@ @@ -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.
@ -51,6 +51,7 @@ import org.springframework.util.ReflectionUtils; @@ -51,6 +51,7 @@ import org.springframework.util.ReflectionUtils;
*
* @author Phillip Webb
* @author Juergen Hoeller
* @author Sam Brannen
* @since 4.0
*/
final class SerializableTypeWrapper {
@ -89,8 +90,8 @@ final class SerializableTypeWrapper { @@ -89,8 +90,8 @@ final class SerializableTypeWrapper {
*/
@SuppressWarnings("unchecked")
public static <T extends Type> T unwrap(T type) {
Type unwrapped = type;
while (unwrapped instanceof SerializableTypeProxy) {
Type unwrapped = null;
if (type instanceof SerializableTypeProxy) {
unwrapped = ((SerializableTypeProxy) type).getTypeProvider().getType();
}
return (unwrapped != null ? (T) unwrapped : type);

2
spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java

@ -33,8 +33,6 @@ import org.junit.Test; @@ -33,8 +33,6 @@ import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SerializableTypeWrapper}.
*

Loading…
Cancel
Save