IDEA-115468 (for loop variables, catch block parameters and resource variables not reported by "local variable or parameter can be final" inspection)

This commit is contained in:
Bas Leijdekkers
2013-10-28 16:44:04 +01:00
parent 0024cf32e8
commit e62f352ab9
8 changed files with 93 additions and 1 deletions
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>CatchParameter.java</file>
<line>8</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Local variable or parameter can be final</problem_class>
<description>Parameter &lt;code&gt;e&lt;/code&gt; can have &lt;code&gt;final&lt;/code&gt; modifier</description>
</problem>
</problems>
@@ -0,0 +1,12 @@
import java.io.*;
class CatchParameter {
void m() {
try (InputStream in = new FileInputStream("filename")) { // don't warn about 'in' because it is implicitly final
} catch (FileNotFoundException | RuntimeException e) { // don't warn about 'e' because it is implicitly final
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>For.java</file>
<line>3</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Local variable or parameter can be final</problem_class>
<description>Variable &lt;code&gt;it&lt;/code&gt; can have &lt;code&gt;final&lt;/code&gt; modifier</description>
</problem>
</problems>
@@ -0,0 +1,7 @@
class For {
void f(List<String> list) {
for (Iterator<String> it = list.iterator(); it.hasNext();) { // 'it' can be final but not reported
}
for (int i = 0; i < 10; i++) {}
}
}
@@ -15,6 +15,11 @@
<line>9</line>
<description>foo final</description>
</problem>
<problem>
<file>Junk.java</file>
<line>13</line>
<description>e final</description>
</problem>
<problem>
<file>Junk.java</file>
<line>15</line>
@@ -15,6 +15,11 @@
<line>9</line>
<description>foo final</description>
</problem>
<problem>
<file>Junk.java</file>
<line>13</line>
<description>e final</description>
</problem>
<problem>
<file>Junk.java</file>
<line>15</line>