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