Skip to content

Conversation

@3pacccccc
Copy link
Contributor

Fixes #24245

Motivation

enable FindPublicAttributes check of SpotBugs

Modifications

as the FindPublicAttributes check of SpotBugs requires, change the Primitive field from public into private to limit external accessibility.

Verifying this change

  • Make sure that the change passes the CI checks.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: 3pacccccc#6

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label May 11, 2025
@lhotari lhotari added this to the 4.1.0 milestone May 12, 2025
Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, @3pacccccc . I think that this is the correct way how to enable FindPublicAttributes check. For some reason, public fields have been used in Pulsar code base extensively, perhaps due to the coding style and possibly also due to a belief that setters would be causing addition overhead. Modern JVMs can eliminate the overhead, so it's not really useful to avoid using setters.

The main challenge in this change is to ensure that we don't break current public interfaces or internal interfaces that are are used when there's a mixed version Pulsar cluster running during a new version upgrade or downgrade. Public interfaces extend also to Pulsar plugins and they aren't very well defined.

Since there's at least one breaking change in the public API at the moment, it's worth starting a discussion on the dev mailing list about these changes and the FindPublicAttributes check of SpotBugs. It's usually necessary to write a PIP so that everyone becomes aware of this change and that we properly document the considerations and make a decision about it. It's also possible that we decide to keep on ignoring the FindPublicAttributes check in SpotBugs, but it's useful to make that decision as part of handling the PIP. That's why the PIP should be mainly about deciding whether to handle it or not and when would we possibly ignore it.

Comment on lines +34 to +46
@Getter
@Setter
private long storageSize;

/** Total number of messages. */
public long totalMessages;
@Getter
@Setter
private long totalMessages;

/** Total backlog. */
public long messageBacklog;
@Getter
@Setter
private long messageBacklog;
Copy link
Member

Choose a reason for hiding this comment

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

These are most likely a breaking change in the public API. In other stats classes there's a separate "Impl" class and a separate interface. I don't see a way how to preserve API compatibility and perhaps we should just break the API when making the change.

private long messageBacklog;

/** Broker host where this stat was generated. */
public final String brokerName;
Copy link
Member

@lhotari lhotari May 12, 2025

Choose a reason for hiding this comment

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

These final fields should be handled with getters for consistency.

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

Labels

doc-not-needed Your PR changes do not impact docs ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task] Enable SpotBug checks disabled in 4.9.x upgrade and fix possible detected bugs

2 participants