Skip to content

Prevent external mutation of reference list - #1710

Merged
jordanpadams merged 3 commits into
NASA-PDS:mainfrom
ravimnm:fix/1618-unmodifiable-references
Oct 23, 2026
Merged

jordanpadams merged 3 commits into
NASA-PDS:mainfrom
ravimnm:fix/1618-unmodifiable-references

Conversation

@ravimnm

@ravimnm ravimnm commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Return an unmodifiable view from HashSetReferenceInfo.getReferences() to prevent callers from modifying the internal reference list.
  • Add a regression test verifying that the returned list cannot be modified and reflects references added through addReference().

Testing

  • mvn -Dtest=HashSetReferenceInfoTest test — passed (1 test).
  • mvn test — the full suite did not complete successfully; the Cucumber test process terminated after Windows-path URI errors and registry-related test output.

Related issue

Fixes #1618

@ravimnm
ravimnm requested a review from a team as a code owner October 20, 2026 15:17
@ravimnm
ravimnm requested review from jordanpadams and removed request for a team October 20, 2026 15:17

@jordanpadams jordanpadams left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR! The change itself looks good and the test covers it. One small update requested (see the inline comment on the test), plus one observation:

getReferences() doesn't appear to be called anywhere in src/ - ReferentialIntegrityUtil only uses doesReferenceExist() and addReference(). That means this hardening doesn't affect any current code path, and the method can probably be removed altogether rather than made unmodifiable. Happy to go either way, but if you agree it's unused, removing it (and this test) may be the cleaner resolution for #1618.

🤖 Generated with help from Claude Code

class HashSetReferenceInfoTest {

@Test
void getReferencesReturnsUnmodifiableView() throws Exception {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please replace throws Exception with the specific checked exception that can actually be thrown here. Only new URL(String) throws one, so throws java.net.MalformedURLException is enough. We avoid declaring generic Exception types.

🤖 Generated with help from Claude Code

@ravimnm

ravimnm commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I checked the repository for usages of HashSetReferenceInfo.getReferences() and confirmed that it isn't used by the current source code. I agree that removing the unused getter is cleaner, so I've removed it along with the regression test.

The updated code compiles successfully with mvn -DskipTests compile. The full test suite still encounters the existing Windows-path URI and Cucumber integration-test issues on my environment.

@sonarqubecloud

Copy link
Copy Markdown

@jordanpadams
jordanpadams merged commit ddf61bd into NASA-PDS:main Oct 23, 2026
2 checks passed
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.

Bug: HashSetReferenceInfo.getReferences() exposes live mutable ArrayList from shared static state

2 participants