forked from phoedos/pmd
Merge branch 'pr-1503'
This commit is contained in:
docs/pages
pmd-java/src
main/resources/category/java
test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml
@ -2790,7 +2790,7 @@ Avoid returning from a finally block, this can discard exceptions.
|
|||||||
|
|
||||||
**This rule is defined by the following XPath expression:**
|
**This rule is defined by the following XPath expression:**
|
||||||
``` xpath
|
``` xpath
|
||||||
//FinallyStatement//ReturnStatement
|
//FinallyStatement//ReturnStatement except //FinallyStatement//(MethodDeclaration|LambdaExpression)//ReturnStatement
|
||||||
```
|
```
|
||||||
|
|
||||||
**Example(s):**
|
**Example(s):**
|
||||||
|
@ -18,11 +18,14 @@ This is a {{ site.pmd.release_type }} release.
|
|||||||
|
|
||||||
* java-bestpractices
|
* java-bestpractices
|
||||||
* [#658](https://github.com/pmd/pmd/issues/658): \[java] OneDeclarationPerLine: False positive for loops
|
* [#658](https://github.com/pmd/pmd/issues/658): \[java] OneDeclarationPerLine: False positive for loops
|
||||||
|
* java-errorprone
|
||||||
|
* [#1035](https://github.com/pmd/pmd/issues/1035): \[java] ReturnFromFinallyBlock: False positive on lambda expression in finally block
|
||||||
|
|
||||||
### API Changes
|
### API Changes
|
||||||
|
|
||||||
### External Contributions
|
### External Contributions
|
||||||
|
|
||||||
|
* [#1503](https://github.com/pmd/pmd/pull/1503): \[java] Fix for ReturnFromFinallyBlock false-positives - [RishabhDeep Singh](https://github.com/rishabhdeepsingh)
|
||||||
* [#1516](https://github.com/pmd/pmd/pull/1516): \[java] OneDeclarationPerLine: Don't report multiple variables in a for statement. - [Kris Scheibe](https://github.com/kris-scheibe)
|
* [#1516](https://github.com/pmd/pmd/pull/1516): \[java] OneDeclarationPerLine: Don't report multiple variables in a for statement. - [Kris Scheibe](https://github.com/kris-scheibe)
|
||||||
* [#1521](https://github.com/pmd/pmd/pull/1521): \[java] Upgrade to ASM7 for JDK 11 support - [Mark Pritchard](https://github.com/markpritchard)
|
* [#1521](https://github.com/pmd/pmd/pull/1521): \[java] Upgrade to ASM7 for JDK 11 support - [Mark Pritchard](https://github.com/markpritchard)
|
||||||
|
|
||||||
|
@ -2666,8 +2666,9 @@ Avoid returning from a finally block, this can discard exceptions.
|
|||||||
</description>
|
</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<properties>
|
<properties>
|
||||||
|
<property name="version" value="2.0"/>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
<value>//FinallyStatement//ReturnStatement</value>
|
<value>//FinallyStatement//ReturnStatement except //FinallyStatement//(MethodDeclaration|LambdaExpression)//ReturnStatement</value>
|
||||||
</property>
|
</property>
|
||||||
</properties>
|
</properties>
|
||||||
<example>
|
<example>
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
|
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
|
||||||
<test-code>
|
<test-code>
|
||||||
<description><![CDATA[
|
<description>throw exception but return from finally</description>
|
||||||
throw exception but return from finally
|
|
||||||
]]></description>
|
|
||||||
<expected-problems>1</expected-problems>
|
<expected-problems>1</expected-problems>
|
||||||
<code><![CDATA[
|
<code><![CDATA[
|
||||||
public class Foo {
|
public class Foo {
|
||||||
@ -23,9 +21,7 @@ public class Foo {
|
|||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
<test-code>
|
<test-code>
|
||||||
<description><![CDATA[
|
<description>lots of returns</description>
|
||||||
lots of returns
|
|
||||||
]]></description>
|
|
||||||
<expected-problems>1</expected-problems>
|
<expected-problems>1</expected-problems>
|
||||||
<code><![CDATA[
|
<code><![CDATA[
|
||||||
public class Foo {
|
public class Foo {
|
||||||
@ -42,9 +38,7 @@ public class Foo {
|
|||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
<test-code>
|
<test-code>
|
||||||
<description><![CDATA[
|
<description>ok</description>
|
||||||
ok
|
|
||||||
]]></description>
|
|
||||||
<expected-problems>0</expected-problems>
|
<expected-problems>0</expected-problems>
|
||||||
<code><![CDATA[
|
<code><![CDATA[
|
||||||
public class Foo {
|
public class Foo {
|
||||||
@ -57,4 +51,93 @@ public class Foo {
|
|||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
<test-code>
|
||||||
|
<description>#1035 [java] ReturnFromFinallyBlock: False positive on lambda expression in finally block</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
String bar() {
|
||||||
|
try {
|
||||||
|
} finally {
|
||||||
|
Object o = new Object() {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
<test-code>
|
||||||
|
<description>Return from Lambda in Finally</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
String getBar() {
|
||||||
|
try {
|
||||||
|
} finally {
|
||||||
|
Collection<ServiceExecutionEntry> untracked = serviceExecutionTracker.untrackMatchingEntries(e -> {
|
||||||
|
ServiceExecutionIdentifiers ids = e.getIdentifiers();
|
||||||
|
Long execBqiId = (ids == null) ? null : ids.getBqiId();
|
||||||
|
return Objects.equals(bqiId, execBqiId);
|
||||||
|
});
|
||||||
|
untracked.forEach(e -> logger.info("overwriteLastBqi(bqId={}, bqiId={}) untracked {}", bqId, bqiId, e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
<test-code>
|
||||||
|
<description>return from a lambda should not cause issues</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
void printSomething() {
|
||||||
|
try {
|
||||||
|
System.out.println("Integers: ");
|
||||||
|
} finally {
|
||||||
|
Arrays.asList(0, 1, 2).map(i -> { return i + 1; }).forEach(i -> System.out.println(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
<test-code>
|
||||||
|
<description>Return in finally should give error but not in lambda</description>
|
||||||
|
<expected-problems>1</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
String printSomething() {
|
||||||
|
try {
|
||||||
|
System.out.println("Integers: ");
|
||||||
|
} finally {
|
||||||
|
Arrays.asList(0, 1, 2).map(i -> { return i + 1; }).forEach(i -> System.out.println(i));
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
<test-code>
|
||||||
|
<description>Return from anonyous class should not give any error</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
void printSomething() {
|
||||||
|
try {
|
||||||
|
System.out.println("Integers: ");
|
||||||
|
} finally {
|
||||||
|
Arrays.asList(0, 1, 2).map(new Function<Integer, Integer>() {
|
||||||
|
@Override
|
||||||
|
public Integer apply(Integer i) {
|
||||||
|
return i + 1;
|
||||||
|
}
|
||||||
|
}).forEach(i -> System.out.println(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
</test-data>
|
</test-data>
|
||||||
|
Reference in New Issue
Block a user