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#11807: fixes exception on records and fields in Requ…
…ireThis
- Loading branch information
Showing
3 changed files
with
61 additions
and
5 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
42 changes: 42 additions & 0 deletions
42
...wl/tools/checkstyle/checks/coding/requirethis/InputRequireThisRecordsWithCheckFields.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,42 @@ | ||
/* | ||
RequireThis | ||
checkFields = true | ||
checkMethods = (default)true | ||
validateOnlyOverlapping = (default)true | ||
*/ | ||
|
||
//non-compiled with javac: Compilable with Java14 | ||
package com.puppycrawl.tools.checkstyle.checks.coding.requirethis; | ||
|
||
public record InputRequireThisRecordsWithCheckFields(int a) { | ||
void method() { | ||
String a = "BUG"; | ||
a = a.substring(0, 1); // violation 'Reference to instance variable 'a' needs "this."' | ||
} | ||
|
||
void method2() { | ||
String a = "BUG".substring(0, 1); // ok | ||
} | ||
} | ||
class InputRequireThisRecordsWithCheckFieldsClass { | ||
int a; | ||
|
||
public InputRequireThisRecordsWithCheckFieldsClass(int a) { | ||
this.a = a; | ||
} | ||
|
||
void method() { | ||
String a = "BUG"; | ||
a = a.substring(0, 1); // violation 'Reference to instance variable 'a' needs "this."' | ||
} | ||
|
||
void method2() { | ||
String a = "BUG".substring(0, 1); // ok | ||
} | ||
|
||
public int a() { | ||
return a; | ||
} | ||
} |