aboutsummaryrefslogtreecommitdiff
path: root/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding
diff options
context:
space:
mode:
authorLuolc <luolc.witty@gmail.com>2017-03-20 00:15:06 +0800
committerRoman Ivanov <romani@users.noreply.github.com>2017-03-23 11:12:46 -0700
commite69ca128dd850bd7941d999b0a416ec3229af7a5 (patch)
tree639c420b71c924059f600d1ea097ae525304a6f7 /src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding
parent9c70477fb449f50ca6ad54995ce0f1855d48e450 (diff)
downloadcheckstyle-e69ca128dd850bd7941d999b0a416ec3229af7a5.tar.gz
Issue #3172: Regression false-positive FinalLocalVariable
Diffstat (limited to 'src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding')
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputFinalLocalVariableFalsePositives.java219
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputFinalLocalVariableLeavingSlistToken.java59
2 files changed, 278 insertions, 0 deletions
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputFinalLocalVariableFalsePositives.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputFinalLocalVariableFalsePositives.java
index 68fde4cc3..8c6d44af8 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputFinalLocalVariableFalsePositives.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputFinalLocalVariableFalsePositives.java
@@ -1,5 +1,8 @@
package com.puppycrawl.tools.checkstyle.checks.coding;
+import java.util.ArrayList;
+import java.util.Arrays;
+
public class InputFinalLocalVariableFalsePositives {
// spring-framework/spring-web/src/main/java/org/springframework/web/multipart/commons/CommonsFileUploadSupport.java
@@ -2201,4 +2204,220 @@ public class InputFinalLocalVariableFalsePositives {
}
b = "b";
}
+
+ private void foo91() {
+ Integer[] s;
+ if (true) {
+ s = new Integer[0];
+ } else {
+ s = new Integer[5];
+ if (true) {
+ final ArrayList<Integer> retain = new ArrayList<>();
+ for (final Integer c : s) {
+ if (true) {
+ retain.add(c);
+ }
+ }
+ s = retain.toArray(new Integer[retain.size()]);
+ }
+ if (true && s.length > 0) {
+ s = new Integer[] {s[0]};
+ }
+ }
+ Arrays.toString(s);
+ }
+
+ // findbugs/src/java/edu/umd/cs/findbugs/ba/jsr305/TypeQualifierApplications.java
+ private void foo92() {
+ String tqa;
+ if (true) {
+ tqa = null;
+ if (true) {
+ }
+ }
+ else {
+ if (true) {
+ }
+ tqa = "a";
+ if (true) {
+ }
+ if (tqa == null) {
+ if (true) {
+ }
+ tqa = "b";
+ if (true) {
+ if (tqa == "abc") {
+ } else if (tqa != null) {
+ } else {
+ }
+ }
+ }
+ if (tqa == "bcd") {
+ tqa = null;
+ }
+ if (tqa == null) {
+ if (true) {
+ if (true) {
+ }
+ } else {
+ if (true) {
+ }
+ tqa = "c";
+ if (true) {
+ }
+ }
+ }
+ }
+ }
+
+ // hibernate-core/src/main/java/org/hibernate/internal/util/collections/BoundedConcurrentHashMap.java
+ private void foo93() {
+ if (true) {
+ String evictedCopy;
+ if (true) {
+ final String evictedEntry = "a";
+ evictedCopy = evictedEntry;
+ } else {
+ evictedCopy = "c";
+ for (int i = 0; i < 0; ++i) {
+ evictedCopy.trim();
+ }
+ evictedCopy = evictedCopy.trim();
+ }
+ }
+ }
+
+ // spring-framework/spring-core/src/main/java/org/springframework/core/Conventions.java
+ private void foo94() {
+ String valueClass;
+ if (true) {
+ valueClass = "a";
+ }
+ else if (true) {
+ valueClass = "b";
+ if (valueClass == null) {
+ if (true) {
+ }
+ if (true) {
+ }
+ valueClass = "c";
+ }
+ }
+ else {
+ valueClass = "d";
+ }
+ }
+
+ // spring-framework/spring-test/src/main/java/org/springframework/test/annotation/ProfileValueUtils.java
+ private void foo95() {
+ String profileValueSource;
+ if (true) {
+ profileValueSource = "a";
+ }
+ else {
+ try {
+ profileValueSource = "b";
+ }
+ catch (Exception e) {
+ if (true) {
+ }
+ profileValueSource = "c";
+ }
+ }
+ }
+
+ // spring-framework/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java
+ private void foo96() {
+ Object arg;
+ if (true) {
+ arg = "a";
+ }
+ else if (true) {
+ arg = "b";
+ }
+ else if (true) {
+ arg = "c";
+ }
+ else if (true) {
+ arg = "d";
+ }
+ else if (true) {
+ arg = "e";
+ }
+ else if (true) {
+ arg = "f";
+ }
+ else {
+ try {
+ arg = "g";
+ if (arg != null) {
+ if (true) {
+ }
+ }
+ }
+ catch (Exception ex) {
+ arg = null;
+ }
+ }
+ }
+
+ // infinispan/commons/src/main/java/org/infinispan/commons/util/concurrent/jdk8backported/BoundedEquivalentConcurrentHashMapV8.java
+ private void foo97() {
+ if (true) {
+ String evictedCopy;
+ if (true) {
+ evictedCopy = "b";
+ } else {
+ evictedCopy = "c";
+ for (int i = 0; i < 0; ++i) {
+ }
+ evictedCopy = "d";
+ }
+ }
+ }
+
+ // infinispan/core/src/main/java/org/infinispan/util/concurrent/BoundedConcurrentHashMap.java
+ private void foo98() {
+ if (true) {
+ String evictedCopy;
+ if (true) {
+ evictedCopy = "b";
+ } else {
+ evictedCopy = "c";
+ for (int i = 0; i < 0; ++i) {
+ }
+ evictedCopy = "d";
+ }
+ }
+ }
+
+ // infinispan/persistence/soft-index/src/main/java/org/infinispan/persistence/sifs/IndexNode.java
+ private void foo99() {
+ int insertionPoint;
+ if (true) {
+ insertionPoint = 0;
+ } else if (true) {
+ insertionPoint = 1;
+ } else {
+ insertionPoint = 2;
+ if (insertionPoint < 0) {
+ insertionPoint = -insertionPoint - 1;
+ } else {
+ insertionPoint++;
+ }
+ }
+ }
+
+ // apache-struts/core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
+ private void foo100() {
+ String result;
+ if (true) {
+ result = "a";
+ } else {
+ result = "b";
+ if (result != null) {
+ }
+ result = "c";
+ }
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputFinalLocalVariableLeavingSlistToken.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputFinalLocalVariableLeavingSlistToken.java
new file mode 100644
index 000000000..43bb9dea7
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputFinalLocalVariableLeavingSlistToken.java
@@ -0,0 +1,59 @@
+package com.puppycrawl.tools.checkstyle.checks.coding;
+
+import java.util.stream.Stream;
+
+public class InputFinalLocalVariableLeavingSlistToken {
+
+ private int assignedInInstanceInitAndCtor;
+ private static int assignedInStaticInitAndFoo1;
+
+ {
+ assignedInInstanceInitAndCtor = 1;
+ }
+
+ static {
+ assignedInStaticInitAndFoo1 = 1;
+ }
+
+ InputFinalLocalVariableLeavingSlistToken() {
+ assignedInInstanceInitAndCtor = 2;
+ }
+
+ void foo1() {
+ assignedInStaticInitAndFoo1 = 2;
+ }
+
+ void foo2() {
+ int a;
+ if (true) {
+ }
+ else {
+ a = 1;
+
+ try {
+ } catch (Exception e) {
+ } finally {
+ }
+
+ if (true) {
+ }
+
+ Stream.of(1).forEach(integer -> {});
+
+ synchronized (InputFinalLocalVariableLeavingSlistToken.class) {
+ }
+
+ for (int i = 0; i < 0; ++i) {
+ }
+ while (Math.random() > 0) {
+ }
+ do {
+ }
+ while (Math.random() > 0);
+
+ {}
+
+ a = 2;
+ }
+ }
+}