Skip to content

Fix PMD EmptyControlStatement and ForLoopCanBeForeach violations and enforce them in quality report#4454

Merged
shai-almog merged 7 commits intomasterfrom
codex/fix-pmd-emptycontrolstatement-and-forloopcanbeforeach
Jan 22, 2026
Merged

Fix PMD EmptyControlStatement and ForLoopCanBeForeach violations and enforce them in quality report#4454
shai-almog merged 7 commits intomasterfrom
codex/fix-pmd-emptycontrolstatement-and-forloopcanbeforeach

Conversation

@shai-almog
Copy link
Collaborator

Motivation

  • Remove numerous PMD EmptyControlStatement and ForLoopCanBeForeach violations across the codebase to improve code clarity and satisfy static analysis rules.
  • Convert safe index-based loops to enhanced for loops and make intentionally-empty loops explicit to avoid accidental no-ops.
  • Enforce these PMD rules as CI quality gates so future violations cause the PR quality check to fail.

Description

  • Replaced empty if/else/while/do..while bodies with explicit behavior such as return, continue, or a minimal harmless expression to make intent clear (examples: ConnectionRequest, JSONSanitizer, Deflate, DeflaterOutputStream, RSSService, GeofenceManager).
  • Converted many for (int i = 0; ...) index-based loops to enhanced for loops where the index was only used for iteration (examples: FileTreeModel, SimpleDateFormat, PropertyIndex, Dialog, Display, MenuBar, HTMLComponent, GroupLayout, Element, RE, TBigInteger and others).
  • Preserved loops that must remain indexed by adding explicit comments or // NOPMD ForLoopCanBeForeach where a foreach would be unsafe (example: Form.loopAnimations kept as an indexed loop with a NOPMD annotation).
  • Made several other small refactorings to avoid empty-statement patterns (e.g. replace // do nothing comments with continue in numeric library code).
  • Added EmptyControlStatement and ForLoopCanBeForeach to the forbidden PMD rules list in .github/scripts/generate-quality-report.py so future builds will fail the quality-report step on these violations.
  • The change set touches multiple files (47 files changed) to remediate the reported PMD findings.

Testing

  • No automated unit tests or Maven builds were executed as part of this change; only source edits and the quality-report script were modified.
  • The CI quality-report script was updated so the repository's PR checks will now fail if EmptyControlStatement or ForLoopCanBeForeach PMD findings are present (effects will be observed when the PR CI runs).
  • A commit containing the source edits was created; running the repository's usual mvn CI steps (see AGENTS.md) is recommended to validate compilation and unit tests under Java 8.

Codex Task

@shai-almog
Copy link
Collaborator Author

shai-almog commented Jan 21, 2026

Compared 30 screenshots: 30 matched.

Native Android coverage

  • 📊 Line coverage: 24.76% (2654/10717 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 24.41% (12335/50528), branch 15.35% (717/4672), complexity 17.52% (743/4241), method 32.97% (600/1820), class 34.65% (105/303)
    • Lowest covered classes
      • com.codename1.impl.android.com.codename1.impl.android.AndroidContactsManager – 0.00% (0/400 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.AndroidImplementation$Video – 0.00% (0/168 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.IntentIntegrator – 0.00% (0/139 lines covered)
      • com.codename1.impl.android.util.com.codename1.impl.android.util.Base64 – 0.00% (0/117 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.AndroidImplementation$SocketImpl – 0.00% (0/77 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.AndroidTextureView – 0.00% (0/76 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.AndroidSurfaceView – 0.00% (0/73 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.LocalNotificationPublisher – 0.00% (0/65 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.FridaDetectionUtil – 0.00% (0/64 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.PushNotificationService – 0.00% (0/59 lines covered)

✅ Native Android screenshot tests passed.

Native Android coverage

  • 📊 Line coverage: 24.76% (2654/10717 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 24.41% (12335/50528), branch 15.35% (717/4672), complexity 17.52% (743/4241), method 32.97% (600/1820), class 34.65% (105/303)
    • Lowest covered classes
      • com.codename1.impl.android.com.codename1.impl.android.AndroidContactsManager – 0.00% (0/400 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.AndroidImplementation$Video – 0.00% (0/168 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.IntentIntegrator – 0.00% (0/139 lines covered)
      • com.codename1.impl.android.util.com.codename1.impl.android.util.Base64 – 0.00% (0/117 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.AndroidImplementation$SocketImpl – 0.00% (0/77 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.AndroidTextureView – 0.00% (0/76 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.AndroidSurfaceView – 0.00% (0/73 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.LocalNotificationPublisher – 0.00% (0/65 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.FridaDetectionUtil – 0.00% (0/64 lines covered)
      • com.codename1.impl.android.com.codename1.impl.android.PushNotificationService – 0.00% (0/59 lines covered)

@github-actions
Copy link

github-actions bot commented Jan 21, 2026

✅ Continuous Quality Report

Test & Coverage

Static Analysis

Generated automatically by the PR CI workflow.

@shai-almog
Copy link
Collaborator Author

shai-almog commented Jan 21, 2026

iOS screenshot updates

Compared 30 screenshots: 23 matched, 6 updated, 1 missing reference.

  • BrowserComponent — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    BrowserComponent
    Preview info: Preview provided by instrumentation.
    Full-resolution PNG saved as BrowserComponent.png in workflow artifacts.

  • graphics-draw-arc — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    graphics-draw-arc
    Preview info: JPEG preview quality 20; JPEG preview quality 20; downscaled to 603x1311.
    Full-resolution PNG saved as graphics-draw-arc.png in workflow artifacts.

  • graphics-draw-gradient — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    graphics-draw-gradient
    Preview info: JPEG preview quality 10; JPEG preview quality 10; downscaled to 844x1835.
    Full-resolution PNG saved as graphics-draw-gradient.png in workflow artifacts.

  • graphics-draw-round-rect — missing reference. Reference screenshot missing at /Users/runner/work/CodenameOne/CodenameOne/scripts/ios/screenshots/graphics-draw-round-rect.png.

    graphics-draw-round-rect
    Preview info: JPEG preview quality 10; JPEG preview quality 10; downscaled to 844x1835.
    Full-resolution PNG saved as graphics-draw-round-rect.png in workflow artifacts.

  • graphics-draw-string — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    graphics-draw-string
    Preview info: JPEG preview quality 10; JPEG preview quality 10; downscaled to 422x918.
    Full-resolution PNG saved as graphics-draw-string.png in workflow artifacts.

  • graphics-draw-string-decorated — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    graphics-draw-string-decorated
    Preview info: JPEG preview quality 10; JPEG preview quality 10; downscaled to 603x1311.
    Full-resolution PNG saved as graphics-draw-string-decorated.png in workflow artifacts.

  • kotlin — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    kotlin
    Preview info: Preview provided by instrumentation.
    Full-resolution PNG saved as kotlin.png in workflow artifacts.

Benchmark Results

  • VM Translation Time: 357 seconds
  • Compilation Time: 179 seconds

Detailed Performance Metrics

Metric Duration
Build Time Statistics
Setup & Unzip 42520 ms
Extract Extensions 27 ms
Google Services Setup 8 ms
Scan Classes 2251 ms
Extract Libs 1303 ms
Inject Build Hints 45 ms
Generate Unit Tests 2 ms
Generate Stubs 1870 ms
Compile Stubs 2932 ms
Generate Icons 1468 ms
Prepare ParparVM 247 ms
ParparVM Execution 197607 ms
Post-VM Setup 157 ms
CocoaPods 4823 ms
Finalize 32 ms
Total Time 255293 msMaven Overhead : 102000 ms
CocoaPods Install (Script) 1000 ms
Simulator Boot (Run) 78000 ms
App Install 23000 ms
App Launch 8000 ms
Test Execution 179000 ms

@shai-almog shai-almog merged commit 610830c into master Jan 22, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant