-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
Description
When a static method of a generic type is accessed with an explicit qualifier (type access or instance), then CodeQL reports the getDeclaringType() (and getReceiverType()) as raw type.
This is incorrect and also pretty problematic because raw types have a <> suffix in their name; therefore queries checking for a specific qualified name will most likely not match, causing false negatives (see #5521).
Affected cases
Method
- Explicit type access qualifier for static method, e.g.
Generic.staticMethod()- Questionable:
getReceiverType()reports raw type
Should probably report generic type getMethod().getDeclaringType()reports raw type
- Questionable:
- Raw type instance qualifier for static method, e.g.
Generic raw = ...; raw.staticMethod()getMethod().getDeclaringType()reports raw type
Field
- Explicit type access qualifier for static field, e.g.
Generic.staticField = 1- Questionable:
getQualifier().getType()reports raw type (thoughgetField()is correct)
Should probably report generic type
- Questionable:
Example
class Generic<T> {
static void doSomething() { }
static <T> void doSomethingT() { }
static String staticF;
String f;
void test() {
// GOOD: These report generic type
doSomething();
doSomethingT();
/*
* BAD: Using declaring type as qualifier causes `getReceiverType()` and
* `getMethod().getDeclaringType()` to have raw type as result
*/
Generic.doSomething();
Generic.doSomethingT();
// GOOD: These report generic type
this.doSomething();
this.doSomethingT();
// GOOD: For fields result of `getField()` seems to be always correct
staticF = "";
/*
* QUESTIONABLE: When declaring type is used as qualifier, `getQualifier()`
* has raw type (though `getField()` is correct)
*/
Generic.staticF = "";
// GOOD: Generic type is reported
this.staticF = "";
}
void testRaw(Generic raw) {
// GOOD: Raw type is reported
raw.test();
/*
* BAD: Accessing static method with raw type as qualifier causes
* `getMethod().getDeclaringType()` to have raw type as result
*/
raw.doSomething();
raw.doSomethingT();
// GOOD: Result of `getField()` is correct, and `getQualifier()` type is raw
raw.f = "";
}
}