Skip to content

Java: Static member type of generic declaring type reports raw type as getDeclaringType() #5672

@Marcono1234

Description

@Marcono1234

Description

Similar to #5593

For a static member type of a generic declaring type, getDeclaringType() reports the 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. The most prominent example is probably java.util.Map.Entry; CodeQL currently reports the qualified name as java.util.Map<>$Entry.

This only affects static member types, non-static member types correctly report the generic type as getDeclaringType().

Example

class Generic<T> {
    // BAD: Reports Generic<> (raw) as declaring type
    static class Nested {}
    // BAD: Reports Generic<> (raw) as declaring type
    interface NestedInterface {}

    // GOOD: Reports Generic as declaring type
    class Inner {}
}

CodeQL query:

import java

from Member m
where
    m.fromSource()
    and m instanceof RefType
select m, m.getDeclaringType()

Metadata

Metadata

Assignees

No one assigned

    Labels

    JavaquestionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions