1   ////////////////////////////////////////////////////////////////////////////////
2   // Test case file for FOR_ITERATION and whitespace.
3   // Created: 2003
4   ////////////////////////////////////////////////////////////////////////////////
5   package com.puppycrawl.tools.checkstyle.checks.coding.modifiedcontrolvariable;
6   import java.io.Serializable;
7   class InputModifiedControlVariableBothForLoops
8   {
9       int k;
10      void method1()
11      {
12          //Violations:
13          for (int i = 0; i < 1; i++) {
14              i++;
15          }
16          for (int i = 0; i < 1; i++) {
17              i = i + 1;
18          }
19          for (int i = 0; i < 1; i++) {
20              for (int j = 0; j < 1; i++) {
21                  --i;
22              }
23          }
24          for (int i = 0, j = 0; i < 1; i++) {
25              j++;
26          }
27  
28          // Ok:
29          for (int i = 0; i < 1; i++) {
30          }
31          for (int i = 0; i < 1; i++) {
32              int x = i;
33          }
34          for (int i = 0; i < 1; i++) {
35              Serializable s = new Serializable() {
36                  int i = 3;
37                  void a() {
38                      System.identityHashCode(i++);
39                  }
40              };
41          }
42          for (int k = 0; k < 1; k++) {
43              this.k++;   
44          }
45  
46          String[] sa = {"a", "b"};
47          for(String s:sa) {}
48          for(String s:sa) {
49              s = "new string";
50          }
51          for(int i=0;i < 10;) {
52              i++;
53          }
54          for (int i = 0, l = 0,m=0; l < 10; i++,m=m+2) {
55              l++;
56              m++;
57          }
58          for (int i = 0; i < 10; ) {
59              i = 11;
60          }
61          int w=0;
62          for (int i=0;i<10; java.sql.Date.valueOf(""),this.i++,w++) {
63              i++;
64              w++;
65          }
66          for (int i=0,k=0; i<10 && k < 10; ++i,++k) {
67              i = i + 3;
68              k = k + 4;
69          }
70          for (int i = 0,j = 0 ; i <10; i++) {
71              j++;
72          }
73          
74          for (String v : sa) {
75              new NestedClass() {
76                  public void method() {}
77              };
78              v = "bad";
79          }
80          for (int i = 0; i < 10; i += 1) {
81              for (i = 7; i < 10; i += 1) {}
82          }
83          for (String name: new String[] {}) {
84          }
85  
86          for (i = 0; i < 10; i++) {
87              String name;
88              name = "";
89          }
90      }
91      private int i;
92  }
93  
94  @SuppressWarnings(value = "this previously caused NullPointerException")
95  class VariableDeclaredBeforeTheFirstBlockBegins {
96      void foo(String[] requests) {
97          for (String eventDataType : requests) {
98              @SuppressWarnings(value = "this previously caused NullPointerException")
99              String eventData;
100         }
101     }
102 }
103 abstract class NestedClass {
104     public abstract void method();
105 }