Skip to content

Java: Add test showing missing dispatch for incomplete parameterised type #19543

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 2 commits into
base: main
Choose a base branch
from

Conversation

aschackmull
Copy link
Contributor

Cf. #19538

The test is failing for a couple of reasons. The most important is that MethodCall.getMethod() has no results for the call, i.e. the extractor has not populated callableBinding. It's unclear what exactly we'd want the target callable to be, but it's clear what its getSourceDeclaration() should be and that's what we really need. If we fix that somehow, then we'll also need to allow ErrorType in Unification.qll, but for now that won't do anything.

@Copilot Copilot AI review requested due to automatic review settings May 20, 2025 15:04
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label May 20, 2025
@aschackmull aschackmull requested a review from a team as a code owner May 20, 2025 15:04
@github-actions github-actions bot added the Java label May 20, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a reproducer for missing virtual dispatch on error-containing generics and wires up a CodeQL query to detect it.

  • Introduce a GenericClass<T> and testDispatch method in Test.java to trigger dispatch on both valid and error types.
  • Add Dispatch.ql to query viableImpl of MethodCall.
  • Provide expected output in Dispatch.expected for the successful dispatch case.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
java/ql/test/library-tests/errortype/Test.java Added nested GenericClass<T> and testDispatch method to exercise dispatch logic
java/ql/test/library-tests/errortype/Dispatch.ql New query selecting virtual dispatch (viableImpl) matches
java/ql/test/library-tests/errortype/Dispatch.expected Expected single dispatch result for the String instantiation
Comments suppressed due to low confidence (1)

java/ql/test/library-tests/errortype/Test.java:14

  • The method testDispatch is missing a return type. Update the signature to something like public void testDispatch() so the code compiles.
public testDispatch() {

public testDispatch() {
GenericClass<String> g1 = new GenericClass<>();
g1.method();
GenericClass<NoSuchClass> g2 = new GenericClass<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, the QL-based type inference/method resolution implementation should be able to handle cases like these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's good to know.

Co-authored-by: Chris Smowton <smowton@github.com>
@smowton
Copy link
Contributor

smowton commented May 21, 2025

Suggest trying resolving this by https://github.com/github/semmle-code/tree/smowton/wip/fix-missing-methods

That fixes the database inconsistency so MethodCall.getCallee works, but it is not picked up by viableCallable yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy