View Javadoc
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      }
81      private int i;
82  }
83  
84  @SuppressWarnings(value = "this previously caused NullPointerException")
85  class VariableDeclaredBeforeTheFirstBlockBegins {
86      void foo(String[] requests) {
87          for (String eventDataType : requests) {
88              @SuppressWarnings(value = "this previously caused NullPointerException")
89              String eventData;
90          }
91      }
92  }
93  abstract class NestedClass {
94      public abstract void method();
95  }