checkstyle / checkstyle/checkstyle
ModifiedControlVariable does not detect errors for reference type variables and control variable declared outside
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 4.2k
- Avg merge
- 22h 23m
- Merged PRs (30d)
- 232
Description
Check documentation: https://checkstyle.org/config_coding.html#ModifiedControlVariable
`E:\New folder\Java Dev\src\com\company>javac Demo.java`
`E:\New folder\Java Dev\src\com\company>type Demo.java
`
```
package com.company;
class Hello
{
public static void main(String args[])
{
for(int a[]={0};a[0]<4;a[0]++)
{
a[0]++; //Doesn't warn incorrect
}
}
}
```
`E:\New folder\Java Dev\src\com\company>type config.xml
`
```
```
```
E:\New folder\Java Dev\src\com\company>java -jar checkstyle-8.39-all.jar -c config.xml Demo.java
Starting audit...
Audit done.
```
Expected:Violation on 8 th line.
```
[ERROR] E:\New folder\Java Dev\src\com\company\Demo.java:9:14: Control variable 'a[0]' is modified. [ModifiedControlVariable]
Audit done.
Checkstyle ends with 1 errors.
```
```
package com.company;
public class Demo {
public static void main(String args[])
{
int i;
for(i=0;i<8;i++)
{
i++; // Doesn't warn incorrect
}
}
}
```
`E:\New folder\Java Dev\src\com\company>type config.xml
`
```
```
```
E:\New folder\Java Dev\src\com\company>java -jar checkstyle-8.39-all.jar -c config.xml Demo.java
Starting audit...
Audit done.
```
Expected:Violation on 8 th line.
```
[ERROR] E:\New folder\Java Dev\src\com\company\Demo.java:9:14: Control variable 'i' is modified. [ModifiedControlVariable]
Audit done.
Checkstyle ends with 1 errors.
```
Contributor guide
Research direction
Start by reproducing both examples from the issue with Demo.java, the shown config.xml, and the ModifiedControlVariable check. Compare the audit output with the expected violations for the reference-type variable and the control variable declared outside the loop; done means both cases report the modification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100