github / github/codeql

LGTM.com - false positive - Dereferenced variable may be null

Aperta
#2,630 5 commenti 0 reazioni 1 assegnatario Rivendicata da @aschackmull Vedi su GitHub
false-positive Java
Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 15h
PR unite (30g)
141

Descrizione

https://lgtm.com/projects/g/quickfix-j/quickfixj/snapshot/9657839bf46838645b670486e57852de40d34f04/files/quickfixj-core/src/main/java/quickfix/Message.java?sort=name&dir=ASC&mode=heatmap#xaced2743c6d7c82:1

To be honest it is quite tricky to find out that the variable `group` cannot be null. This is conveyed via boolean `firstFieldFound` which is only set when `group` has been assigned. See here:

https://lgtm.com/projects/g/quickfix-j/quickfixj/snapshot/9657839bf46838645b670486e57852de40d34f04/files/quickfixj-core/src/main/java/quickfix/Message.java?sort=name&dir=ASC&mode=heatmap#L707

But if `firstFieldFound` is false an Exception would be thrown from here:
https://lgtm.com/projects/g/quickfix-j/quickfixj/snapshot/9657839bf46838645b670486e57852de40d34f04/files/quickfixj-core/src/main/java/quickfix/Message.java?sort=name&dir=ASC&mode=heatmap#L720

However, I wanted to make the null-check easier to spot for LGTM by removing the boolean variable and simply check for `group!=null` in `checkFirstFieldFound()` but the alert is still not removed. This can be seen here:

https://lgtm.com/projects/g/quickfix-j/quickfixj/rev/pr-e6092b79d8f5ba3d89e1644bd0153b8c5b22f5bb

The only alert not fixed by that PR is the possible null pointer dereference:
https://lgtm.com/projects/g/quickfix-j/quickfixj/snapshot/9657839bf46838645b670486e57852de40d34f04/files/quickfixj-core/src/main/java/quickfix/Message.java?sort=name&dir=ASC&mode=heatmap#xaced2743c6d7c82:1

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.