Skip to content

Fix SonarCloud issues: simplify complex methods and clean up - #229

Merged
mfl28 merged 3 commits into
masterfrom
refactor/sonar-cleanup
Oct 11, 2026
Merged

mfl28 merged 3 commits into
masterfrom
refactor/sonar-cleanup

Conversation

@mfl28

@mfl28 mfl28 commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Fixes about 40 of the 61 open SonarCloud issues on master. No behavior changes.

Critical: all 7 methods that were too complex

  • PNGMaskLoadStrategy: reading a single mask file moved into a per-import LoadContext (strategies keep per-call state in a context object). A small ObjectRegion class collects each object's bounds and category counts.
  • PNGMaskSaveStrategy: converting a shape to a mask (toMask) and painting a mask (paint) are separate methods, which also removes the continues.
  • COCOLoadStrategy: readRoot checks the file and its arrays, readAnnotation reads one annotation, and the results moved into the existing LoadContext record.
  • COCORunLengthEncoding.decode: reading a single count moved into a CountReader.
  • BoundingMaskView and EditorImagePaneView: the event-handler bodies became named methods.

Major

  • MutableMask: fillCircle, fillPolygon and strokeLine return Optional<PixelRegion> (a new record) instead of an int[] or null. Two loops that changed their counter in the body are now while loops.
  • CSVLoadStrategy: the nested try blocks became readRow and importRow.
  • The three load exceptions are no longer nested in ImageAnnotationLoadStrategy; each has its own file.
  • The number input's regex uses possessive quantifiers. It accepts the same input but can't backtrack.
  • Fields of inner classes no longer hide outer ones (ResizeHandle.handleDragAnchor, VertexHandle.vertexEditing).
  • main passes its arguments to launch.
  • PVOC flag tags (truncated/occluded/difficult) are handled in their own method.

Minor: unnamed catch variables (11), a loop without continue in ImageAnnotationSaver, assertThrows instead of try/fail (4 tests), method references, an unused import, an unnecessary throws, and != instead of !(==).

Left out on purpose

  • Assertion counts in long UI tests (S5961): they belong to a separate test-splitting change.
  • The 5 issues in Controller: Move the autosave logic from Controller into AutosaveController #228 changes it heavily, so they follow after it's merged.
  • MainView "monster class": too big a change for a cleanup.
  • Hard-coded URIs (S1075): these are bundled resource paths.
  • transient in BoundingMaskData: it deliberately keeps Gson from serializing masks by reflection.

The full suite (291 tests) passes locally.

Critical: split the 7 methods that were too complex (PNG mask import and
export, COCO import, the RLE decoder, the mask view's and the image pane's
handlers) into smaller ones.

Major: MutableMask returns Optional<PixelRegion> instead of int[] or null,
loops no longer change their counters, CSV rows are read and imported in
separate methods, the load exceptions are no longer nested in an interface,
the number input's regex can't backtrack, inner-class fields no longer
hide outer ones, and main passes its arguments on.

Minor: unnamed catch variables, assertThrows instead of try/fail, method
references, an unused import and an unnecessary throws clause.

No behavior changes.
@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.31579% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.25%. Comparing base (509e580) to head (f1d0bac).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...fl28/boundingboxeditor/model/data/MutableMask.java 61.11% 4 Missing and 3 partials ⚠️
...b/mfl28/boundingboxeditor/ui/BoundingMaskView.java 76.66% 2 Missing and 5 partials ⚠️
...oundingboxeditor/model/io/PNGMaskLoadStrategy.java 93.18% 1 Missing and 5 partials ⚠️
...fl28/boundingboxeditor/ui/EditorImagePaneView.java 62.50% 4 Missing and 2 partials ⚠️
...undingboxeditor/model/io/ImageAnnotationSaver.java 63.63% 3 Missing and 1 partial ⚠️
...28/boundingboxeditor/model/io/CSVLoadStrategy.java 85.71% 0 Missing and 2 partials ⚠️
.../mfl28/boundingboxeditor/BoundingBoxEditorApp.java 0.00% 1 Missing ⚠️
...ingboxeditor/controller/ImageFolderController.java 0.00% 1 Missing ⚠️
...28/boundingboxeditor/model/data/ImageMetaData.java 0.00% 1 Missing ⚠️
...undingboxeditor/model/io/BoundingBoxPredictor.java 0.00% 1 Missing ⚠️
... and 3 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #229      +/-   ##
============================================
+ Coverage     90.05%   90.25%   +0.20%     
- Complexity     2374     2389      +15     
============================================
  Files           135      140       +5     
  Lines          8901     8963      +62     
  Branches        865      860       -5     
============================================
+ Hits           8016     8090      +74     
+ Misses          462      455       -7     
+ Partials        423      418       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

@mfl28
mfl28 merged commit fc23983 into master Oct 11, 2026
19 checks passed
@mfl28
mfl28 deleted the refactor/sonar-cleanup branch October 11, 2026 11:38
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.

1 participant