issue-1701 fix bug to suppress false positive in useTryWithResources when close method have multiple arguments

This commit is contained in:
Rishabh Jain
2019-03-11 22:11:24 -04:00
parent e5ca9d71bf
commit e590f29da8
3 changed files with 26 additions and 2 deletions

View File

@@ -1657,7 +1657,7 @@ preserved.
][
pmd-java:typeIs('java.lang.AutoCloseable')
or
../../PrimarySuffix/Arguments[@ArgumentCount = 1]//PrimaryPrefix[pmd-java:typeIs('java.lang.AutoCloseable')]
../../PrimarySuffix/Arguments//PrimaryPrefix[pmd-java:typeIs('java.lang.AutoCloseable')]
]]
```

View File

@@ -1546,7 +1546,7 @@ preserved.
][
pmd-java:typeIs('java.lang.AutoCloseable')
or
../../PrimarySuffix/Arguments[@ArgumentCount = 1]//PrimaryPrefix[pmd-java:typeIs('java.lang.AutoCloseable')]
../../PrimarySuffix/Arguments//PrimaryPrefix[pmd-java:typeIs('java.lang.AutoCloseable')]
]]
]]>
</value>

View File

@@ -189,4 +189,28 @@ public class TryWithResources {
}
]]></code>
</test-code>
<test-code>
<description>Custom close methods with multiple arguments</description>
<rule-property name="closeMethods">myClose2,myClose</rule-property>
<expected-problems>1</expected-problems>
<expected-linenumbers>6</expected-linenumbers>
<code><![CDATA[
import java.io.*;
public class TryWithResources {
public void run() {
InputStream in = null, in2 = null;
try {
in = openInputStream();
in2 = openInputStream();
int i = in.read(), j = in2.read();
} catch (IOException e) {
e.printStackTrace();
} finally {
myClose(in, in2);
}
}
}
]]></code>
</test-code>
</test-data>