Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

False Negative: ContradictoryTypeChecks.ql misses impossible subtype checks once the false branch is expressed through aliases or lambdas.

Aberta
#21,541 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
48/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Pouca atividade
Stack de tecnologia
java
Domínio
devtools, security

Direção de pesquisa

Leia Likely Bugs/Likely Typos/ContradictoryTypeChecks.ql junto com PosCase1_Var3.java e PosCase2_Var1.java. Rastreie como o checker trata ramos falsos, lambdas e aliases; considera-se concluído quando ambas as operações impossíveis de subtipo forem reportadas como verificações de tipo contraditórias.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

False Negative: ContradictoryTypeChecks.ql misses impossible subtype checks once the false branch is expressed through aliases or lambdas.

Version
codeql 2.24.3

Checker

  • Checker id: Likely Bugs/Likely Typos/ContradictoryTypeChecks.ql
  • Checker description: This checker detects contradictory type checks where a variable is first checked to be of a supertype via an instanceof guard, and later accessed with a cast or instanceof check for a subtype, which is impossible.

Description of the false negative

Both samples keep the same contradiction: after ruling out a supertype, the code still checks or casts the same value as if it were a subtype of that supertype. One variant hides the contradiction in a lambda branch, and the other splits it across an alias.

That is still exactly the bug Likely Bugs/Likely Typos/ContradictoryTypeChecks.ql is supposed to catch.

Affected test cases

PosCase1_Var3.java

The lambda packaging is incidental. On the false side of obj instanceof CharSequence, the code still performs String s = (String) obj, which remains contradictory.

// A variable is checked with instanceof for a supertype in a guard condition, and on the guard's false path, the same variable is cast to a subtype of that supertype should be flagged as contradictory type check.
package scensct.var.pos;

public class PosCase1_Var3 {
    public static void main(String[] args) {
        Object obj = new Object();
        // Use a ternary operator to choose a path, but keep the cast in the false branch
        Runnable action = (obj instanceof CharSequence) 
            ? () -> { CharSequence cs = (CharSequence) obj; }
            : () -> { String s = (String) obj; }; // Contradictory cast inside lambda
        action.run();
    }
}
PosCase2_Var1.java

Using temp in the guard and obj in the false branch does not change the underlying contradiction. Both names refer to the same object.

// A variable is checked with instanceof for a supertype in a guard condition, and on the guard's false path, the same variable is checked with instanceof for a subtype of that supertype should be flagged as contradictory type check.
package scensct.var.pos;

public class PosCase2_Var1 {
    public static void main(String[] args) {
        Object obj = new Object();
        // Introduce a temporary variable to alias the original
        Object temp = obj;
        // Guard condition on the alias
        if (temp instanceof CharSequence) {
            CharSequence cs = (CharSequence) temp;
        } else {
            // The false branch still refers to the original variable
            if (obj instanceof String) {
                String s = (String) obj;
            }
        }
    }
}

Cause analysis

The query seems too syntax-driven around a single if/else shape. Once the contradictory check is split across aliases or packed into another control-flow construct, the relationship between the guard and the impossible subtype operation is lost.

That makes the rule easier to bypass than it should be. The contradiction is semantic, not stylistic.

References

None known.

Linguagem predominante
CodeQL
Estrelas
10.1k
Forks
2.1k
Merge médio
2d 16h
PRs com merge (30d)
143

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de github/codeql

Todas as issues de github/codeql

Issues semelhantes

Mais issues de DevTools

Receba novas issues na sua caixa de entrada

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