mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
Merge pull request #6994 from erik-krogh/redundant-cast
Approved by RasmusWL, aschackmull, esbena, geoffw0, hvitved, nickrolfe
This commit is contained in:
@@ -150,7 +150,7 @@ private module ControlFlowGraphImpl {
|
||||
* `TypeThrowable` which results in both `TypeError` and `TypeRuntimeException`.
|
||||
*/
|
||||
UncheckedThrowableType getAnUncheckedSubtype() {
|
||||
result = this.(UncheckedThrowableType)
|
||||
result = this
|
||||
or
|
||||
result instanceof TypeError and this instanceof TypeThrowable
|
||||
or
|
||||
|
||||
@@ -665,7 +665,7 @@ final class GenericTypeNode extends PrintAstNode, TGenericTypeNode {
|
||||
override Location getLocation() { none() }
|
||||
|
||||
override ElementNode getChild(int childIndex) {
|
||||
result.getElement().(TypeVariable) = ty.getTypeParameter(childIndex)
|
||||
result.getElement() = ty.getTypeParameter(childIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -686,7 +686,7 @@ final class GenericCallableNode extends PrintAstNode, TGenericCallableNode {
|
||||
override string toString() { result = "(Generic Parameters)" }
|
||||
|
||||
override ElementNode getChild(int childIndex) {
|
||||
result.getElement().(TypeVariable) = c.getTypeParameter(childIndex)
|
||||
result.getElement() = c.getTypeParameter(childIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -150,7 +150,7 @@ private Type parameterForSubTypes(ParameterizedType type) {
|
||||
lowerBound = arg.(Wildcard).getLowerBoundType()
|
||||
|
|
||||
// `T super Foo` implies that `Foo`, or any super-type of `Foo`, may be represented.
|
||||
lowerBound.(RefType).getAnAncestor() = result
|
||||
lowerBound.getAnAncestor() = result
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ class ThrowStmt extends Stmt, @throwstmt {
|
||||
or
|
||||
exists(Stmt mid |
|
||||
mid = this.findEnclosing() and
|
||||
not exists(this.catchClauseForThis(mid.(TryStmt))) and
|
||||
not exists(this.catchClauseForThis(mid)) and
|
||||
result = mid.getEnclosingStmt()
|
||||
)
|
||||
}
|
||||
@@ -575,7 +575,7 @@ class ThrowStmt extends Stmt, @throwstmt {
|
||||
private CatchClause catchClauseForThis(TryStmt try) {
|
||||
result = try.getACatchClause() and
|
||||
result.getEnclosingCallable() = this.getEnclosingCallable() and
|
||||
this.getExpr().getType().(RefType).hasSupertype*(result.getVariable().getType().(RefType)) and
|
||||
this.getExpr().getType().(RefType).hasSupertype*(result.getVariable().getType()) and
|
||||
not this.getEnclosingStmt+() = result
|
||||
}
|
||||
|
||||
|
||||
@@ -511,7 +511,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
||||
this.getSourceDeclaration().inherits(f)
|
||||
)
|
||||
or
|
||||
this.hasMethod(m.(Method), _)
|
||||
this.hasMethod(m, _)
|
||||
}
|
||||
|
||||
/** Holds if this is a top-level type, which is not nested inside any other types. */
|
||||
|
||||
@@ -18,12 +18,12 @@ predicate isLive(Callable c) {
|
||||
* would imply the liveness of `c`.
|
||||
*/
|
||||
Callable possibleLivenessCause(Callable c, string reason) {
|
||||
c.(Method).overridesOrInstantiates(result.(Method)) and
|
||||
c.(Method).overridesOrInstantiates(result) and
|
||||
reason = "is overridden or instantiated by"
|
||||
or
|
||||
result.calls(c) and reason = "calls"
|
||||
or
|
||||
result.callsConstructor(c.(Constructor)) and reason = "calls constructor"
|
||||
result.callsConstructor(c) and reason = "calls constructor"
|
||||
or
|
||||
exists(ClassInstanceExpr e | e.getEnclosingCallable() = result |
|
||||
e.getConstructor() = c and reason = "constructs"
|
||||
@@ -93,8 +93,8 @@ class SuppressedConstructor extends Constructor {
|
||||
not this.isDefaultConstructor() and
|
||||
// Verify that there is only one statement, which is the `super()` call. This exists
|
||||
// even for empty constructors.
|
||||
this.getBody().(BlockStmt).getNumStmt() = 1 and
|
||||
this.getBody().(BlockStmt).getAStmt().(SuperConstructorInvocationStmt).getNumArgument() = 0 and
|
||||
this.getBody().getNumStmt() = 1 and
|
||||
this.getBody().getAStmt().(SuperConstructorInvocationStmt).getNumArgument() = 0 and
|
||||
// A constructor that is called is not acting to suppress the default constructor. We permit
|
||||
// calls from suppressed and default constructors - in both cases, they can only come from
|
||||
// sub-class constructors.
|
||||
@@ -243,7 +243,7 @@ class DeadMethod extends Callable {
|
||||
) and
|
||||
not (
|
||||
this.(Method).isAbstract() and
|
||||
exists(Method m | m.overridesOrInstantiates+(this.(Method)) | isLive(m))
|
||||
exists(Method m | m.overridesOrInstantiates+(this) | isLive(m))
|
||||
) and
|
||||
// A getter or setter associated with a live JPA field.
|
||||
//
|
||||
|
||||
@@ -262,7 +262,7 @@ class ManagedBeanImplEntryPoint extends EntryPoint, RegisteredManagedBeanImpl {
|
||||
// Find the method that will be called for each method on each managed bean that this class
|
||||
// implements.
|
||||
this.inherits(result) and
|
||||
result.(Method).overrides(this.getAnImplementedManagedBean().getAMethod())
|
||||
result.overrides(this.getAnImplementedManagedBean().getAMethod())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class JaxbType extends Class {
|
||||
this.getAnAnnotation() = a and
|
||||
a.getType().(JaxbAnnotationType).hasName("XmlAccessorType")
|
||||
|
|
||||
result.getAnAccess() = a.getValue("value").(VarAccess)
|
||||
result.getAnAccess() = a.getValue("value")
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -668,7 +668,7 @@ Type inheritsMatchingMethodExceptThrows(SessionEJB ejb, Method m) {
|
||||
sig = n.getSignature() and
|
||||
sig = m.getSignature() and
|
||||
exists(Exception ex | ex = n.getAnException() and not throwsExplicitUncheckedException(n, ex) |
|
||||
not ex.getType().(RefType).hasSupertype*(m.getAnException().getType()) and
|
||||
not ex.getType().hasSupertype*(m.getAnException().getType()) and
|
||||
result = ex.getType()
|
||||
)
|
||||
)
|
||||
@@ -717,7 +717,7 @@ Type inheritsMatchingCreateMethodExceptThrows(StatefulSessionEJB ejb, EjbInterfa
|
||||
exists(Exception ex |
|
||||
ex = cm.getAnException() and not throwsExplicitUncheckedException(cm, ex)
|
||||
|
|
||||
not ex.getType().(RefType).hasSupertype*(icm.getAnException().getType()) and
|
||||
not ex.getType().hasSupertype*(icm.getAnException().getType()) and
|
||||
result = ex.getType()
|
||||
)
|
||||
)
|
||||
@@ -732,7 +732,7 @@ Type inheritsMatchingCreateMethodExceptThrows(StatefulSessionEJB ejb, EjbInterfa
|
||||
exists(Exception ex |
|
||||
ex = im.getAnException() and not throwsExplicitUncheckedException(im, ex)
|
||||
|
|
||||
not ex.getType().(RefType).hasSupertype*(icm.getAnException().getType()) and
|
||||
not ex.getType().hasSupertype*(icm.getAnException().getType()) and
|
||||
result = ex.getType()
|
||||
)
|
||||
)
|
||||
|
||||
@@ -141,8 +141,7 @@ class ExternalAPIUsedWithUntrustedData extends TExternalAPI {
|
||||
|
|
||||
this = TExternalAPIParameter(m, index) and
|
||||
result =
|
||||
m.getDeclaringType().(RefType).getQualifiedName() + "." + m.getSignature() + " [" +
|
||||
indexString + "]"
|
||||
m.getDeclaringType().getQualifiedName() + "." + m.getSignature() + " [" + indexString + "]"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,9 +395,7 @@ class MavenRepo extends Folder {
|
||||
/**
|
||||
* Gets a Jar file contained within this repository.
|
||||
*/
|
||||
File getAJarFile() {
|
||||
result = this.getAChildContainer*().(File) and result.getExtension() = "jar"
|
||||
}
|
||||
File getAJarFile() { result = this.getAChildContainer*() and result.getExtension() = "jar" }
|
||||
|
||||
/**
|
||||
* Gets any jar artifacts in this repository that match the POM project definition. This is an
|
||||
|
||||
Reference in New Issue
Block a user