Java: clarify help for java/unreachable-catch-clause

This commit is contained in:
yh-semmle
2018-09-19 16:01:42 -04:00
parent 001b9f8b56
commit 26b630f700
2 changed files with 10 additions and 5 deletions

View File

@@ -1,11 +1,10 @@
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(new File("may_not_exist.txt"));
// read from input stream
fos = new FileOutputStream(new File("may_not_exist.txt"));
} catch (FileNotFoundException e) {
// ask the user and try again
} catch (IOException e) {
// more serious, abort
} finally {
if (fis!=null) { try { fis.close(); } catch (IOException e) { /*ignore*/ } }
if (fos!=null) { try { fos.close(); } catch (IOException e) { /*ignore*/ } }
}

View File

@@ -45,7 +45,13 @@ than one of the <code>catch</code> clauses, only the first matching clause is ex
</recommendation>
<example>
<p>In the following example, the second <code>catch</code> clause is unreachable, and can be removed.</p>
<p>
In the following example, the second <code>catch</code> clause is unreachable.
The code is incomplete because a <code>FileOutputStream</code> is opened but
no methods are called to write to the stream. Such methods typically throw
<code>IOException</code>s, which would make the second <code>catch</code> clause
reachable.
</p>
<sample src="PartiallyMaskedCatch.java" />