Repository navigation
Simplify some boolean returns - #1179
Open
Ashutosh-Panda2004 wants to merge 1 commit into
Open
Ashutosh-Panda2004 wants to merge 1 commit into
Ashutosh-Panda2004 wants to merge 1 commit into
Conversation
Ashutosh-Panda2004
force-pushed
the
simplify-boolean-returns
branch
from
October 12, 2026 18:02
3cb98c7 to
ef455b6
Compare
|
Member
|
@Ashutosh-Panda2004 thanks for your contribution, can you please add your name at the end of the list of contributors in pom.xml and also add your name as author to each file you have touched. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Hi, this simplifies the boolean returns in seven methods across six files, things like an if that returns true followed by a return false at the end of a method. Each one now returns the condition directly, or its negation where the old code returned false for the condition. The behaviour is unchanged, the conditions have no side effects and short circuiting is kept where the old code relied on it.
The spots are LoadJob.isOutdated in WebClient, the next sibling case of selects in CssStyleSheet, equals in Color, isPreflightHeader and isAuthorizedHeader in XMLHttpRequest, supportedByXML10 in StringUtils and contains in Line2D. In supportedByXML10 both branches of the last if returned true, so the tail of the method is now a single return of the remaining range check.
I found these with the SimplifyBooleanReturn check from checkstyle. The check was recently extended in checkstyle issue 11608 to also catch this method tail shape, and the current checkstyle build flags these seven places here. HtmlUnit enables SimplifyBooleanReturn in its own checkstyle.xml, so I thought it would be good to clean them up before the next checkstyle update starts reporting them. Running the project checkstyle config over the whole tree passes cleanly with this change.
Happy to split this up or adjust the wording of any of the returns if you prefer a different style.