Skip to content

Commit c40b628

Browse files
committed
Java: Adjust ImpossibleJavadocThrows.ql
1 parent fd99ae7 commit c40b628

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import java
1313

14-
Class getTaggedType(ThrowsTag tag) {
14+
ClassOrInterface getTaggedType(ThrowsTag tag) {
1515
result.hasName(tag.getExceptionName()) and
1616
result = tag.getFile().(CompilationUnit).getATypeInScope()
1717
}
@@ -22,7 +22,9 @@ predicate canThrow(Callable callable, Class exception) {
2222
callable.getAnException().getType().getADescendant() = exception
2323
}
2424

25-
from ThrowsTag throwsTag, Class thrownType, Callable docMethod
25+
// Uses ClassOrInterface as type for thrownType to also cover case where erroneously an interface
26+
// type is declared as thrown exception
27+
from ThrowsTag throwsTag, ClassOrInterface thrownType, Callable docMethod
2628
where
2729
getTaggedType(throwsTag) = thrownType and
2830
docMethod.getDoc().getJavadoc().getAChild*() = throwsTag and
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
| ImpossibleJavadocThrows.java:9:5:9:12 | @throws | Javadoc for bad1 claims to throw InterruptedException but this is impossible. |
22
| ImpossibleJavadocThrows.java:16:5:16:15 | @exception | Javadoc for bad2 claims to throw Exception but this is impossible. |
3+
| ImpossibleJavadocThrows.java:23:5:23:12 | @throws | Javadoc for bad3 claims to throw Runnable but this is impossible. |

java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ public void bad1() {
1818
public void bad2() {
1919
}
2020

21+
/**
22+
*
23+
* @throws Runnable
24+
*/
25+
public void bad3() {
26+
}
27+
2128
/**
2229
*
2330
* @throws InterruptedException

0 commit comments

Comments
 (0)