Skip to content

Fix questionable cast to abstract collection in ListResult and SetResult #138

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ic0ns
Copy link
Contributor

@ic0ns ic0ns commented Jun 30, 2025

This PR fixes the SpotBugs BC_BAD_CAST_TO_ABSTRACT_COLLECTION warnings in ListResult and SetResult classes.

Summary

The issue was that both classes were casting the parent class's field to more specific types ( and ). This is problematic because there's no guarantee the collection is of the expected type.

Changes

  • Added a private final field to to store the list directly
  • Added a private final field to to store the set directly
  • Modified and methods to return the stored fields instead of casting
  • Added comprehensive unit tests for both classes to ensure the functionality works correctly

Testing

  • All new tests pass
  • Existing tests continue to pass
  • SpotBugs no longer reports the BC_BAD_CAST_TO_ABSTRACT_COLLECTION warnings for these classes

Fixes #67

TLS Attacker Developer and others added 2 commits June 30, 2025 14:26
Instead of casting the parent's collection field, store the specific collection types (List<T> and Set<T>) as separate fields in ListResult and SetResult respectively. This eliminates the SpotBugs BC_BAD_CAST_TO_ABSTRACT_COLLECTION warnings.

The changes:
- Added private final List<T> field to ListResult
- Added private final Set<T> field to SetResult
- Modified getList() and getSet() to return the stored fields instead of casting
- Added comprehensive unit tests for both classes

Fixes #67
@TrueSkrillor
Copy link
Contributor

TrueSkrillor commented Jul 2, 2025

This PR needs a little more work and is intertwined with the JSON serialization rework (merging like this will most likely cause double serialization of the list / set). I will keep this open until I got to check JSON annotation in Scanner-Core.

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