github / github/codeql

Java: RawType getASourceSupertype() is not generic type / getting source declaration or supertype is cumbersome

Abierto
#5,521 2 comentarios 0 reacciones 0 asignados Ver en GitHub
question
Lenguaje dominante
CodeQL
Estrellas
10.1k
Forks
2.1k
Merge medio
2 d 15 h
PR fusionados (30 d)
141

Descripción

It appears that for a `RawType` the result of `getASourceSupertype()` will not be the generic type. (This is also described by the `getASourceSupertype()` [documentation](https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/Type.qll/predicate.Type$RefType$getASourceSupertype.0.html).)

In addition to that there are the following issues:
- CodeQL raw types have a `<>` at the end of their name, therefore a check for the class name such as `getDeclaringType().getASourceSupertype*().hasQualifiedName("java.util", "List")` would not hold due to the trailing `<>`.
- Access of static fields and methods declared on a generic class, but only when explicitly using the declaring class as qualifier, are treated like accesses on a raw type (`fieldAccess.getQualifier().getType()` and `methodAccess.getDeclaringType()` will have a raw type as result).
Whether that is the correct behavior might be a different story (now #5593).

This all combined causes some false negatives for the pattern `getDeclaringType().getASourceSupertype*()` (which is also used a few times in the CodeQL codebase).
Is there a more 'correct' predicate for this task? A workaround might be `getDeclaringType().getASourceSupertype*().getErasure()`.
If there is no alternative currently, would it make sense to change the behavior of `getASourceSupertype()` or introduce a new predicate?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.