github / github/codeql

Java: `MemberRefExpr.asMethod()` uses parameter types of referenced callable instead of types of functional method

Aberta
#5,706 0 comentários 0 reações 0 responsáveis Ver no GitHub
enhancement Java
Linguagem predominante
CodeQL
Estrelas
10.1k
Forks
2.1k
Merge médio
2d 15h
PRs com merge (30d)
141

Descrição

### Description
Relates to #3605

`MemberRefExpr.asMethod()` uses the parameter types of the referenced callable instead of the parameter types of the functional method it implements. For example using `void consumeObject(Object)` as referenced method for an `IntConsumer` will cause `asMethod()` to report that the signature is `consume(Object)` instead of `consume(int)`.

This prevents detecting any conversions, e.g. boxing or unboxing, which happen when the referenced callable would be called.
As workaround it is possible to check for the overridden method (because interestingly CodeQL at least claims that `consume(Object)` overrides `consume(int)`).

### Example
Java source:
```java
import java.util.function.*;

class MemberRefExprTest {
void consumeLong(long l) {
}

void consumeFloat(float f) {
}

void consumeObject(Object o) {
}

void test() {
// asMethod(): consume(long)
IntConsumer m1 = this::consumeLong;
// asMethod(): consume(float)
IntConsumer m2 = this::consumeFloat;
// asMethod(): consume(Object)
IntConsumer m3 = this::consumeObject;

// asMethod(): consume(Object)
Consumer m4 = this::consumeObject;
}
}
```

CodeQL query:
```ql
import java

from MemberRefExpr m, Method asMethod, Method overridden
where
asMethod = m.asMethod()
and asMethod.overrides(overridden)
select m, m.getReferencedCallable().getStringSignature() as referencedSig, asMethod.getStringSignature() as methodSig,
overridden.getStringSignature() as overriddenSig
```

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.