Skip to content

MINOR: Cleanup Connect Module (1/n) #19869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from

Conversation

sjhajharia
Copy link
Contributor

@sjhajharia sjhajharia commented May 31, 2025

Now that Kafka support Java 17, this PR makes some changes in connect
module. The changes in this PR are limited to only some files. A future
PR(s) shall follow.
The changes mostly include:

  • Collections.emptyList(), Collections.singletonList() and
    Arrays.asList() are replaced with List.of()
  • Collections.emptyMap() and Collections.singletonMap() are replaced
    with Map.of()
  • Collections.singleton() is replaced with Set.of()

Sub modules targeted: api, basic-auth-extensions, file, json, mirror,
mirror-client

Copy link
Collaborator

@m1a2st m1a2st left a comment

Choose a reason for hiding this comment

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

Thank @sjhajharia for this patch, left some comments

assertSchemaMatches(SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.INT32_SCHEMA), new HashMap<String, Integer>());
assertSchemaMatches(SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.INT32_SCHEMA), Collections.singletonMap("a", 0));
assertSchemaMatches(SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.INT32_SCHEMA), Map.of("a", 0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

L506 List.of()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was leading to NPEs. The elements in the List may be null. Hence it must be kept as Arrays.asList.

@sjhajharia
Copy link
Contributor Author

Hey @m1a2st , Thanks for the review.
Requesting a re-review.

Copy link
Collaborator

@m1a2st m1a2st left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@github-actions github-actions bot removed the triage PRs from the community label Jun 4, 2025
@sjhajharia
Copy link
Contributor Author

Thanks for the review @m1a2st
cc: @frankvicky

@chia7712
Copy link
Member

@sjhajharia could you please fix the conflicts?

@sjhajharia
Copy link
Contributor Author

Hey @chia7712
I fixed the conflicts. Pls review when available!

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@sjhajharia thanks for this cleanup. only one minor comment remains.

@@ -185,7 +184,7 @@ public SchemaBuilder doc(String doc) {

@Override
public Map<String, String> parameters() {
return parameters == null ? null : Collections.unmodifiableMap(parameters);
return parameters == null ? null : Map.copyOf(parameters);
Copy link
Member

Choose a reason for hiding this comment

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

According to comment in line#198, the order is kept as expected. Perhaps, we should keep using Collections.unmodifiableMap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @chia7712.
I have updated the PR.

@@ -419,7 +419,7 @@ public Schema valueSchema() {
*/
public Schema build() {
return new ConnectSchema(type, isOptional(), defaultValue, name, version, doc,
parameters == null ? null : Collections.unmodifiableMap(parameters),
parameters == null ? null : Map.copyOf(parameters),
Copy link
Member

Choose a reason for hiding this comment

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

This will change the order too, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes.
Missed that.
Fixing the same in the next commit

@sjhajharia
Copy link
Contributor Author

Hey @chia7712
Gentle ping for the above PR

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@sjhajharia thanks for this patch. one last comment is left. PTAL

@@ -1273,10 +1254,8 @@ public boolean canDetect(Object value) {
}
if (knownType == null) {
knownType = schema.type();
} else if (knownType != schema.type()) {
Copy link
Member

Choose a reason for hiding this comment

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

            if (knownType == null) knownType = schema.type();
            return knownType == schema.type();

How about using this style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I will push an update.
Thanks!

Copy link
Contributor

@frankvicky frankvicky left a comment

Choose a reason for hiding this comment

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

Overall LGTM

@sjhajharia sjhajharia requested a review from chia7712 July 3, 2025 12:15
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.

4 participants