Skip to content
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

Fix shallow copy in getEntries and introduce new method #104

Merged
merged 2 commits into from
Feb 11, 2024

Conversation

mitsuki31
Copy link
Owner

Overview

This pull request addresses two key improvements to the matrix data access functionalities:

  1. Fix shallow copy in getEntries:
    The getEntries method originally returned a reference to the internal matrix data, potentially leading to unintended modifications. This change ensures a deep copy is returned, preserving data integrity.

  2. Introduce getReadOnlyEntries method:
    This new method provides a read-only view of the matrix entries, preventing accidental modifications and enhancing data security.

Changes Made

getEntries Method

  • Modified the method to return a deep copy of the internal entries array. The deep copy in getEntries utilizes MatrixUtils.deepCopyOf for efficient and reliable copying.
  • Updated the documentation to reflect the change and clarify its purpose.

getReadOnlyEntries Method

  • Added a new getReadOnlyEntries method that returns an unmodifiable view of the matrix elements. This method leverages Arrays.stream and Collections.unmodifiableList API to create the read-only structure.
  • Provided comprehensive documentation explaining the method's functionality, implementation details, and limitations.

Note

Both methods have been thoroughly tested to ensure their correctness and stability.

Summary

This pull request improves data integrity and security by addressing the shallow copy issue (#103) and providing a read-only access method. It also enhances the API with clear documentation for both methods.

Instead returning the object reference of the entries, now the method
returns a new array (a deep copy of the entries) ensuring that any
modifications to the returned array will never affect the original
matrix data. In addition, the method documentation has been updated.
The method called `getReadOnlyEntries`, as the name implies, this
method returns read-only (unmodifiable view) of the matrix entries
offering a secure way to access the matrix elements without the risk
of unintended modifications. Additionally, the documentation of this
method has been added for API details and the implementation note.
@mitsuki31 mitsuki31 self-assigned this Feb 11, 2024
@github-actions github-actions bot added bugfix Fixes some bug or issue lang:java Some changes on Java code labels Feb 11, 2024
@mitsuki31 mitsuki31 linked an issue Feb 11, 2024 that may be closed by this pull request
@mitsuki31 mitsuki31 marked this pull request as ready for review February 11, 2024 15:37
@mitsuki31 mitsuki31 added feature Add new features to improve the project minor Minor update labels Feb 11, 2024
@mitsuki31 mitsuki31 merged commit 96991a7 into master Feb 11, 2024
34 checks passed
@mitsuki31 mitsuki31 deleted the fix/shallow-copy-on-returned-entries branch February 11, 2024 15:54
@mitsuki31 mitsuki31 added this to the v1.5.0 milestone May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes some bug or issue feature Add new features to improve the project lang:java Some changes on Java code minor Minor update
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BUG]: Shallow copy issue in getEntries() method
1 participant