From c40b6285a29563ea812b7496de0f1a45aea8935a Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Mon, 26 Sep 2022 12:08:43 +0200 Subject: [PATCH] Java: Adjust `ImpossibleJavadocThrows.ql` --- .../src/Advisory/Documentation/ImpossibleJavadocThrows.ql | 6 ++++-- .../query-tests/Javadoc/ImpossibleJavadocThrows.expected | 1 + .../test/query-tests/Javadoc/ImpossibleJavadocThrows.java | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql b/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql index 2452dda4fc4..3111c704b4d 100644 --- a/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql +++ b/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql @@ -11,7 +11,7 @@ import java -Class getTaggedType(ThrowsTag tag) { +ClassOrInterface getTaggedType(ThrowsTag tag) { result.hasName(tag.getExceptionName()) and result = tag.getFile().(CompilationUnit).getATypeInScope() } @@ -22,7 +22,9 @@ predicate canThrow(Callable callable, Class exception) { callable.getAnException().getType().getADescendant() = exception } -from ThrowsTag throwsTag, Class 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 diff --git a/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.expected b/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.expected index f94a6f61f33..5b031604e56 100644 --- a/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.expected +++ b/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.expected @@ -1,2 +1,3 @@ | ImpossibleJavadocThrows.java:9:5:9:12 | @throws | Javadoc for bad1 claims to throw InterruptedException but this is impossible. | | ImpossibleJavadocThrows.java:16:5:16:15 | @exception | Javadoc for bad2 claims to throw Exception but this is impossible. | +| ImpossibleJavadocThrows.java:23:5:23:12 | @throws | Javadoc for bad3 claims to throw Runnable but this is impossible. | diff --git a/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.java b/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.java index 7ba8988c38b..b0b27397359 100644 --- a/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.java +++ b/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.java @@ -18,6 +18,13 @@ class ImpossibleJavadocThrows { public void bad2() { } + /** + * + * @throws Runnable + */ + public void bad3() { + } + /** * * @throws InterruptedException