Skip to content

Fix PA_PUBLIC_PRIMITIVE_ATTRIBUT of MuttablePair class with attribute encapsulation#1321

Closed
felipevendrami wants to merge 1 commit intoapache:masterfrom
felipevendrami:fix/mutablepair-encapsulation-left-right
Closed

Fix PA_PUBLIC_PRIMITIVE_ATTRIBUT of MuttablePair class with attribute encapsulation#1321
felipevendrami wants to merge 1 commit intoapache:masterfrom
felipevendrami:fix/mutablepair-encapsulation-left-right

Conversation

@felipevendrami
Copy link

Encapsulate fields left and right in MutablePair to improve data integrity

Description:
This pull request addresses the issue identified by SpotBugs (PA_PUBLIC_PRIMITIVE_ATTRIBUTE) regarding the "left" and "right" fields in the MutablePair class. These fields were publicly accessible, which exposed them to potential unintended modification, violating the principle of encapsulation.

Changes made:

  1. Encapsulation: The fields "left" and "right" in MutablePair were changed from public to private to improve data integrity.
  2. Getter methods: The getLeft() and getRight() methods were already present, so no additional getters were created.
  3. Test class update: Updated MutablePairTest to use the getLeft() and getRight() methods instead of accessing the fields directly.

SpotBugs Reference:
This change resolves the SpotBugs warning: PA_PUBLIC_PRIMITIVE_ATTRIBUTE
Reference: MutablePair.java:[line 138]

Why this change is important:
Encapsulating fields ensures better control over the internal state of the MutablePair object, preventing potential misuse and maintaining consistency within the class.

@garydgregory
Copy link
Member

garydgregory commented Nov 28, 2024

-1: This PR breaks binary compatibility.

From our README file:

Before you pushing a PR, run mvn (by itself), this runs the default goal, which contains all build checks.

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