Skip to content

Commit 1cd1b14

Browse files
committed
remove some more benign results in ql/suggest-instanceof-extension
1 parent 35f9f7c commit 1cd1b14

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

ql/ql/src/codeql_ql/style/UseInstanceofExtensionQuery.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ predicate instanceofThisInCharPred(Class c, Type type) {
1616
type = instanceOf.getType().getResolvedType()
1717
) and
1818
// no existing super-type corresponds to the instanceof type, that is benign.
19-
not c.getASuperType().getResolvedType() = type
19+
not c.getType().getASuperType+() = type
2020
}
2121

2222
/** Gets an inline cast that cases `this` to `type` inside a class predicate for `c`. */
@@ -29,7 +29,7 @@ InlineCast getAThisCast(Class c, Type type) {
2929
)
3030
}
3131

32-
predicate usesFieldBasedInstanceof(Class c, TypeExpr type, FieldDecl field, ComparisonFormula comp) {
32+
predicate usesFieldBasedInstanceof(Class c, Type type, FieldDecl field, ComparisonFormula comp) {
3333
exists(FieldAccess fieldAccess |
3434
c.getCharPred().getBody() = comp or
3535
c.getCharPred().getBody().(Conjunction).getAnOperand() = comp
@@ -39,8 +39,9 @@ predicate usesFieldBasedInstanceof(Class c, TypeExpr type, FieldDecl field, Comp
3939
comp.getAnOperand() instanceof ThisAccess and
4040
comp.getAnOperand() = fieldAccess and
4141
fieldAccess.getDeclaration() = field and
42-
field.getVarDecl().getTypeExpr() = type
43-
)
42+
field.getVarDecl().getType() = type
43+
) and
44+
not c.getType().getASuperType+() = type
4445
}
4546

4647
FieldAccess getARangeFieldAccess(Class c, FieldDecl field, string name) {

ql/ql/src/queries/style/UseInstanceofExtension.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from Class c, Type type, string message
1515
where
1616
(
1717
instanceofThisInCharPred(c, type) or
18-
usesFieldBasedInstanceof(c, any(TypeExpr te | te.getResolvedType() = type), _, _)
18+
usesFieldBasedInstanceof(c, type, _, _)
1919
) and
2020
message = "Consider defining this class as non-extending subtype of $@."
2121
select c, message, type.getDeclaration(), type.getName()

0 commit comments

Comments
 (0)