Skip to content

Fix JavaDoc snippet validator and the snippets it surfaced#4944

Merged
shai-almog merged 1 commit into
masterfrom
fix-javadoc-snippet-validation
May 14, 2026
Merged

Fix JavaDoc snippet validator and the snippets it surfaced#4944
shai-almog merged 1 commit into
masterfrom
fix-javadoc-snippet-validation

Conversation

@shai-almog
Copy link
Copy Markdown
Collaborator

@shai-almog shai-almog commented May 14, 2026

Summary

  • The headless JavaDoc snippet validator (scripts/validate-extracted-javadoc-snippets.sh) had silently stopped catching real issues - every snippet was failing in the same uniform way, so the SpanLabel setIcon(icon) bug (and others like it) shipped uncaught. This PR fixes the harness and then fixes the snippets it now flags.
  • Validator end-to-end run: 411 snippets extracted, 407 validated, 4 excluded with documented reasons, 0 failures.

Harness fixes

  • scripts/java-snippet-to-playground-uri.sh - unpack the ZipSupport cn1lib so PlaygroundProjectExporter's net.sf.zipme.* imports resolve (regression from Standardize native-theme build hints; fix simulator menu bugs #4855), and prepend the locally-built codenameone-javase jar to the classpath so Display.init(null) can populate Display.impl.
  • PlaygroundRunner.bindGlobals - restore the resolveDisplayBinding / resolveUiManagerBinding defensive wrappers (introduced in 54604ab for exactly this CLI use case, inadvertently reverted in 8c429e9).
  • JavaSnippetToPlaygroundUriHarness - replace reflection into CN1's Base64 (which now transitively requires Display.impl via Simd) with java.util.Base64.getUrlEncoder().withoutPadding(); treat Error-wrapped failures from headless CN1 init as non-parse passes; treat Undefined argument / Undefined variable eval errors as failures (this is the class of bug SpanLabel had).

Snippet fixes - made runnable in the playground

All these stay tagged ```java so syntax highlighting is preserved.

  • SpanLabel, SpanButton, MultiButton, CheckBox, RadioButton, ButtonGroup, Label, ImageViewer - add the missing Form hi = new Form(...), Image icon = FontImage.createMaterial(...), and trailing hi.show() so they actually open in the playground.
  • Preferences and io/package-info - declare String myToken = ... so the storage example is self-contained.
  • MathUtil.compare(float) / compare(double) - turn the bare new Float(f1).compareTo(...) expression into a runnable Form that displays the result.
  • Component.getAllStyles / Graphics.fillArc - rewrite the broken new Painter(cmp) { switch (style) { ... } } block (Painter is an interface, style/cmp were undefined) as a runnable Painter demo that still shows antialiased fillArc/drawArc.
  • Validator - wrap the custom Constraint example with the surrounding Form + TextField phone + Validator val setup.

Snippet relabel

  • com/codename1/system/package-info.java - the snippet inside is Objective-C (@interface ... : NSObject, @end), so the fence is now objc instead of java. Not removing highlighting - correcting it.

Exclusions (with documented reasons)

The 4 GroupLayout.add(component, ...) / LayoutStyle.getPreferredGap(...) snippets are one-line method-signature illustrations embedded in the JavaDoc of those methods themselves. They keep their java fence (so syntax highlighting still works) but are listed in scripts/java-snippet-validation-exclusions.jsonl with explicit reasons - their job is to document the call shape, not run as demos.

Test plan

  • scripts/extract-javadoc-java-snippets.sh CodenameOne/src extracts 411 snippets
  • scripts/validate-extracted-javadoc-snippets.sh reports Validated 407 snippets successfully and Excluded 4 snippets via explicit exclusion list, exit 0
  • Spot-check the SpanLabel snippet through the harness: now flagged when icon is removed, passes when the fixed sample is fed in
  • CI workflow .github/workflows/java-snippet-validation.yml passes on this branch (will trigger because the harness scripts changed)

Generated with Claude Code

The headless snippet validator stopped catching real issues after a
chain of refactors: PlaygroundProjectExporter pulled in net.sf.zipme.*
breaking the harness build, the resolveDisplayBinding wrappers were
reverted out of PlaygroundRunner.bindGlobals so it tripped on
ExceptionInInitializerError, and CN1's Base64 grew a Simd dep that
forced Display.impl to be live before any encoding could happen.

Repairs:
- Add ZipSupport cn1lib to the harness classpath
- Restore resolveDisplay/UiManagerBinding in PlaygroundRunner
- Encode URIs via java.util.Base64 instead of reflecting into CN1's
- Best-effort Display.init from the locally-built JavaSE jar so
  "Undefined argument: icon" surfaces instead of an NPE
- Tighten the harness so undefined-identifier eval errors fail,
  while genuine headless-runtime failures still pass

Then fix the snippets the now-working validator flags:
- SpanLabel/SpanButton/MultiButton/CheckBox/RadioButton/ButtonGroup/
  Label/ImageViewer: add the missing Form/Image setup and hi.show()
- Preferences (and io/package-info copy): declare String myToken
- MathUtil.compare(float|double): turn the bare compareTo line into
  a runnable Form demo
- Component.getAllStyles / Graphics.fillArc: rewrite the broken
  "new Painter(cmp) { switch (style) ... }" pseudo-code (Painter is
  an interface; style/cmp were undefined) as a runnable Painter demo
- Validator: wrap the Constraint sample in a runnable Form
- system/package-info: relabel the Objective-C example block from
  java to objc
- Add the four genuinely-illustrative GroupLayout/LayoutStyle method-
  signature snippets to the exclusions list with documented reasons

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

✅ Continuous Quality Report

Test & Coverage

Static Analysis

  • SpotBugs [Report archive]
    • ByteCodeTranslator: 0 findings (no issues)
    • android: 0 findings (no issues)
    • codenameone-maven-plugin: 0 findings (no issues)
    • core-unittests: 0 findings (no issues)
    • ios: 0 findings (no issues)
  • PMD: 0 findings (no issues) [Report archive]
  • Checkstyle: 0 findings (no issues) [Report archive]

Generated automatically by the PR CI workflow.

@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 14, 2026

Compared 106 screenshots: 106 matched.

Native Android coverage

  • 📊 Line coverage: 11.40% (6306/55313 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 9.07% (31248/344567), branch 3.97% (1302/32768), complexity 5.03% (1580/31420), method 8.75% (1286/14701), class 14.76% (294/1992)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

✅ Native Android screenshot tests passed.

Native Android coverage

  • 📊 Line coverage: 11.40% (6306/55313 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 9.07% (31248/344567), branch 3.97% (1302/32768), complexity 5.03% (1580/31420), method 8.75% (1286/14701), class 14.76% (294/1992)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

Benchmark Results

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 966.000 ms
Base64 CN1 encode 270.000 ms
Base64 encode ratio (CN1/native) 0.280x (72.0% faster)
Base64 native decode 984.000 ms
Base64 CN1 decode 233.000 ms
Base64 decode ratio (CN1/native) 0.237x (76.3% faster)
Image encode benchmark status skipped (SIMD unsupported)

@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 14, 2026

Compared 106 screenshots: 106 matched.
✅ Native iOS screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 223 seconds

Build and Run Timing

Metric Duration
Simulator Boot 90000 ms
Simulator Boot (Run) 0 ms
App Install 11000 ms
App Launch 10000 ms
Test Execution 298000 ms

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 1338.000 ms
Base64 CN1 encode 1401.000 ms
Base64 encode ratio (CN1/native) 1.047x (4.7% slower)
Base64 native decode 933.000 ms
Base64 CN1 decode 1040.000 ms
Base64 decode ratio (CN1/native) 1.115x (11.5% slower)
Base64 SIMD encode 464.000 ms
Base64 encode ratio (SIMD/native) 0.347x (65.3% faster)
Base64 encode ratio (SIMD/CN1) 0.331x (66.9% faster)
Base64 SIMD decode 529.000 ms
Base64 decode ratio (SIMD/native) 0.567x (43.3% faster)
Base64 decode ratio (SIMD/CN1) 0.509x (49.1% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 58.000 ms
Image createMask (SIMD on) 10.000 ms
Image createMask ratio (SIMD on/off) 0.172x (82.8% faster)
Image applyMask (SIMD off) 146.000 ms
Image applyMask (SIMD on) 85.000 ms
Image applyMask ratio (SIMD on/off) 0.582x (41.8% faster)
Image modifyAlpha (SIMD off) 220.000 ms
Image modifyAlpha (SIMD on) 75.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.341x (65.9% faster)
Image modifyAlpha removeColor (SIMD off) 185.000 ms
Image modifyAlpha removeColor (SIMD on) 85.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.459x (54.1% faster)
Image PNG encode (SIMD off) 1103.000 ms
Image PNG encode (SIMD on) 1196.000 ms
Image PNG encode ratio (SIMD on/off) 1.084x (8.4% slower)
Image JPEG encode 653.000 ms

@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 14, 2026

Compared 106 screenshots: 106 matched.
✅ Native iOS Metal screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 335 seconds

Build and Run Timing

Metric Duration
Simulator Boot 93000 ms
Simulator Boot (Run) 2000 ms
App Install 21000 ms
App Launch 11000 ms
Test Execution 284000 ms

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 1750.000 ms
Base64 CN1 encode 2148.000 ms
Base64 encode ratio (CN1/native) 1.227x (22.7% slower)
Base64 native decode 1020.000 ms
Base64 CN1 decode 1620.000 ms
Base64 decode ratio (CN1/native) 1.588x (58.8% slower)
Base64 SIMD encode 791.000 ms
Base64 encode ratio (SIMD/native) 0.452x (54.8% faster)
Base64 encode ratio (SIMD/CN1) 0.368x (63.2% faster)
Base64 SIMD decode 603.000 ms
Base64 decode ratio (SIMD/native) 0.591x (40.9% faster)
Base64 decode ratio (SIMD/CN1) 0.372x (62.8% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 138.000 ms
Image createMask (SIMD on) 37.000 ms
Image createMask ratio (SIMD on/off) 0.268x (73.2% faster)
Image applyMask (SIMD off) 228.000 ms
Image applyMask (SIMD on) 140.000 ms
Image applyMask ratio (SIMD on/off) 0.614x (38.6% faster)
Image modifyAlpha (SIMD off) 167.000 ms
Image modifyAlpha (SIMD on) 80.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.479x (52.1% faster)
Image modifyAlpha removeColor (SIMD off) 338.000 ms
Image modifyAlpha removeColor (SIMD on) 112.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.331x (66.9% faster)
Image PNG encode (SIMD off) 1544.000 ms
Image PNG encode (SIMD on) 1170.000 ms
Image PNG encode ratio (SIMD on/off) 0.758x (24.2% faster)
Image JPEG encode 2702.000 ms

@github-actions
Copy link
Copy Markdown
Contributor

Cloudflare Preview

@shai-almog shai-almog merged commit 5398cc5 into master May 14, 2026
21 of 22 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.

1 participant