Test case for #3303

This commit is contained in:
Clément Fournier committed 2021-06-23 23:36:44 +02:00
1 parent d79c2d1a0f
commit b71c1cf92e
3 files changed
+66 -7

No files matched your search

@@ -0,0 +1,23 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.rule.design.singularfield;
public class Issue3303 {
// "private" is a must for reproducing the problem
private final NoThrowingCloseable first;
Issue3303(NoThrowingCloseable first) {
this.first = first;
}
public void performClosing() {
// note: this is uncommented in the test case, it needs
// java 9
// try (first) {
// this block can be empty or not
// }
}
}
@@ -0,0 +1,10 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.rule.design.singularfield;
public interface NoThrowingCloseable extends AutoCloseable {
@Override
void close();
}
@@ -8,14 +8,16 @@
<description>failure case</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
private int x;
int bar(int y) {
public class Foo {
private int x;
int bar(int y) {
x = y + 5;
return x;
}
}
]]></code>
}
}
]]></code>
</test-code>
<test-code>
@@ -720,7 +722,31 @@ public class Foo {
private final LocalModel model;
public InternalAggregation reduce(String s) {
try (model) { }
try (model) {
}
}
}
]]></code>
</test-code>
<test-code>
<description>#3303 [java] NPE Exception applying rule SingularField on file</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
package net.sourceforge.pmd.lang.java.rule.design.singularfield;
public class Issue3303 {
// "private" is a must for reproducing the problem
private final NoThrowingCloseable first;
Issue3303(NoThrowingCloseable first) {
this.first = first;
}
public void performClosing() {
try (first) {
// this block can be empty or not
}
}
}
]]></code>