Skip to content

Commit 80a7c05

Browse files
committed
Detect usage of value-based class as key for IdentityHashMap
1 parent 2e5a35c commit 80a7c05

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

codeql-custom-queries-java/queries/error-prone/value-based-class-identity-sensitive-operation.ql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* must only be compared using `equals(Object)` and `hashCode()`.
66
*
77
* See also https://bugs.openjdk.java.net/browse/JDK-8249100
8+
*
9+
* @kind problem
810
*/
911

1012
import java
@@ -96,6 +98,11 @@ class ValueBasedForbiddenExpr extends Expr {
9698
or exists(IdentityHashCodeCall hashCodeCall |
9799
hashCodeCall.getArgument(0) = this
98100
)
101+
or exists(TypeAccess identityHashMapType |
102+
identityHashMapType.getType().(RefType).getSourceDeclaration().hasQualifiedName("java.util", "IdentityHashMap")
103+
// `this` is the key type of the map, on which reference equality checks are performed
104+
and this = identityHashMapType.getTypeArgument(0)
105+
)
99106
}
100107
}
101108

0 commit comments

Comments
 (0)