Skip to content

feat: add eval for UTF-16 character predicate streams #61

Description

@martinfrancois

Problem

The Streams capture workflow missed a character loop that can become String.chars().allMatch(...). This is eval-worthy because a superficially cleaner rewrite can change two contracts: allMatch is vacuously true for empty input, and codePoints() changes UTF-16 code-unit iteration into Unicode code-point iteration.

Area

Evals or scoring

Describe the solution you want

Add a reference eval for replacing a non-empty universal charAt predicate loop with String.chars().allMatch(...) while preserving empty-input and supplementary-character behavior.

Code before the prompt was executed

boolean isNumeric(String value) {
    if (value.isEmpty()) {
        return false;
    }
    for (int i = 0; i < value.length(); i++) {
        if (!Character.isDigit(value.charAt(i))) {
            return false;
        }
    }
    return true;
}

Prompt that caused the implementation

The original prompt required a complete Java-source API-reuse audit:

  • Audit every tracked Java source for worthwhile replacements with the Java standard library or a directly declared dependency.
  • Implement only changes that clearly reduce code, complexity, duplication, or maintenance risk.
  • Preserve observable behavior, ordering, failure semantics, null handling, concurrency, security, and relevant performance characteristics.
  • Add focused regression tests for each affected boundary.

The prompt should have activated the Streams skill for a pure universal predicate loop.

Later prompt that exposed the issue

A maintainer later asked whether the Streams capture issue had been created and requested that the capture workflow cover cases like this.

Prompt-produced code before maintainer correction

boolean isNumeric(String value) {
    return !value.isEmpty() && value.chars().allMatch(Character::isDigit);
}

The implementation is preferred, but its important equivalence proof was not captured.

Why the prompt-produced code is weak

The code is not weak; the capture workflow is. Existing predicate-loop guidance explicitly excludes character scans, so it cannot teach when a character scan is safely result-producing. Without a focused eval, an agent may drop the empty guard or choose codePoints() because it appears more Unicode-aware, silently changing behavior.

Behavior-equivalence analysis

allMatch returns true for an empty stream, so !value.isEmpty() is required. charAt and String.chars() both inspect UTF-16 code units. A supplementary mathematical digit such as 𝟙 is two surrogate code units and remains rejected; codePoints() would see one digit and accept it. Tests must cover ASCII digits, BMP Arabic-Indic digits, empty and mixed strings, signs/whitespace, and a supplementary digit.

Maintainer-preferred code

boolean isNumeric(String value) {
    return !value.isEmpty() && value.chars().allMatch(Character::isDigit);
}

Why the replacement is better

The terminal directly expresses the universal predicate and preserves short-circuiting, while the guard and chars() choice make the old contracts explicit.

Desired eval behavior

  • Reward activation during the original audit prompt.
  • Reward preserving the non-empty guard.
  • Reward matching the original iteration unit: charAt to chars().
  • Reward explaining vacuous truth and the UTF-16/code-point distinction.
  • Reward focused supplementary-character tests.

Anti-patterns the eval should reject

  • Dropping the empty guard.
  • Replacing chars() with codePoints() without an explicit contract change.
  • Boxing the primitive stream.
  • Replacing the loop with a regex without proving identical Unicode semantics.

Suggested eval name

utf16-character-allmatch

Examples

Use the helper above as the self-contained reference task. Add Java 8 compatibility entries for String.chars() and String.codePoints() if runtime guidance is added.

Alternatives considered

Appending this to the general predicate-loop issue #49 was rejected because #49 deliberately excludes character scans and does not cover iteration-unit semantics.

Current workaround

Manually compare charAt, chars, and codePoints, and add explicit empty/supplementary test cases.

Additional context

No user-facing contract change is intended.

AI Assistance

  • AI-assisted issue
  • I confirm I understand and reviewed this request

AI prompts / session logs (optional)

Prepared with Codex assistance from a maintainer review of a behavior-preserving Java API-reuse audit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions