From a43ba052e94eb3b07ec9e407500e713d24e02b16 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 7 Aug 2019 12:24:48 +0200 Subject: [PATCH] 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 --- .../org/springframework/core/SerializableTypeWrapper.java | 7 ++++--- .../springframework/core/SerializableTypeWrapperTests.java | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java index 97537e45cc..04ef40d528 100644 --- a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java +++ b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java @@ -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; * * @author Phillip Webb * @author Juergen Hoeller + * @author Sam Brannen * @since 4.0 */ final class SerializableTypeWrapper { @@ -89,8 +90,8 @@ final class SerializableTypeWrapper { */ @SuppressWarnings("unchecked") public static 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); diff --git a/spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java b/spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java index e0610c0749..fe8ac43dc7 100644 --- a/spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java +++ b/spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java @@ -33,8 +33,6 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; - - /** * Tests for {@link SerializableTypeWrapper}. *