Skip to content

Commit c5f235c

Browse files
Roman Marchenkomrserb
authored andcommitted
8347826: Introspector shows wrong method list after 8071693
Reviewed-by: azvegint, serb, aivanov
1 parent 832c5b0 commit c5f235c

File tree

4 files changed

+447
-57
lines changed

4 files changed

+447
-57
lines changed

src/java.desktop/share/classes/com/sun/beans/introspect/MethodInfo.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,10 +31,11 @@
3131
import java.lang.reflect.Method;
3232
import java.lang.reflect.Modifier;
3333
import java.lang.reflect.Type;
34+
import java.util.ArrayDeque;
3435
import java.util.ArrayList;
35-
import java.util.Arrays;
3636
import java.util.Collections;
3737
import java.util.Comparator;
38+
import java.util.Deque;
3839
import java.util.List;
3940
import java.util.Set;
4041

@@ -105,13 +106,16 @@ static List<Method> get(Class<?> type) {
105106
}
106107
}
107108

108-
// Add default methods inherited from interfaces
109-
for (Class<?> iface : type.getInterfaces()) {
109+
// Add methods inherited from interfaces
110+
Deque<Class<?>> ifaceDeque = new ArrayDeque<>(List.of(type.getInterfaces()));
111+
while (!ifaceDeque.isEmpty()) {
112+
Class<?> iface = ifaceDeque.removeLast();
110113
if (IGNORABLE_INTERFACES.contains(iface)) {
111114
continue;
112115
}
116+
ifaceDeque.addAll(List.of(iface.getInterfaces()));
113117
for (Method method : iface.getMethods()) {
114-
if (!Modifier.isAbstract(method.getModifiers())) {
118+
if (!Modifier.isAbstract(method.getModifiers()) && !method.isBridge()) {
115119
(list = createIfNeeded(list)).add(method);
116120
}
117121
}

src/java.desktop/share/classes/com/sun/beans/introspect/PropertyInfo.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -78,7 +78,8 @@ private boolean initialize() {
7878
}
7979
if (!isInitedToIsGetter && this.readList != null) {
8080
for (MethodInfo info : this.readList) {
81-
if ((this.read == null) || this.read.type.isAssignableFrom(info.type)) {
81+
if ((this.read == null) || (!info.method.isDefault()
82+
&& this.read.type.isAssignableFrom(info.type))) {
8283
this.read = info;
8384
this.type = info.type;
8485
}
@@ -91,6 +92,9 @@ private boolean initialize() {
9192
if (writeType == null) {
9293
this.write = info;
9394
writeType = info.type;
95+
} else if (isParentOfIncoming(this.write, info)) {
96+
this.write = info;
97+
writeType = info.type;
9498
} else if (writeType.isAssignableFrom(info.type)) {
9599
if ((this.write == null) || this.write.type.isAssignableFrom(info.type)) {
96100
this.write = info;
@@ -307,4 +311,16 @@ public static Map<String,PropertyInfo> get(Class<?> type) {
307311
? Collections.unmodifiableMap(map)
308312
: Collections.emptyMap();
309313
}
314+
315+
private static boolean isParentOfIncoming(MethodInfo current, MethodInfo incoming) {
316+
if (null == current) {
317+
return false;
318+
}
319+
Class<?> currentClass = current.method.getDeclaringClass();
320+
Class<?> incomingClass = incoming.method.getDeclaringClass();
321+
if (currentClass == incomingClass) {
322+
return false;
323+
}
324+
return currentClass.isAssignableFrom(incomingClass);
325+
}
310326
}

src/java.desktop/share/classes/java/beans/Introspector.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1052,8 +1052,12 @@ private void addMethod(MethodDescriptor md) {
10521052
}
10531053
}
10541054
if (match) {
1055-
MethodDescriptor composite = new MethodDescriptor(old, md);
1056-
methods.put(name, composite);
1055+
Class<?> oldClass = old.getMethod().getDeclaringClass();
1056+
Class<?> mdClass = md.getMethod().getDeclaringClass();
1057+
if (oldClass == mdClass || oldClass.isAssignableFrom(mdClass) || !mdClass.isAssignableFrom(oldClass)) {
1058+
MethodDescriptor composite = new MethodDescriptor(old, md);
1059+
methods.put(name, composite);
1060+
}
10571061
return;
10581062
}
10591063

0 commit comments

Comments
 (0)