Skip to content

Commit ec527a4

Browse files
committed
Relaxed expectation for JDK bug in cornerSpr8949 (for compatibility with OpenJDK 8 b100)
Issue: SPR-10558
1 parent 5ccbc80 commit ec527a4

File tree

1 file changed

+54
-60
lines changed

1 file changed

+54
-60
lines changed

spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,19 @@
2121
import java.beans.IntrospectionException;
2222
import java.beans.Introspector;
2323
import java.beans.PropertyDescriptor;
24-
25-
import java.lang.reflect.Method;
2624
import java.math.BigDecimal;
2725

2826
import org.junit.Test;
2927

3028
import org.springframework.core.JdkVersion;
3129
import org.springframework.tests.sample.beans.TestBean;
32-
import org.springframework.util.ClassUtils;
33-
34-
35-
import static org.hamcrest.Matchers.greaterThan;
36-
import static org.hamcrest.Matchers.lessThan;
37-
3830

3931
import static org.hamcrest.CoreMatchers.equalTo;
4032
import static org.hamcrest.CoreMatchers.is;
41-
33+
import static org.hamcrest.Matchers.*;
4234
import static org.junit.Assert.*;
4335

4436
/**
45-
* Unit tests for {@link ExtendedBeanInfo}.
46-
*
4737
* @author Chris Beams
4838
* @since 3.1
4939
*/
@@ -208,10 +198,6 @@ public Integer getProperty1() {
208198
}
209199
}
210200

211-
interface Spr9453<T> {
212-
T getProp();
213-
}
214-
215201
@Test
216202
public void cornerSpr9453() throws IntrospectionException {
217203
final class Bean implements Spr9453<Class<?>> {
@@ -597,7 +583,6 @@ public void cornerSpr10111() throws Exception {
597583
new ExtendedBeanInfo(Introspector.getBeanInfo(BigDecimal.class));
598584
}
599585

600-
601586
@Test
602587
public void subclassWriteMethodWithCovariantReturnType() throws IntrospectionException {
603588
@SuppressWarnings("unused") class B {
@@ -796,6 +781,7 @@ public void propertyDescriptorOrderIsEqual() throws IntrospectionException {
796781
@Test
797782
public void propertyDescriptorComparator() throws IntrospectionException {
798783
PropertyDescriptorComparator c = new PropertyDescriptorComparator();
784+
799785
assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("a", null, null)), equalTo(0));
800786
assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("abc", null, null)), equalTo(0));
801787
assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("b", null, null)), lessThan(0));
@@ -867,33 +853,6 @@ public void reproSpr8806() throws IntrospectionException {
867853
new ExtendedBeanInfo(Introspector.getBeanInfo(LawLibrary.class));
868854
}
869855

870-
interface Book { }
871-
872-
interface TextBook extends Book { }
873-
874-
interface LawBook extends TextBook { }
875-
876-
interface BookOperations {
877-
Book getBook();
878-
void setBook(Book book);
879-
}
880-
881-
interface TextBookOperations extends BookOperations {
882-
@Override
883-
TextBook getBook();
884-
}
885-
886-
abstract class Library {
887-
public Book getBook() { return null; }
888-
public void setBook(Book book) { }
889-
}
890-
891-
class LawLibrary extends Library implements TextBookOperations {
892-
@Override
893-
public LawBook getBook() { return null; }
894-
}
895-
896-
897856
@Test
898857
public void cornerSpr8949() throws IntrospectionException {
899858
class A {
@@ -912,23 +871,10 @@ public boolean isTargetMethod() {
912871

913872
BeanInfo bi = Introspector.getBeanInfo(B.class);
914873

915-
/* first, demonstrate the 'problem':
916-
* java.beans.Introspector returns the "wrong" declaring class for overridden read
917-
* methods, which in turn violates expectations in {@link ExtendedBeanInfo} regarding
918-
* method equality. Spring's {@link ClassUtils#getMostSpecificMethod(Method, Class)}
919-
* helps out here, and is now put into use in ExtendedBeanInfo as well
920-
*/
921-
for (PropertyDescriptor pd : bi.getPropertyDescriptors()) {
922-
if ("targetMethod".equals(pd.getName())) {
923-
Method readMethod = pd.getReadMethod();
924-
assertTrue(readMethod.getDeclaringClass().equals(A.class)); // we expected B!
925-
926-
Method msReadMethod = ClassUtils.getMostSpecificMethod(readMethod, B.class);
927-
assertTrue(msReadMethod.getDeclaringClass().equals(B.class)); // and now we get it.
928-
}
929-
}
930-
931-
// and now demonstrate that we've indeed fixed the problem
874+
// java.beans.Introspector returns the "wrong" declaring class for overridden read
875+
// methods, which in turn violates expectations in {@link ExtendedBeanInfo} regarding
876+
// method equality. Spring's {@link ClassUtils#getMostSpecificMethod(Method, Class)}
877+
// helps out here, and is now put into use in ExtendedBeanInfo as well.
932878
BeanInfo ebi = new ExtendedBeanInfo(bi);
933879

934880
assertThat(hasReadMethodForProperty(bi, "targetMethod"), is(true));
@@ -980,8 +926,56 @@ public void shouldSupportStaticWriteMethod() throws IntrospectionException {
980926
}
981927
}
982928

929+
930+
interface Spr9453<T> {
931+
932+
T getProp();
933+
}
934+
935+
interface Book {
936+
}
937+
938+
interface TextBook extends Book {
939+
}
940+
941+
interface LawBook extends TextBook {
942+
}
943+
944+
interface BookOperations {
945+
946+
Book getBook();
947+
948+
void setBook(Book book);
949+
}
950+
951+
interface TextBookOperations extends BookOperations {
952+
953+
@Override
954+
TextBook getBook();
955+
}
956+
957+
abstract class Library {
958+
959+
public Book getBook() {
960+
return null;
961+
}
962+
963+
public void setBook(Book book) {
964+
}
965+
}
966+
967+
class LawLibrary extends Library implements TextBookOperations {
968+
969+
@Override
970+
public LawBook getBook() {
971+
return null;
972+
}
973+
}
974+
983975
static class WithStaticWriteMethod {
976+
984977
public static void setProp1(String prop1) {
985978
}
986979
}
980+
987981
}

0 commit comments

Comments
 (0)