-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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>
andtestDispatch
method inTest.java
to trigger dispatch on both valid and error types. - Add
Dispatch.ql
to queryviableImpl
ofMethodCall
. - 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 likepublic void testDispatch()
so the code compiles.
public testDispatch() {
public testDispatch() { | ||
GenericClass<String> g1 = new GenericClass<>(); | ||
g1.method(); | ||
GenericClass<NoSuchClass> g2 = new GenericClass<>(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
Suggest trying resolving this by https://github.com/github/semmle-code/tree/smowton/wip/fix-missing-methods That fixes the database inconsistency so |
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 populatedcallableBinding
. It's unclear what exactly we'd want the target callable to be, but it's clear what itsgetSourceDeclaration()
should be and that's what we really need. If we fix that somehow, then we'll also need to allowErrorType
inUnification.qll
, but for now that won't do anything.