Skip to content

8347826: Introspector shows wrong method list after 8071693 #3618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,10 +31,11 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -105,13 +106,16 @@ static List<Method> get(Class<?> type) {
}
}

// Add default methods inherited from interfaces
for (Class<?> iface : type.getInterfaces()) {
// Add methods inherited from interfaces
Deque<Class<?>> ifaceDeque = new ArrayDeque<>(List.of(type.getInterfaces()));
while (!ifaceDeque.isEmpty()) {
Class<?> iface = ifaceDeque.removeLast();
if (IGNORABLE_INTERFACES.contains(iface)) {
continue;
}
ifaceDeque.addAll(List.of(iface.getInterfaces()));
for (Method method : iface.getMethods()) {
if (!Modifier.isAbstract(method.getModifiers())) {
if (!Modifier.isAbstract(method.getModifiers()) && !method.isBridge()) {
(list = createIfNeeded(list)).add(method);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -79,7 +79,8 @@ private boolean initialize() {
}
if (!isInitedToIsGetter && this.readList != null) {
for (MethodInfo info : this.readList) {
if ((this.read == null) || this.read.type.isAssignableFrom(info.type)) {
if ((this.read == null) || (!info.method.isDefault()
&& this.read.type.isAssignableFrom(info.type))) {
this.read = info;
this.type = info.type;
}
Expand All @@ -92,6 +93,9 @@ private boolean initialize() {
if (writeType == null) {
this.write = info;
writeType = info.type;
} else if (isParentOfIncoming(this.write, info)) {
this.write = info;
writeType = info.type;
} else if (writeType.isAssignableFrom(info.type)) {
if ((this.write == null) || this.write.type.isAssignableFrom(info.type)) {
this.write = info;
Expand Down Expand Up @@ -313,4 +317,16 @@ public static Map<String,PropertyInfo> get(Class<?> type) {
? Collections.unmodifiableMap(map)
: Collections.emptyMap();
}

private static boolean isParentOfIncoming(MethodInfo current, MethodInfo incoming) {
if (null == current) {
return false;
}
Class<?> currentClass = current.method.getDeclaringClass();
Class<?> incomingClass = incoming.method.getDeclaringClass();
if (currentClass == incomingClass) {
return false;
}
return currentClass.isAssignableFrom(incomingClass);
}
}
10 changes: 7 additions & 3 deletions src/java.desktop/share/classes/java/beans/Introspector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1068,8 +1068,12 @@ private void addMethod(MethodDescriptor md) {
}
}
if (match) {
MethodDescriptor composite = new MethodDescriptor(old, md);
methods.put(name, composite);
Class<?> oldClass = old.getMethod().getDeclaringClass();
Class<?> mdClass = md.getMethod().getDeclaringClass();
if (oldClass == mdClass || oldClass.isAssignableFrom(mdClass) || !mdClass.isAssignableFrom(oldClass)) {
MethodDescriptor composite = new MethodDescriptor(old, md);
methods.put(name, composite);
}
return;
}

Expand Down
Loading