diff --git a/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql b/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql index 7e2738af1e1..7f8f4d4f983 100644 --- a/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql +++ b/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql @@ -16,21 +16,14 @@ RefType getTaggedType(ThrowsTag tag) { exists(ImportType i | i.getFile() = tag.getFile() | i.getImportedType() = result) } -predicate canThrow(Callable callable, RefType exception) { - exists(string uncheckedException | - uncheckedException = "RuntimeException" or uncheckedException = "Error" - | - exception.getAnAncestor().hasQualifiedName("java.lang", uncheckedException) - ) - or - callable.getAnException().getType().getADescendant() = exception -} - -from ThrowsTag throwsTag, RefType thrownType, Callable docMethod +// Uses ClassOrInterface as type for thrownType to also cover case where erroneously an interface +// type is declared as thrown exception +from ThrowsTag throwsTag, ClassOrInterface thrownType, Callable docMethod where getTaggedType(throwsTag) = thrownType and docMethod.getDoc().getJavadoc().getAChild*() = throwsTag and - not canThrow(docMethod, thrownType) + not thrownType instanceof UncheckedThrowableType and + not docMethod.getAnException().getType().getADescendant() = thrownType select throwsTag, "Javadoc for " + docMethod + " claims to throw " + thrownType.getName() + " but this is impossible."