-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #11973: Fix NPE on empty switch statements in VariableDeclarati…
…onUsageDistance
- Loading branch information
Showing
9 changed files
with
203 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1349,6 +1349,7 @@ todocomment | |
tokenizer | ||
tokennizer | ||
tokentype | ||
tokenutil | ||
tolist | ||
Toolbar | ||
TOSTRING | ||
|
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
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
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
92 changes: 92 additions & 0 deletions
92
...eclarationusagedistance/InputVariableDeclarationUsageDistanceCheckSwitchExpressions2.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,92 @@ | ||
/* | ||
VariableDeclarationUsageDistance | ||
allowedDistance = 1 | ||
ignoreVariablePattern = (default) | ||
validateBetweenScopes = true | ||
ignoreFinal = false | ||
*/ | ||
|
||
//non-compiled with javac: Compilable with Java14 | ||
package com.puppycrawl.tools.checkstyle.checks.coding.variabledeclarationusagedistance; | ||
|
||
public class InputVariableDeclarationUsageDistanceCheckSwitchExpressions2 { | ||
void issue11973() { | ||
int i = -1; // violation 'Distance between.*'i'.*and.*first usage is 2, but allowed 1.' | ||
int x = -1; // ok | ||
switch (i) { | ||
case 1 -> { | ||
x++; | ||
i++; | ||
} | ||
}; | ||
|
||
int a = -1; // ok | ||
int a123 = switch (a) { | ||
case 1 -> { | ||
yield 2; | ||
} | ||
default -> { | ||
yield a; | ||
} | ||
}; | ||
|
||
int b = -1; // ok | ||
int b123 = switch (b) { | ||
case 1 -> { | ||
yield b; | ||
} | ||
default -> { | ||
yield 1; | ||
} | ||
}; | ||
|
||
int day = 1; // ok | ||
int c = -1; | ||
int c123 = switch (c) { | ||
case 1: | ||
case 2: | ||
default: | ||
c++; | ||
c--; | ||
yield day++; | ||
}; | ||
|
||
int day1 = 1; // ok | ||
int cc = -1; | ||
int d123 = switch (cc) { | ||
case 1 -> { | ||
cc++; | ||
cc--; | ||
yield day1; | ||
} | ||
default -> { | ||
yield 0; | ||
} | ||
}; | ||
|
||
int day2 = 1; // ok | ||
int ccc = -1; | ||
int e123 = switch (ccc) { | ||
case 1 -> { | ||
ccc++; | ||
ccc--; | ||
yield ccc; | ||
} | ||
case 2 -> { | ||
yield 2; | ||
} | ||
default -> { | ||
ccc++; | ||
ccc--; | ||
ccc++; | ||
day2++; | ||
yield 3; | ||
} | ||
}; | ||
|
||
int u = 0; | ||
switch (u) { }; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...pycrawl/tools/checkstyle/utils/tokenutil/InputTokenUtilTestForEachChildMultipleTypes.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,10 @@ | ||
package com.puppycrawl.tools.checkstyle.utils.tokenutil; | ||
|
||
public class InputTokenUtilTestForEachChildMultipleTypes { | ||
void method1() { } | ||
private int a; | ||
enum Days { } | ||
void method2() { } | ||
class Inner1 { } | ||
private int b; | ||
} |