aboutsummaryrefslogtreecommitdiff
path: root/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableBothForLoops.java
blob: d3f57c7beb00aaff7d529abf42f3f0c1afd6f1b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
////////////////////////////////////////////////////////////////////////////////
// Test case file for FOR_ITERATION and whitespace.
// Created: 2003
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks.coding.modifiedcontrolvariable;
import java.io.Serializable;
class InputModifiedControlVariableBothForLoops
{
    int k;
    void method1()
    {
        //Violations:
        for (int i = 0; i < 1; i++) {
            i++;
        }
        for (int i = 0; i < 1; i++) {
            i = i + 1;
        }
        for (int i = 0; i < 1; i++) {
            for (int j = 0; j < 1; i++) {
                --i;
            }
        }
        for (int i = 0, j = 0; i < 1; i++) {
            j++;
        }

        // Ok:
        for (int i = 0; i < 1; i++) {
        }
        for (int i = 0; i < 1; i++) {
            int x = i;
        }
        for (int i = 0; i < 1; i++) {
            Serializable s = new Serializable() {
                int i = 3;
                void a() {
                    System.identityHashCode(i++);
                }
            };
        }
        for (int k = 0; k < 1; k++) {
            this.k++;   
        }

        String[] sa = {"a", "b"};
        for(String s:sa) {}
        for(String s:sa) {
            s = "new string";
        }
        for(int i=0;i < 10;) {
            i++;
        }
        for (int i = 0, l = 0,m=0; l < 10; i++,m=m+2) {
            l++;
            m++;
        }
        for (int i = 0; i < 10; ) {
            i = 11;
        }
        int w=0;
        for (int i=0;i<10; java.sql.Date.valueOf(""),this.i++,w++) {
            i++;
            w++;
        }
        for (int i=0,k=0; i<10 && k < 10; ++i,++k) {
            i = i + 3;
            k = k + 4;
        }
        for (int i = 0,j = 0 ; i <10; i++) {
            j++;
        }
    }
    private int i;
}

@SuppressWarnings(value = "this previously caused NullPointerException")
class VariableDeclaredBeforeTheFirstBlockBegins {
    void foo(String[] requests) {
        for (String eventDataType : requests) {
            @SuppressWarnings(value = "this previously caused NullPointerException")
            String eventData;
        }
    }
}