Skip to content

Java: Should FunctionalExpr be a non-extending subtype of ClassInstanceExpr? #14277

@Marcono1234

Description

@Marcono1234

Description of the issue
Currently the Java CodeQL class FunctionalExpr extends ClassInstanceExpr. This makes it inherit a lot of redundant predicates, and also some misleading ones such as getQualifier.

For example for the Java method reference this::toString, using the CodeQL MemberRefExpr::getQualifier has no result because it is not actually the qualifier (or to match the name of the other predicate, "receiver") of the method reference, that is this, but the qualifier of the creation of the synthetic anonymous class.

Since the fact that functional expressions are modelled as ClassInstanceExpr is kind of an implementation detail of the CodeQL Java extractor, would it make sense and be possible to change FunctionalExpr to not extend ClassInstanceExpr but instead let is be a "non-extending subtype" (... instanceof ClassInstanceExpr)?

In the CodeQL Java library code there are a few usages of ClassInstanceExpr predicates on a FunctionalExpr (getAnonymousClass() and getConstructedType()), but they seem to handle certain implementation details of how functional expressions are modelled as ClassInstanceExpr. Maybe if necessary a getPreciseType() / getInternalType() predicate could be added to FunctionalExpr to still allow retrieving this information.

What do you think? Maybe I am overlooking something though, and switching to a non-extending subtype has undesired side effects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions