You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
All checks that use AbstractCheck#getLine() should check code points instead of characters for spacing #10924
➜ checks git:(issue-10920) grep -R 'getLine('| grep -v "indentCheck\|\.getLine(\|int"
indentation/CommentsIndentationCheck.java: final String targetSourceLine = getLine(singleLineComment.getLineNo() - 1);
indentation/CommentsIndentationCheck.java: final String commentLine = getLine(blockComment.getLineNo() - 1);
blocks/RightCurlyCheck.java: elseif (shouldBeAloneOnLine(option, details, getLine(details.rcurly.getLineNo() - 1))) {
blocks/LeftCurlyCheck.java: final String braceLine = getLine(brace.getLineNo() - 1);
whitespace/WhitespaceAfterCheck.java: final String line = getLine(targetAST.getLineNo() - 1);
whitespace/WhitespaceAfterCheck.java: final String line = getLine(ast.getLineNo() - 1);
whitespace/GenericWhitespaceCheck.java: final String line = getLine(ast.getLineNo() - 1);
whitespace/GenericWhitespaceCheck.java: final String line = getLine(ast.getLineNo() - 1);
whitespace/NoWhitespaceBeforeCheck.java: final String line = getLine(ast.getLineNo() - 1);
whitespace/WhitespaceAroundCheck.java: final String line = getLine(ast.getLineNo() - 1);
whitespace/SingleSpaceSeparatorCheck.java: getLine(currentNode.getLineNo() - 1),
whitespace/NoWhitespaceAfterCheck.java: final String line = getLine(astLineNo - 1);
Noticed in #10837 and #10920, any check where we use AbstractCheck#getLine() (extracting a line of code from a source file) should be converted to using code points instead of characters. Now that Checkstyle supports Unicode in variable names and counts Unicode surrogate pairs correctly, we should make sure that all affected checks use code points instead of character arrays to ensure that we are indexing the correct character.
Another option to consider is to have AbstractCheck#getLine() return an int array of code points, but this would be a significant breaking change for users.
@nmancus1 Need help.
I created a method getCodePoint() in AbstractCheck, then I tried doing the required change but when I am running the tests related to that files, they are failing.
For eg: GenericWhiteSpaceCheck and GenericWhiteSpaceCheckTest 3 of 11 checks are failing.
Should I create a draft PR, to let you take a look at my changes?
@MUzairS15 a good strategy for this update might be:
Create AbstractCheck#getCodePoints
Make changes in already updated checks (WhitespaceAround, NoWhitespaceBefore) to use this method
Update checks that require simpler changes, such as *CurlyChecks and SingleSpaceSeparatorCheck
GenericWhitespaceCheck seems to be the most complicated update, so I would do this last.
This process may help to give you a better feel for the reason why we are doing this update, and provide some insight that will be helpful when you return to GenericWhitespaceCheck.
I am working on the following remaining #10924 slices:
ClassHeaderWrapOpenjdkCheck
JavadocLeadingAsteriskAlignCheck
I reproduced both on current master with supplementary Unicode:
ClassHeaderWrapOpenjdkCheck: false positive in the wrapped-header decision due to AST code-point columns being used with UTF-16 string slicing/length calculation.
JavadocLeadingAsteriskAlignCheck: false alignment violations due to a code-point column being used with UTF-16 charAt.
I’ll handle these as separate focused changes/PRs.
I am on JavadocUtilizingTrailingSpaceCheck: it adds the code point column of a Javadoc node to the UTF-16 length of its text, so a supplementary character counts twice. A line of exactly lineLimit code points with an emoji is reported as too long (found 81 for 80), and an under-utilized line is not reported when the next line with an emoji would fit. Reproduced on current master; I will measure the content in code points.
I am on NoWhitespaceBeforeCaseDefaultColonCheck: it adds the code point column of the last token before the colon to the UTF-16 length of its text, so case "😀": and case 𝒜: (enum constant) are reported as ':' preceded with whitespace although there is none. Reproduced on current master.
I am on NoWhitespaceAfterCheck: getPositionAfter adds the UTF-16 length of the token text to its code point column, so after an identifier with supplementary characters it looks at the wrong position. int 𝒜 []; is not reported, and int 𝒜𝒜[]; is reported although it has no whitespace. Reproduced on current master.
I am on PreferLiteralJavadocInlineTagCheck: it logs an HTML entity at the text node's code point column plus the UTF-16 index from String.indexOf, so the column is too far right when the text before the entity has supplementary characters (Emoji 😀 text < is reported one column late, 𝒜𝒜 < two columns late). Reproduced on current master.
I am on RegexpCheck: with ignoreComments = true it compares the match position from FileText.lineColumn (UTF-16 chars) with comment positions (code points), so on a line with supplementary characters a match right before a comment is taken as inside the comment and silently ignored. Reproduced on current master.
I am on CommonUtil.lengthExpandedTabs and ApiUtil.lengthExpandedTabs (used by AbstractCheck#log and several checks): they walk UTF-16 chars up to a code point index, so a tab after a supplementary character is not expanded. For example String b = "😀";<TAB>int B1; reports MemberName at column 28 instead of 29. Reproduced on current master.
I am on WhitespaceBeforeEmptyBodyCheck: isSpaceBetweenTokens adds firstToken.getColumnNo() (code points) to tokenText.length() (UTF-16 units), so empty bodies after supplementary-character identifiers (such as class 𝒜 {} or interface 𝒞 {}) are falsely reported as missing whitespace before {. Reproduced on current master.
Activity
nrmancuso commentedon Nov 4, 2021
Another option to consider is to have
AbstractCheck#getLine()return an int array of code points, but this would be a significant breaking change for users.rnveach commentedon Nov 4, 2021
Why not add a
getCodePoints()method?nrmancuso commentedon Nov 4, 2021
In
AbstractCheck? Great idea.MUzairS15 commentedon Nov 16, 2021
Can I work on this?
nrmancuso commentedon Nov 16, 2021
@MUzairS15 sure, please be aware that we will need to generate check regression reports for all checks listed in the issue description.
MUzairS15 commentedon Nov 17, 2021
Thank you for your response.
MUzairS15 commentedon Nov 20, 2021
@nmancus1 Need help.
I created a method getCodePoint() in AbstractCheck, then I tried doing the required change but when I am running the tests related to that files, they are failing.
For eg: GenericWhiteSpaceCheck and GenericWhiteSpaceCheckTest 3 of 11 checks are failing.
Should I create a draft PR, to let you take a look at my changes?
nrmancuso commentedon Nov 22, 2021
@MUzairS15 circling back on this issue, I see that you edited your comment.
Yes, please do.
Issue checkstyle#10924: Checks that use getLine() should check code p…
MUzairS15 commentedon Nov 23, 2021
I have created a draft PR, pls check when you find time,
Yes, I edited because I thought I will manage but I was not able to.
nrmancuso commentedon Nov 23, 2021
@MUzairS15 a good strategy for this update might be:
AbstractCheck#getCodePointsWhitespaceAround,NoWhitespaceBefore) to use this methodCurlyChecks andSingleSpaceSeparatorCheckGenericWhitespaceCheckseems to be the most complicated update, so I would do this last.This process may help to give you a better feel for the reason why we are doing this update, and provide some insight that will be helpful when you return to
GenericWhitespaceCheck.Here is an article(and additional links) from StackOverflow that helped me to better understand code points: https://stackoverflow.com/questions/23979676/java-what-are-characters-code-points-and-surrogates-what-difference-is-there/23980020 ; perhaps this can also aid you in your work on this issue.
Issue checkstyle#10924: Checks that use getLine() should check code p…
Issue checkstyle#10924: Checks that use getLine() should check code p…
nrmancuso commentedon Dec 4, 2021
We have missed a bunch of instances where we use
getLines()[i], which has the same effect: #11001These checks will also need to be updated.
258 remaining items
romani commentedon Nov 1, 2026
yes, it will help to force others and New checks to use proper aproach.
Krish-876 commentedon Nov 2, 2026
Thanks, I'll send a PR for 1.
Issue checkstyle#10924: Use code point for whitespace check in RightC…
sarabbose commentedon Nov 10, 2026
I am working on the following remaining #10924 slices:
ClassHeaderWrapOpenjdkCheckJavadocLeadingAsteriskAlignCheckI reproduced both on current master with supplementary Unicode:
ClassHeaderWrapOpenjdkCheck: false positive in the wrapped-header decision due to AST code-point columns being used with UTF-16 string slicing/length calculation.JavadocLeadingAsteriskAlignCheck: false alignment violations due to a code-point column being used with UTF-16charAt.I’ll handle these as separate focused changes/PRs.
arshil42 commentedon Nov 11, 2026
I am on JavadocUtilizingTrailingSpaceCheck: it adds the code point column of a Javadoc node to the UTF-16 length of its text, so a supplementary character counts twice. A line of exactly
lineLimitcode points with an emoji is reported as too long (found 81for 80), and an under-utilized line is not reported when the next line with an emoji would fit. Reproduced on current master; I will measure the content in code points.arshil42 commentedon Nov 11, 2026
I am on NoWhitespaceBeforeCaseDefaultColonCheck: it adds the code point column of the last token before the colon to the UTF-16 length of its text, so
case "😀":andcase 𝒜:(enum constant) are reported as ':' preceded with whitespace although there is none. Reproduced on current master.arshil42 commentedon Nov 11, 2026
I am on NoWhitespaceAfterCheck:
getPositionAfteradds the UTF-16 length of the token text to its code point column, so after an identifier with supplementary characters it looks at the wrong position.int 𝒜 [];is not reported, andint 𝒜𝒜[];is reported although it has no whitespace. Reproduced on current master.arshil42 commentedon Nov 11, 2026
I am on PreferLiteralJavadocInlineTagCheck: it logs an HTML entity at the text node's code point column plus the UTF-16 index from
String.indexOf, so the column is too far right when the text before the entity has supplementary characters (Emoji 😀 text <is reported one column late,𝒜𝒜 <two columns late). Reproduced on current master.Issue checkstyle#10924: Update ClassHeaderWrapOpenjdkCheck to use cod…
arshil42 commentedon Nov 11, 2026
I am on RegexpCheck: with
ignoreComments = trueit compares the match position fromFileText.lineColumn(UTF-16 chars) with comment positions (code points), so on a line with supplementary characters a match right before a comment is taken as inside the comment and silently ignored. Reproduced on current master.arshil42 commentedon Nov 11, 2026
I am on
CommonUtil.lengthExpandedTabsandApiUtil.lengthExpandedTabs(used byAbstractCheck#logand several checks): they walk UTF-16 chars up to a code point index, so a tab after a supplementary character is not expanded. For exampleString b = "😀";<TAB>int B1;reports MemberName at column 28 instead of 29. Reproduced on current master.Hrushikesh-ramilla commentedon Nov 12, 2026
I am on WhitespaceBeforeEmptyBodyCheck: isSpaceBetweenTokens adds firstToken.getColumnNo() (code points) to tokenText.length() (UTF-16 units), so empty bodies after supplementary-character identifiers (such as
class 𝒜 {}orinterface 𝒞 {}) are falsely reported as missing whitespace before{. Reproduced on current master.Issue checkstyle#10924: Update ClassHeaderWrapOpenjdkCheck to use cod…
Issue checkstyle#10924: Update JavadocLeadingAsteriskAlignCheck to us…