Skip to content

Commit 26b630f

Browse files
committed
Java: clarify help for java/unreachable-catch-clause
1 parent 001b9f8 commit 26b630f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
FileInputStream fis = null;
1+
FileOutputStream fos = null;
22
try {
3-
fis = new FileInputStream(new File("may_not_exist.txt"));
4-
// read from input stream
3+
fos = new FileOutputStream(new File("may_not_exist.txt"));
54
} catch (FileNotFoundException e) {
65
// ask the user and try again
76
} catch (IOException e) {
87
// more serious, abort
98
} finally {
10-
if (fis!=null) { try { fis.close(); } catch (IOException e) { /*ignore*/ } }
9+
if (fos!=null) { try { fos.close(); } catch (IOException e) { /*ignore*/ } }
1110
}

java/ql/src/Likely Bugs/Statements/PartiallyMaskedCatch.qhelp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ than one of the <code>catch</code> clauses, only the first matching clause is ex
4545
</recommendation>
4646
<example>
4747

48-
<p>In the following example, the second <code>catch</code> clause is unreachable, and can be removed.</p>
48+
<p>
49+
In the following example, the second <code>catch</code> clause is unreachable.
50+
The code is incomplete because a <code>FileOutputStream</code> is opened but
51+
no methods are called to write to the stream. Such methods typically throw
52+
<code>IOException</code>s, which would make the second <code>catch</code> clause
53+
reachable.
54+
</p>
4955

5056
<sample src="PartiallyMaskedCatch.java" />
5157

0 commit comments

Comments
 (0)