Skip to content

8071693: Introspector ignores default interface methods #13544

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

Closed
wants to merge 13 commits into from

Conversation

archiecobbs
Copy link
Contributor

@archiecobbs archiecobbs commented Apr 19, 2023

The Introspector class was never updated to include default methods inherited from interfaces.

This patch attempts to fix that omission.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issues

  • JDK-8071693: Introspector ignores default interface methods
  • JDK-8306477: Introspector ignores default interface methods (CSR) (Withdrawn)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/13544/head:pull/13544
$ git checkout pull/13544

Update a local copy of the PR:
$ git checkout pull/13544
$ git pull https://git.openjdk.org/jdk.git pull/13544/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 13544

View PR using the GUI difftool:
$ git pr show -t 13544

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/13544.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 19, 2023

👋 Welcome back archiecobbs! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 19, 2023
@openjdk
Copy link

openjdk bot commented Apr 19, 2023

@archiecobbs The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Apr 19, 2023
@mlbridge
Copy link

mlbridge bot commented Apr 19, 2023

import java.util.List;

import com.sun.beans.TypeResolver;
import com.sun.beans.finder.MethodFinder;

final class MethodInfo {

static final HashSet<Class<?>> IGNORABLE_INTERFACES = new HashSet<>(6);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static final HashSet<Class<?>> IGNORABLE_INTERFACES = new HashSet<>(6);
static final HashSet<Class<?>> IGNORABLE_INTERFACES = HashSet.newHashSet(6);

Or even better, use Set.of instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, much cleaner. Fixed in e37a146.

@archiecobbs archiecobbs changed the title 8182025: PropertyDescriptor ignores default methods from interfaces implemented by superclasses 8071693: Introspector ignores default interface methods Apr 19, 2023
@archiecobbs
Copy link
Contributor Author

This one probably needs a CSR.

/csr

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Apr 19, 2023
@openjdk
Copy link

openjdk bot commented Apr 19, 2023

@archiecobbs has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@archiecobbs please create a CSR request for issue JDK-8071693 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.


import com.sun.beans.TypeResolver;
import com.sun.beans.finder.MethodFinder;

final class MethodInfo {

static final Set<Class<?>> IGNORABLE_INTERFACES = Set.of(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Why only this specific interfaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This a list of commonly implemented interfaces that don't need to be inspected because they are "known empty". This list is inspired by Spring's ClassUtils. Happy to add any others that deserve to be in there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that serializable is commonly implemented, this may be a worthwhile optimisation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should have some explanation comment, about why this interfaces are ignored and how they were chosen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ac90a10.

Comment on lines 107 to 112
if (IGNORABLE_INTERFACES.contains(iface))
continue;
for (Method method : iface.getMethods()) {
if ((method.getModifiers() & Modifier.ABSTRACT) == 0)
(list = createIfNeeded(list)).add(method);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use braces even if the body has only one statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll fix. I've seen examples of both styles in the JDK so am never really sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In client libs, we tend to use the braces all the time.

By this comment, I meant adding braces to all the statements where you omitted them, including the test.

If you look through MethodInfo.java class, you see that braces are used consistently even if the body has only one statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ac90a10.

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix overall looks fine, but I'm not seeing why you think it needs a CSR.
It is just a bug fix. And if there were a CSR, it would be about the visible change, not the internals.

@archiecobbs
Copy link
Contributor Author

The fix overall looks fine, but I'm not seeing why you think it needs a CSR. It is just a bug fix.

I'm not sure if it does or not. According to the CSR FAQ, Behavioral compatibility involves operational equivalence; with "the same" inputs, does a program behave "the same way" before and after a change.

I've been dinged before for mere "bug fixes" without a CSR (see for example #10856 which made the compiler behave more closely to the spec and was eventually reverted because of it :) So, just being conservative I guess.

I'd be happy to be wrong. @jddarcy, your opinion?

@jddarcy
Copy link
Member

jddarcy commented Apr 21, 2023

The fix overall looks fine, but I'm not seeing why you think it needs a CSR. It is just a bug fix.

I'm not sure if it does or not. According to the CSR FAQ, Behavioral compatibility involves operational equivalence; with "the same" inputs, does a program behave "the same way" before and after a change.

I've been dinged before for mere "bug fixes" without a CSR (see for example #10856 which made the compiler behave more closely to the spec and was eventually reverted because of it :) So, just being conservative I guess.

I'd be happy to be wrong. @jddarcy, your opinion?

Hmmm. I'm not an expert on Introspectors, but my impression is the behavior change is CSR-worthy. HTH

@prrace
Copy link
Contributor

prrace commented Apr 21, 2023

The fix overall looks fine, but I'm not seeing why you think it needs a CSR. It is just a bug fix.

I'm not sure if it does or not. According to the CSR FAQ, Behavioral compatibility involves operational equivalence; with "the same" inputs, does a program behave "the same way" before and after a change.

By that criterion every change needs a CSR.
Gosh, it used to SEGV, now it doesn't - I'd better file a CSR !

I've been dinged before for mere "bug fixes" without a CSR (see for example #10856 which made the compiler behave more closely to the spec and was eventually reverted because of it :) So, just being conservative I guess.
I'd be happy to be wrong. @jddarcy, your opinion?

Hmmm. I'm not an expert on Introspectors, but my impression is the behavior change is CSR-worthy. HTH

Maybe but regardless the CSR that has been written is very wrong, as I already commented there.
If you could write something up that sticks to specification or describing behaviour that rises to the level of implied
specification, using words, not code, then we can consider it.

All it needs to say is
"Previously, the introspector would ignore interfaces, since before default methods were added to the language, there
could be no implementation. Now interfaces are considered like other classes"

That's it, isn't it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it expected that the test file doesn't compile with simple javac DefaultMethodBeanPropertyTest.java? It complains about BeanUtils not found. When run with jtreg, the test compiles successfully.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it expected that the test file doesn't compile with simple javac DefaultMethodBeanPropertyTest.java?

Definitely not. For example, many regression tests use classes that are not part of the standard JDK such as toolbox.ToolBox.

@archiecobbs
Copy link
Contributor Author

Let's make this CSR question easy. I'll remove the CSR and see if anybody actually complains :)

/csr unneeded

@openjdk
Copy link

openjdk bot commented Apr 21, 2023

@archiecobbs only Reviewers can determine that a CSR is not needed.

@archiecobbs
Copy link
Contributor Author

Let's make this CSR question easy. I'll remove the CSR and see if anybody actually complains :)

Ugh, it looks like the bot won't let me do that. A reviewer will have to remove the CSR....

@prrace
Copy link
Contributor

prrace commented Apr 21, 2023

/csr unneeded

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Apr 21, 2023
@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Apr 24, 2023
import java.util.Arrays;
import java.util.HashSet;

public class DefaultMethodBeanPropertyTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please add two additional tests to verify the "diamond" case:

  • getFoo is in the top interfaceA, two empty subinterfaces B anc C , and one class D of B and C, will the D have one correct prop Foo?
  • getFoo is in the top interfaceA, two non-empty subinterfaces B and C and each override getFoo by the different return types, and then one class D of B and C which override getFoo again by compatible type from B and C, will the D have one correct prop Foo?

We also can test the case if the D from the cases above is interface and implemented by the class E.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing... see 6b43627.

findProperty(ClassB.class, "foo");

// Expected properties
final HashSet<PropertyDescriptor> expected = new HashSet<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please split the long lines to use 80 chars per line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e6a2ecb.

Copy link
Member

@mrserb mrserb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine.

@archiecobbs
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Apr 24, 2023
@openjdk
Copy link

openjdk bot commented Apr 24, 2023

@archiecobbs
Your change (at version e6a2ecb) is now ready to be sponsored by a Committer.

@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Apr 25, 2023
@archiecobbs
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Apr 25, 2023
@openjdk
Copy link

openjdk bot commented Apr 25, 2023

@archiecobbs
Your change (at version b92726a) is now ready to be sponsored by a Committer.

@mrserb
Copy link
Member

mrserb commented Apr 26, 2023

/sponsor

@openjdk
Copy link

openjdk bot commented Apr 26, 2023

Going to push as commit 1e4eafb.
Since your change was applied there have been 40 commits pushed to the master branch:

  • 750bece: 8305771: SA ClassWriter.java fails to skip overpass methods
  • b81c9c8: 8306951: [BACKOUT] JDK-8305252 make_method_handle_intrinsic may call java code under a lock
  • 732179c: 8306409: Open source AWT KeyBoardFocusManger, LightWeightComponent related tests
  • 38cc039: 8306705: com/sun/jdi/PopAndInvokeTest.java fails with NativeMethodException
  • 01b8512: 8302182: Update Public Suffix List to 88467c9
  • 8e36c05: 8305853: java/text/Format/DateFormat/DateFormatRegression.java fails with "Uncaught exception thrown in test method Test4089106"
  • d0e8aec: 8306374: (bf) Improve performance of DirectCharBuffer::append(CharSequence[,int,int])
  • a18191f: 8302328: [s390x] Simplify asm_assert definition
  • 9bc6a21: 8306033: Resolve multiple definition of 'throwIOException' and friends when statically linking with JDK native libraries
  • 35e8023: 8306872: Rename Node_Array::Size()
  • ... and 30 more: https://git.openjdk.org/jdk/compare/bad6aa68e4d491e819ab22e91dd5d65bb094120e...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 26, 2023
@openjdk openjdk bot closed this Apr 26, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Apr 26, 2023
@openjdk
Copy link

openjdk bot commented Apr 26, 2023

@mrserb @archiecobbs Pushed as commit 1e4eafb.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@jddarcy
Copy link
Member

jddarcy commented Apr 26, 2023

As a retroactive post-integration comment, there is judgement required when gauging whether or not the behavioral changes associated with a PR merit a CSR, as discussed in the CSR FAQ:

"Q: Under what conditions does a CSR need to be filed for a purely behavioral change?
A: Using qualitative terms, a CSR for a behavioral change should be filed if it is estimated enough developers or users would be sufficiently impacted by the change that it should get additional consideration or documentation. A judgment call is involved. If assistance is needed in determining whether or not a CSR needs to be filed, ask the CSR representative for that area or the CSR chair."
https://wiki.openjdk.org/display/csr/CSR+FAQs

Given my general understanding of the nature of the change, based on nature of the change, my answer to the question of whether or not this should have a CSR would be "yes", but I'm happy to defer to @prrace 's subject matter expertise here that the answer should be "no."

@archiecobbs
Copy link
Contributor Author

Maybe we should add a release note as a sort of consolation prize...?

@exabrial
Copy link

exabrial commented May 9, 2023

Hello, If I backported this to JDK17 LTS, would there be any chance of acceptance?

Open Source work often goes unthanked, so I do wish to express my gratitude for fixing this. Unfortunately it does create headaches in JDK17 as an entire class of methods are getting missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

8 participants