Skip to content

Conversation

@Simulant87
Copy link
Contributor

@sonarqubecloud
Copy link

}

private static String getKeyNameFromMethod(Method method) {
if (!isValidMethod(method)) {
Copy link
Owner

@stleary stleary Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method validation now requires two function calls: getKeyNameFromMethod() and isValidMethod(). Also, the validation check is performed twice, in isValidMethod(), and in populateMap() with the key check. The call to isValidMethod() could be moved back up to the original location in populateMap(). This will help restore a bit of performance without losing all of the cognitive load improvements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sure, how you want to build it.
moving the extracted method isValidMethod() back into the for loop of populateMap() would either indent everything back into an if-statement, which I removed. And reintroducing it would increase the cognitive load again. Or it would introduce an early exit continue; into the for loop, which would be bad for performance as it introduces an unpredictable jump. I tried to avoid both.

@stleary
Copy link
Owner

stleary commented Jun 26, 2025

@Simulant87 Thanks for working on this issue. One minor comment, otherwise looks good.

@stleary
Copy link
Owner

stleary commented Jun 28, 2025

What problem does this code solve?
Refactor JSONObject populateMap(), per #984.

Note: There is an outstanding comment. If the submitter can't make the update, the code will be merged anyway, and I will add a follow-up PR to fix it.

Does the code still compile with Java6?
Yes

Risks
Low

Changes to the API?
No

Will this require a new release?
No

Should the documentation be updated?
No

Does it break the unit tests?
No

Was any code refactored in this commit?
Yes, that was why the issue was created.

Review status
APPROVED

Starting 3-day comment window

@stleary stleary changed the title #984 extract methods reducing cognitive complexity for JSONObject#populateMap Refactor JSONObject populateMap() per SonarQube Jun 28, 2025
@Simulant87
Copy link
Contributor Author

I think I could have a look at it maybe tomorrow. But you could as well merge it already and I could create another PR.

@stleary stleary merged commit 197afdd into stleary:master Jul 1, 2025
8 checks passed
@stleary stleary changed the title Refactor JSONObject populateMap() per SonarQube Refactoring: fix SonarQube issues in populateMap() Dec 24, 2025
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