View Javadoc
1   /*
2   FinalLocalVariable
3   validateEnhancedForLoopVariable = (default)false
4   tokens = (default)VARIABLE_DEF
5   
6   
7   */
8   
9   package com.puppycrawl.tools.checkstyle.checks.coding.finallocalvariable;
10  
11  public class InputFinalLocalVariableMultipleAndNestedConditions {
12  
13      // False positive
14      // https://github.com/checkstyle/checkstyle/issues/3186
15      void method() {
16          for (int i = 0; i < 2; i++) {
17              final Object converter = new Object();
18              final String type = getType();
19              Object value;
20  
21              if ("s1".equals(type)) {
22                  if (getCondition(1)) {
23                      value = getValue(1);
24                  }
25                  else {
26                      continue;
27                  }
28              }
29              else if ("s2".equals(type)) {
30                  if (getCondition(2)) {
31                      value = getValue(2);
32                  }
33                  else {
34                      continue;
35                  }
36              }
37              else {
38                  continue;
39              }
40  
41              if (converter != null) {
42                  value = /* converter. */getValue(1, type, value);
43              }
44          }
45      }
46  
47      // False positive
48      // https://github.com/checkstyle/checkstyle/issues/3186
49      void method2() {
50          for (int i = 0; i < 2; i++) {
51              final Object converter = new Object();
52              final Object element = new Object();
53              String name;
54  
55              if (getCondition(1)) {
56                  name = "1";
57              } else if (getCondition(2)) {
58                  name = "2";
59              } else {
60                  continue;
61              }
62  
63              if (converter != null) {
64                  name = /* converter. */getName(element, name);
65  
66                  if (name == null)
67                      continue;
68              }
69          }
70      }
71  
72      public Object getValue(int i) {
73          return null;
74      }
75      public Object getValue(int i, String type, Object value) {
76          return value;
77      }
78      public boolean getCondition(int i) {
79          return true;
80      }
81      public String getType() {
82          return "s1";
83      }
84      private String getName(Object element, String name) {
85          return "s";
86      }
87  }