forked from checkstyle/checkstyle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#3335: prevented static variables being checked for R…
…equireThis
- Loading branch information
Showing
5 changed files
with
169 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputRequireThisStatic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.puppycrawl.tools.checkstyle.checks.coding; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
|
||
public final class InputRequireThisStatic { | ||
public static String staticField1 = ""; | ||
|
||
public static String staticField2 = new String(staticField1); | ||
|
||
public String instanceField1; | ||
public BufferedReader instanceField2; | ||
|
||
static { | ||
try (BufferedReader instanceField2 = new BufferedReader(new FileReader(""))) { | ||
instanceField2.readLine(); | ||
} | ||
catch (FileNotFoundException e) { | ||
} | ||
catch (IOException e) { | ||
} | ||
} | ||
|
||
public String get() { | ||
return staticField1; | ||
} | ||
|
||
void foo50(String staticField1) { | ||
staticField1 = staticField1; | ||
} | ||
|
||
void foo52(String staticField1) { | ||
staticField1 += staticField1; | ||
} | ||
|
||
static void test(String instanceField1) { | ||
if (instanceField1 == null) { | ||
instanceField1 = staticField1; | ||
} | ||
} | ||
|
||
static void test2() { | ||
try (BufferedReader instanceField2 = new BufferedReader(new FileReader(""))) { | ||
instanceField2.readLine(); | ||
} | ||
catch (IOException e) { | ||
} | ||
} | ||
} |
Oops, something went wrong.