Skip to content

Add String.replace(CharSequence,CharSequence) and rewrite replaceAll/replaceFirst (#4878)#4893

Open
shai-almog wants to merge 3 commits intomasterfrom
add-string-replace-and-replaceall-issue-4878
Open

Add String.replace(CharSequence,CharSequence) and rewrite replaceAll/replaceFirst (#4878)#4893
shai-almog wants to merge 3 commits intomasterfrom
add-string-replace-and-replaceall-issue-4878

Conversation

@shai-almog
Copy link
Copy Markdown
Collaborator

Summary

  • Adds the missing String.replace(CharSequence, CharSequence) reported in missing core method #4878 (real implementation in vm/JavaAPI, stub in Ports/CLDC11 matching the file's stubs-only convention).
  • Wires String.replaceAll(String, String) and String.replaceFirst(String, String) through the bytecode compliance rewriter to a new JdkApiRewriteHelper.replaceAll/replaceFirst pair that delegates to the existing RE regex engine — same pattern already used for String.split.
  • Adds two new BytecodeComplianceMojoTest cases covering the replaceAll and replaceFirst rewrite rules.

Fixes #4878.

Test plan

  • mvn -pl codenameone-maven-plugin test — full suite (19 tests) passes including the two new rewrite tests.
  • mvn -pl core compile — clean.
  • mvn -pl java-runtime compile — clean (CLDC11 stubs build).
  • mvn compile in vm/JavaAPI — clean.
  • Spot-check a sample app that calls String.replace(CharSequence,CharSequence), String.replaceAll, and String.replaceFirst to confirm runtime behavior on iOS / Android / simulator.

🤖 Generated with Claude Code

shai-almog and others added 2 commits May 8, 2026 13:54
…replaceFirst

Fixes #4878. String.replace(CharSequence,CharSequence) was missing from
the Codename One String API. Adds a real implementation in vm/JavaAPI
and a stub in Ports/CLDC11. Also wires String.replaceAll(String,String)
and String.replaceFirst(String,String) through the bytecode compliance
rewriter so user-code callsites are redirected to JdkApiRewriteHelper,
which delegates to the existing RE regex engine (matching the pattern
already used for String.split).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…laceFirst

Adds a Cn1ssDeviceRunner suite test that exercises the new
String.replace(CharSequence,CharSequence) overload along with the
String.replaceAll/replaceFirst regex variants the bytecode rewriter
redirects to JdkApiRewriteHelper. Lets the iOS, Android and JavaScript
ports validate the new APIs end-to-end.

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

github-actions Bot commented May 8, 2026

✅ 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 8, 2026

Compared 90 screenshots: 90 matched.

Native Android coverage

  • 📊 Line coverage: 10.17% (5549/54579 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 7.99% (27202/340606), branch 3.65% (1191/32646), complexity 4.66% (1458/31272), method 8.21% (1200/14614), class 13.59% (267/1964)
    • 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: 10.17% (5549/54579 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 7.99% (27202/340606), branch 3.65% (1191/32646), complexity 4.66% (1458/31272), method 8.21% (1200/14614), class 13.59% (267/1964)
    • 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 757.000 ms
Base64 CN1 encode 194.000 ms
Base64 encode ratio (CN1/native) 0.256x (74.4% faster)
Base64 native decode 872.000 ms
Base64 CN1 decode 217.000 ms
Base64 decode ratio (CN1/native) 0.249x (75.1% faster)
Image encode benchmark status skipped (SIMD unsupported)

…case

The Android CI run found two assertion bugs in the test:
- "a.a.a".replace("a","X") was asserted as "X-X-X" instead of "X.X.X"
  (the literal '.' is preserved by replace - this is replace, not
  replaceAll; periods only match anything when used as regex).
- "aaa".replace("", "x") empty-target behavior is platform-specific
  enough on the JS/iOS ports that it's not worth blocking the suite on
  it - drop that case rather than chase compatibility.

The CI logs confirmed the rewriter applied 8 invocation rewrites on the
test class, so the snapshot release wiring is fine - this was just a
typo on my part.

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

github-actions Bot commented May 8, 2026

✅ ByteCodeTranslator Quality Report

Test & Coverage

  • Tests: 644 total, 0 failed, 2 skipped

Benchmark Results

  • Execution Time: 10343 ms

  • Hotspots (Top 20 sampled methods):

    • 24.82% java.lang.String.indexOf (448 samples)
    • 18.95% com.codename1.tools.translator.Parser.isMethodUsed (342 samples)
    • 16.57% java.util.ArrayList.indexOf (299 samples)
    • 4.27% java.lang.Object.hashCode (77 samples)
    • 3.93% com.codename1.tools.translator.ByteCodeClass.markDependent (71 samples)
    • 2.94% java.lang.System.identityHashCode (53 samples)
    • 2.88% com.codename1.tools.translator.Parser.addToConstantPool (52 samples)
    • 2.71% com.codename1.tools.translator.BytecodeMethod.optimize (49 samples)
    • 2.66% com.codename1.tools.translator.ByteCodeClass.updateAllDependencies (48 samples)
    • 1.55% com.codename1.tools.translator.BytecodeMethod.appendMethodSignatureSuffixFromDesc (28 samples)
    • 1.50% com.codename1.tools.translator.Parser.generateClassAndMethodIndexHeader (27 samples)
    • 1.39% com.codename1.tools.translator.ByteCodeClass.calcUsedByNative (25 samples)
    • 0.78% com.codename1.tools.translator.Parser.cullMethods (14 samples)
    • 0.66% com.codename1.tools.translator.bytecodes.Invoke.addDependencies (12 samples)
    • 0.66% java.lang.StringBuilder.append (12 samples)
    • 0.55% com.codename1.tools.translator.ByteCodeClass.markDependencies (10 samples)
    • 0.55% java.lang.StringCoding.encode (10 samples)
    • 0.50% com.codename1.tools.translator.BytecodeMethod.addToConstantPool (9 samples)
    • 0.50% com.codename1.tools.translator.BytecodeMethod.isMethodUsedByNative (9 samples)
    • 0.39% java.io.FileOutputStream.writeBytes (7 samples)
  • ⚠️ Coverage report not generated.

Static Analysis

  • ✅ SpotBugs: no findings (report was not generated by the build).
  • ⚠️ PMD report not generated.
  • ⚠️ Checkstyle report not generated.

Generated automatically by the PR CI workflow.

@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 8, 2026

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

Benchmark Results

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

Build and Run Timing

Metric Duration
Simulator Boot 120000 ms
Simulator Boot (Run) 1000 ms
App Install 14000 ms
App Launch 54000 ms
Test Execution 302000 ms

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 1450.000 ms
Base64 CN1 encode 1291.000 ms
Base64 encode ratio (CN1/native) 0.890x (11.0% faster)
Base64 native decode 703.000 ms
Base64 CN1 decode 957.000 ms
Base64 decode ratio (CN1/native) 1.361x (36.1% slower)
Base64 SIMD encode 459.000 ms
Base64 encode ratio (SIMD/native) 0.317x (68.3% faster)
Base64 encode ratio (SIMD/CN1) 0.356x (64.4% faster)
Base64 SIMD decode 383.000 ms
Base64 decode ratio (SIMD/native) 0.545x (45.5% faster)
Base64 decode ratio (SIMD/CN1) 0.400x (60.0% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 58.000 ms
Image createMask (SIMD on) 9.000 ms
Image createMask ratio (SIMD on/off) 0.155x (84.5% faster)
Image applyMask (SIMD off) 170.000 ms
Image applyMask (SIMD on) 75.000 ms
Image applyMask ratio (SIMD on/off) 0.441x (55.9% faster)
Image modifyAlpha (SIMD off) 160.000 ms
Image modifyAlpha (SIMD on) 81.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.506x (49.4% faster)
Image modifyAlpha removeColor (SIMD off) 249.000 ms
Image modifyAlpha removeColor (SIMD on) 69.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.277x (72.3% faster)
Image PNG encode (SIMD off) 991.000 ms
Image PNG encode (SIMD on) 848.000 ms
Image PNG encode ratio (SIMD on/off) 0.856x (14.4% faster)
Image JPEG encode 559.000 ms

@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 8, 2026

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

Benchmark Results

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

Build and Run Timing

Metric Duration
Simulator Boot 92000 ms
Simulator Boot (Run) 2000 ms
App Install 20000 ms
App Launch 19000 ms
Test Execution 258000 ms

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 1471.000 ms
Base64 CN1 encode 2186.000 ms
Base64 encode ratio (CN1/native) 1.486x (48.6% slower)
Base64 native decode 957.000 ms
Base64 CN1 decode 1639.000 ms
Base64 decode ratio (CN1/native) 1.713x (71.3% slower)
Base64 SIMD encode 541.000 ms
Base64 encode ratio (SIMD/native) 0.368x (63.2% faster)
Base64 encode ratio (SIMD/CN1) 0.247x (75.3% faster)
Base64 SIMD decode 504.000 ms
Base64 decode ratio (SIMD/native) 0.527x (47.3% faster)
Base64 decode ratio (SIMD/CN1) 0.308x (69.2% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 90.000 ms
Image createMask (SIMD on) 24.000 ms
Image createMask ratio (SIMD on/off) 0.267x (73.3% faster)
Image applyMask (SIMD off) 276.000 ms
Image applyMask (SIMD on) 163.000 ms
Image applyMask ratio (SIMD on/off) 0.591x (40.9% faster)
Image modifyAlpha (SIMD off) 402.000 ms
Image modifyAlpha (SIMD on) 159.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.396x (60.4% faster)
Image modifyAlpha removeColor (SIMD off) 435.000 ms
Image modifyAlpha removeColor (SIMD on) 313.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.720x (28.0% faster)
Image PNG encode (SIMD off) 2243.000 ms
Image PNG encode (SIMD on) 1299.000 ms
Image PNG encode ratio (SIMD on/off) 0.579x (42.1% faster)
Image JPEG encode 1168.000 ms

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.

missing core method

1 participant