False Negative: EqualsArray.ql misses array identity comparisons once the array is widened to `Object` or routed through helper APIs.
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 48/100
Piste de recherche
Commencez par le checker Likely Bugs/Comparison/EqualsArray.ql et examinez les cas affectés PosCase1_Var2.java, PosCase2_Var1.java et PosCase2_Var2.java. Suivez la manière dont les références Object élargies et Objects.equals(...) sont modélisées. Le travail est terminé lorsque ces comparaisons d’identité sont détectées sans perdre la couverture existante des appels directs.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
False Negative: EqualsArray.ql misses array identity comparisons once the array is widened to Object or routed through helper APIs.
Version
codeql 2.24.3
Checker
- Checker id:
Likely Bugs/Comparison/EqualsArray.ql - Checker description: Detects calls to equals or hashCode methods on array objects, which compare object identity rather than array contents.
Description of the false negative
These samples still use array identity operations where content comparison was almost certainly intended. The difference is only that the array is first widened to Object or compared through Objects.equals(...), which still ends up using reference equality for arrays.
Affected test cases
PosCase1_Var2.java
Widening the array to Object does not change the fact that equals still performs identity comparison.
// Calling hashCode() on an array should be flagged as comparing object identity.
package scensct.var.pos;
public class PosCase1_Var2 {
public static void main(String[] args) {
// Variant 2: Intra-procedural refactoring - using a temporary reference
int[] arr = {1, 2, 3};
Object objRef = arr;
int hash = objRef.hashCode(); // Still calling hashCode on the array object
System.out.println(hash);
}
}
PosCase2_Var1.java
Calling equals(Object) on the array still compares object identity rather than contents.
// Calling equals(Object) on an array with compatible array argument should be flagged as comparing object identity.
package scensct.var.pos;
public class PosCase2_Var1 {
public static void main(String[] args) {
Integer[] a = {1, 2, 3};
Integer[] b = {1, 2, 3};
// Using a temporary variable to alias the array
Object obj1 = a;
Object obj2 = b;
boolean same = obj1.equals(obj2);
System.out.println(same);
}
}
PosCase2_Var2.java
The helper API does not change the semantics of array equals; it is still an identity comparison.
// Calling equals(Object) on an array with compatible array argument should be flagged as comparing object identity.
package scensct.var.pos;
import java.util.Objects;
public class PosCase2_Var2 {
public static void main(String[] args) {
String[] arr1 = {"x", "y"};
String[] arr2 = {"x", "y"};
// Using Objects.equals which internally calls equals on the first argument
boolean result = Objects.equals(arr1, arr2);
System.out.println(result);
}
}
Cause analysis
The query appears to recognize only direct array.equals(...) or array.hashCode() calls on obviously array-typed expressions. Once the array is widened to Object or the call is wrapped by a library helper like Objects.equals(...), the identity-based behavior is no longer modeled.
That is a real usability gap. Developers often pass arrays through generic APIs before comparing them, and the bug remains the same.
References
None known.
- Langage dominant
- CodeQL
- Étoiles
- 10.1k
- Forks
- 2.1k
- Merge moyen
- 2 j 16 h
- PR mergées (30 j)
- 143
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de github/codeql
-
agentic-workflows
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
-
false-positive javascript
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
false-positive
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Toutes les issues de github/codeql
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
palladius/rails8-app-on-gcp#145 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
elastic/gradle-plugins#156 ·
-
area:workflow bug ready-for-agent
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
fil-donadoni/tolaria#4409 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
dotenvx/dotenv-vscode#139 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Fission-AI/OpenSpec#1960 ·