CtrlK
BlogDocsLog inGet started
Tessl Logo

martinfrancois/java-optionals

Help AI coding agents use Java Optional well in new code and cleanups, without replacing one antipattern with another.

100

2.08x
Quality

100%

Does it follow best practices?

Impact

100%

2.08x

Average score across 4 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-4/

Extend command sanitization

Create CommandSanitizer.java with the revised class. Assume Java 17.

Current code:

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;

final class CommandSanitizer {
    private static final Set<String> SECRET_OPTIONS = Set.of("--token", "--key", "--workflow", "--config-dir", "--state-home", "--output");

    String sanitize(List<String> args) {
        List<String> sanitized = new ArrayList<>();
        boolean redactNext = false;
        for (String arg : args) {
            if (redactNext) {
                sanitized.add("<redacted>");
                redactNext = false;
                continue;
            }
            Optional<String> option = SECRET_OPTIONS.stream()
                    .filter(secret -> arg.equals(secret))
                    .findFirst();
            if (option.isPresent()) {
                sanitized.add(option.orElseThrow());
                redactNext = true;
            } else {
                sanitized.add(arg);
            }
        }
        return String.join(" ", sanitized);
    }
}

Required changes:

  • Preserve exact-option behavior: --token abc becomes --token <redacted>.
  • Add option=value behavior: --key=abc becomes --key=<redacted>.
  • Preserve non-secret arguments.
  • Keep the real option-set lookup readable and centralized.
  • Return String.join(" ", sanitized).

README.md

tile.json