Skip to content
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

[java] Fix incompatible class bounds not checked during incorporation #4982

Closed
wants to merge 10 commits into from

Conversation

jsotuyod
Copy link
Member

@jsotuyod jsotuyod commented Apr 27, 2024

Describe the PR

If an exception occurred during applicability testing it only means the candidate method is not applicable, not that an error actually occurred during inference, there is no need to abort altogether.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

 - When an applicability test fails (ie: during LUB) we don't want that
   to bubble up and fail the process, simply to discard the candidate
   and move forward. If no matching candidate is found, the inference
   will fail anyway.
@jsotuyod jsotuyod added a:bug PMD crashes or fails to analyse a file. in:type-resolution Affects the type resolution code labels Apr 27, 2024
 - throw an apropriate ResolutionFailedException so we don't loose the
   message
 - handle any exception so we don't couple tightly into the LUB
   implementation
@pmd-test
Copy link

pmd-test commented Apr 28, 2024

1 Message
📖 Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 7 new errors and 0 new configuration errors,
removes 1 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 7 new errors and 0 new configuration errors,
removes 1 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact

Generated by 🚫 Danger

@jsotuyod jsotuyod added this to the 7.2.0 milestone Apr 28, 2024
@oowekyala oowekyala self-requested a review April 28, 2024 14:08
Copy link
Member

@oowekyala oowekyala left a comment

Choose a reason for hiding this comment

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

This is going to hide actual unexpected exceptions so I don't think we should fix this that way... My intuition is that we can catch that earlier and not need to create the bad intersection. Otherwise we should have a more specific exception type for this exception and only catch that one.

@jsotuyod
Copy link
Member Author

My intuition is that we can catch that earlier and not need to create the bad intersection.

I don't see how we could do this… Assume our code is even a more adverse scenario:

public <T> T foo(T t) {
    return t;
}

public void bar() {
    Stream.of(foo("hello")); // should match Stream.of(T) by strict invocation
    Stream.of(foo(new Integer[] { 1, 2, 3 })); // should match Stream.of(T...) by strict invocation
}

Yes, we know the method is varargs, we know we are on a STRICT phase (not VARARGS), but we can't tell if the argument is or not an array until we try to resolve the context to figure out what foo(x) will return (and therefore hitting Lub).

Otherwise we should have a more specific exception type for this exception and only catch that one.

This is probably more reasonable…

@oowekyala
Copy link
Member

I'm going to take a look with a debugger...

@oowekyala
Copy link
Member

I think this should do the trick: oowekyala@6fea861

This is an incompatibility between bounds and should be checked like other bounds are checked, during incorporation.

I can't write to your branch so I just pushed into my repo.

@jsotuyod
Copy link
Member Author

@oowekyala there you go, I incorporated those changes to my branch

@jsotuyod jsotuyod requested a review from oowekyala April 29, 2024 19:57
@oowekyala oowekyala changed the title [java] Avoid exceptions during applicability testing from aborting inference altogether [java] Fix incompatible class bounds not checked during incorporation Apr 30, 2024
Copy link
Member

@oowekyala oowekyala left a comment

Choose a reason for hiding this comment

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

LGTM

Edit: Actually there are some errors I am looking into. It would be nice if you made your branch writeable to maintainers @jsotuyod, there's a checkbox to tick somewhere

-> 5dcffca

@adangel
Copy link
Member

adangel commented May 2, 2024

@jsotuyod FYI, in case you didn't see the edit:

Edit: Actually there are some errors I am looking into. It would be nice if you made your
branch writeable to maintainers @jsotuyod, there's a checkbox to tick somewhere

-> 5dcffca

@jsotuyod
Copy link
Member Author

jsotuyod commented May 2, 2024

@adangel no, Github disabled that for org-owned forks some time back… I'll have to switch my fork at some point.

@oowekyala
Copy link
Member

I opened #4994 to continue this

@oowekyala oowekyala closed this May 6, 2024
@jsotuyod jsotuyod deleted the issue-4980 branch May 6, 2024 12:42
jsotuyod added a commit that referenced this pull request May 9, 2024
 [java] Fix incompatible class bounds not checked during incorporation #4982  (second PR)
@adangel adangel removed this from the 7.2.0 milestone May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file. in:type-resolution Affects the type resolution code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[java] Bad intersection, unrelated class types java.lang.Object[] and java.lang.Number
4 participants