Skip to content

Checkstyle class-design cleanup: add private utility ctors, mark final, drop redundant modifiers, add missing @Override#1038

Merged
akshayrai merged 2 commits into
linkedin:masterfrom
akshayrai:akrai/checkstyle-class-design-cleanup
Jun 29, 2026
Merged

Checkstyle class-design cleanup: add private utility ctors, mark final, drop redundant modifiers, add missing @Override#1038
akshayrai merged 2 commits into
linkedin:masterfrom
akshayrai:akrai/checkstyle-class-design-cleanup

Conversation

@akshayrai

@akshayrai akshayrai commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

No behavior changes in any file. All fixes are declaration-level no-ops that make existing intent explicit without changing runtime behavior.

  • HideUtilityClassConstructorCheck (26): Added explicit private constructors to utility classes to prevent accidental instantiation, matching their existing all-static design.
  • FinalClassCheck (6): Marked classes (and one nested class) as final where they were already effectively non-subclassable due to private constructors.
  • RedundantModifierCheck (16): Removed redundant public modifiers from constructors of private or package-private nested types, since their visibility is already constrained by the enclosing type.
  • MissingOverrideCheck (1): Added a missing @OverRide annotation to AbstractKafkaConnector#getActiveTasks(), aligning with its existing inherited Javadoc.

Testing Done

No logic change. PR checks only

…l, drop redundant modifiers, add missing @OverRide

Bundle of four mechanical class-design fixes the LinkedIn-internal
checkstyle (a stricter superset of the OSS Checker) flags on the
current OSS Brooklin tree. No behavior change in any file; every fix
is a declaration-level no-op that documents intent the language
already enforces, or that the class was implicitly relying on. None
of the targeted rules are currently enabled in OSS Brooklin's own
checkstyle.xml -- two of them (HideUtilityClassConstructorCheck,
MissingOverrideCheck) are present-but-commented-out -- so this PR
addresses the latent violations without proposing a config change.

49 fixes across 41 files, by rule:

HideUtilityClassConstructorCheck (26)
  Adds an explicit `private ClassName()` constructor to each
  utility class (all-static-API classes) so the synthesized
  public default constructor doesn't accidentally let consumers
  instantiate them. Each ctor is a one-liner; no other changes
  in these files. Touched modules: datastream-{client, common,
  kafka, kafka-connector, server, testcommon, tools, utils}.

FinalClassCheck (6)
  Marks five top-level classes (DatastreamRestClientCli,
  DynamicMetricsManager, MetricsTestUtils, EmbeddedDatastreamCluster,
  FutureUtils) and one nested class
  (KafkaMirrorMakerConnector.PartitionDiscoveryThread) `final`.
  Each already had only private constructors, so the `final`
  keyword just makes the existing not-meant-to-be-subclassed
  intent explicit -- the JVM was already enforcing it.

RedundantModifierCheck (16)
  Drops the `public` modifier from constructors of nested types
  whose enclosing class is `private` (or, for ResettableGauge,
  whose own class is package-private). The `public` modifier
  on a constructor of a private/package-private type is
  redundant because the constructor cannot be invoked from
  anywhere the type itself isn't visible. Touched ZkAdapter's
  five private inner zk-listener classes, three CommonConnectorMetrics
  nested metric-bucket classes, Coordinator.CoordinatorMetrics,
  StickyPartitionAssignmentStrategy.ElasticTaskAssignmentInfo,
  RetryUtils.ExceptionTrackingMethodCaller,
  FileProcessor (package-private),
  BaseRestClientFactory.DaemonNamedThreadFactory,
  ResettableGauge x2, DatabaseChunkedReaderMetrics.

MissingOverrideCheck (1)
  Adds @OverRide to AbstractKafkaConnector#getActiveTasks(), which
  already had `{@inheritdoc}` Javadoc but was missing the annotation
  the Javadoc implies.

Motivation outside OSS Brooklin: brooklin-server consumes Brooklin
in-tree (subtree-merge at brooklin-core/) and runs a stricter
checkstyle on the merged code; the four rules above fire 49 times
total today, forcing a build-level carve-out. With this PR merged
upstream, brooklin-server's next OSS sync inherits the cleanup and
the four rules drop out of its checkstyle-suppress list.
@akshayrai akshayrai marked this pull request as ready for review June 29, 2026 10:17
@@ -10,6 +10,9 @@
*/
public class DatastreamMetadataConstants {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we define this class also as final

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@@ -10,6 +10,9 @@
*/
public class KafkaDatastreamMetadataConstants {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same, should this be defined a final class.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@@ -23,6 +23,10 @@
* Utility class for Kafka based connectors
*/
public class KafkaConnectorDiagUtils {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think utils class should also be defined as final.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@dhananjay-sawner

Copy link
Copy Markdown
Collaborator

Thanks Akshay for sanitizing this.

One nit: since we are picking this up, should we also consider defining all the Utils and Constant classes as final?

…losure

Follow-up to reviewer feedback on the previous commit: adding a private
no-arg constructor to the 18 utility / constants classes flipped them
from "synthesized public default ctor" to "only private ctors", which
makes the existing FinalClassCheck rule fire on them (the rule requires
final when a class has only private constructors and no descendants).
The previous commit addressed FinalClass on 6 classes that were already
in that state pre-patch; this commit closes the loop by marking the 18
classes whose new private ctor put them in the same state.
No behavior change: every class was already non-extendable in practice
(only private constructors). The final keyword just makes the intent
explicit at the class declaration and satisfies the FinalClassCheck rule
the previous commit otherwise leaves with new violations.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@dhananjay-sawner dhananjay-sawner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@akshayrai akshayrai merged commit a5073c5 into linkedin:master Jun 29, 2026
1 check passed
akshayrai added a commit that referenced this pull request Jul 1, 2026
Two parallel PRs (#1038 'Checkstyle class-design cleanup' and #1040
'Centralize ObjectMapper construction via JsonUtils.newObjectMapper()')
each independently added a private no-arg constructor to JsonUtils,
merging into master with two definitions of the same constructor.
This broke compilation of datastream-common with:
error: constructor JsonUtils() is already defined in class JsonUtils
Removed the duplicate, keeping the field declarations before the
single remaining private constructor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants