Skip to content

MINOR: Replace Collections factory methods with Java 11+ equivalents in clients#22060

Open
see-quick wants to merge 1 commit intoapache:trunkfrom
see-quick:MINOR-refactor-from-jdk8-to-jdk11-part4
Open

MINOR: Replace Collections factory methods with Java 11+ equivalents in clients#22060
see-quick wants to merge 1 commit intoapache:trunkfrom
see-quick:MINOR-refactor-from-jdk8-to-jdk11-part4

Conversation

@see-quick
Copy link
Copy Markdown
Contributor

This is the 4th part of improving replace collections factory methods with its Java 11 equivalents in the clients module.

…in clients

Signed-off-by: see-quick <maros.orsak159@gmail.com>
@github-actions github-actions bot added clients small Small PRs triage PRs from the community labels Apr 14, 2026
Copy link
Copy Markdown
Contributor

@nileshkumar3 nileshkumar3 left a comment

Choose a reason for hiding this comment

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

LGTM!

@github-actions github-actions bot removed the triage PRs from the community label Apr 15, 2026
Copy link
Copy Markdown
Contributor

@clolov clolov left a comment

Choose a reason for hiding this comment

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

There are a few files where I believe you can fully clean up the usage of Collections, but let me know if I am missing something obvious! Thank you for persevering with this 😊

public MetricKey(String name, Map<String, String> tags) {
this.name = Objects.requireNonNull(name);
this.tags = tags != null ? Collections.unmodifiableMap(tags) : Collections.emptyMap();
this.tags = tags != null ? Collections.unmodifiableMap(tags) : Map.of();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Collections.unmodifiableMap => Map.copyOf?

exporting the metrics to the telemetry backend.
*/
private static final Set<String> EXCLUDE_LABELS = Collections.singleton("client_id");
private static final Set<String> EXCLUDE_LABELS = Set.of("client_id");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is one more entry in this file of Collections.unmodifiableList which you can try to change to List.copyOf? If this works you can also remove the import of Collections 😊

private List<String> requiredScope() {
String requiredSpaceDelimitedScope = option(REQUIRED_SCOPE_OPTION);
return Utils.isBlank(requiredSpaceDelimitedScope) ? Collections.emptyList() : OAuthBearerScopeUtils.parseScope(requiredSpaceDelimitedScope.trim());
return Utils.isBlank(requiredSpaceDelimitedScope) ? List.of() : OAuthBearerScopeUtils.parseScope(requiredSpaceDelimitedScope.trim());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similarly, there is a usage of Collections.unmodifiableMap which you can try to modify (put intended) and then remove the whole of Collections.

String scopeClaimValue = claim(scopeClaimName, String.class);
if (Utils.isBlank(scopeClaimValue))
return Collections.emptySet();
return Set.of();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar comment to other comments 😊

@Override
public Set<String> reconfigurableConfigs() {
return securityProtocol == SecurityProtocol.SASL_SSL ? SslConfigs.RECONFIGURABLE_CONFIGS : Collections.emptySet();
return securityProtocol == SecurityProtocol.SASL_SSL ? SslConfigs.RECONFIGURABLE_CONFIGS : Set.of();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar to other comments!

@clolov
Copy link
Copy Markdown
Contributor

clolov commented Apr 15, 2026

Could you also rebase and resolve the conflict so that tests can run?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants