Skip to content

Simplify some boolean returns - #1179

Open
Ashutosh-Panda2004 wants to merge 1 commit into
HtmlUnit:masterfrom
Ashutosh-Panda2004:simplify-boolean-returns
Open

Ashutosh-Panda2004 wants to merge 1 commit into
HtmlUnit:masterfrom
Ashutosh-Panda2004:simplify-boolean-returns

Conversation

@Ashutosh-Panda2004

Copy link
Copy Markdown

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.

@sonarqubecloud

Copy link
Copy Markdown

@rbri

rbri commented Oct 13, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants