Merge branch 'master' of https://github.com/albfernandez/pmd
This commit is contained in:
commit
499520ae9c
2 files changed
+35
-2
No files matched your search
@@ -160,6 +160,19 @@ public class CloseResourceRule extends AbstractJavaRule {
|
||||
closed = true;
|
||||
break;
|
||||
}
|
||||
if (name.contains(".")) {
|
||||
String[] parts = name.split("\\.");
|
||||
if (parts.length == 2) {
|
||||
String methodName = parts[1];
|
||||
String varName = parts[0];
|
||||
if (varName.equals(variableToClose)
|
||||
&& closeTargets.contains(methodName)) {
|
||||
closed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (closed) {
|
||||
break;
|
||||
|
||||
+22
-2
@@ -153,7 +153,7 @@ New use case
|
||||
]]></description>
|
||||
<rule-property name="closeTargets">commit,close,close,close</rule-property>
|
||||
<rule-property name="types">DAOTransaction,Connection,Statement,ResulSet</rule-property>
|
||||
<expected-problems>2</expected-problems>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
import java.sql.*;
|
||||
public class Foo {
|
||||
@@ -425,4 +425,24 @@ public class Test {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
||||
<test-code>
|
||||
<description><![CDATA[Custom close method, should be ok]]></description>
|
||||
<rule-property name="closeTargets">cleanup</rule-property>
|
||||
<rule-property name="types">MyClass</rule-property>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar() {
|
||||
MyClass myClass = null;
|
||||
try {
|
||||
myClass = new MyClass();
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
myClass.cleanup(); // should be ok, it's closed with cleanup
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
Reference in new issue
Block a user