java

Seeded Spring Boot defects — entities out of controllers, N+1 queries, self-invoked @Transactional.

16 deliberate defects, each with a marker naming the rule in standards/ it breaks. It measures recall: how many of the defects the reviewer flags at their severity or higher. The pass condition is that all 10 BLOCKER defects are flagged.

Because each marker names a rule, the scorer also grades attribution. A reviewer that finds the bug but cites the wrong rule counts as caught, and separately as misattributed.

Running it

Nothing here is ever merged. Open a throwaway pull request on a pilot repository already onboarded for this stack, adding this directory and seeded/clean together, wait for the automated review to finish, then score it.

seed-canary.yml does exactly this on a schedule and closes the pull request afterwards, including when the run fails.

terminal
$ GH_TOKEN=... npx redlinegate metrics score-seeds --repo <org>/<repo> --pr <n>

Flags and output are on redline metrics.

The 16 defects

SeedSeverityRule it violatesDefect
1BLOCKERjava/reference-equalityString compared by identity
1BLOCKERcore/hardcoded-secretshardcoded secret
2BLOCKERjava/bigdecimal-value-semanticsdouble constructor captures rounding error
2BLOCKERjava/field-injectionfield injection instead of constructor injection
3BLOCKERjava/entity-in-controller-responseJPA entity returned from a controller
4BLOCKERjava/jpql-string-concatenationSQL built by string concatenation with request input
5BLOCKERjava/transactional-self-invocation@Transactional on a private method — the proxy is bypassed
6BLOCKERjava/broad-catchexception swallowed, failure reported as success
7BLOCKERjava/mutable-singleton-statemutable shared state on a singleton bean
9BLOCKERcore/type-checker-suppressioncompiler warning suppressed with no explanation and no ticket
3HIGHjava/dropped-exception-causeonly the message survives
4HIGHjava/swallowed-interruptinterrupt status erased
5HIGHjava/print-stack-tracestderr, outside logging
6HIGHjava/ignored-pure-resultresult of toLowerCase discarded
7HIGHjava/test-without-assertionexpected exception with no fail()
8HIGHcore/customer-data-in-logscustomer identifier written to logs

Scoring

The score reports BLOCKER recall, false positives, and rule attribution. The canary appends it to data/seed-scores.jsonl and fails the run if BLOCKER recall drops below 1.0 or the clean corpus attracts a false positive. Of the 16 defects here, 10 BLOCKER and 6 HIGH — only the BLOCKER count is a pass condition.

Adding a defect

Add the code and one marker line above it. The format, and what scripts/validate.mjs checks, are on Seeded corpus.

The full file

seeded/java/AntiSlop.java · 49 lines · 1.5 KB
// DO NOT MERGE — Redline validation seed (anti-slop rules).
package seeded;

import java.math.BigDecimal;

class AntiSlop {
  boolean isAdmin(String role) {
    // SEED 1 [BLOCKER] (java/reference-equality) String compared by identity
    return role == "admin";
  }

  BigDecimal vat(BigDecimal net) {
    // SEED 2 [BLOCKER] (java/bigdecimal-value-semantics) double constructor captures rounding error
    BigDecimal rate = new BigDecimal(0.2);
    return net.multiply(rate);
  }

  Order load(Repo repo, String id) {
    try { return repo.load(id); }
    // SEED 3 [HIGH] (java/dropped-exception-cause) only the message survives
    catch (java.sql.SQLException e) { throw new ServiceException(e.getMessage()); }
  }

  void poll() {
    while (running) {
      try { Thread.sleep(1000); }
      // SEED 4 [HIGH] (java/swallowed-interrupt) interrupt status erased
      catch (InterruptedException e) { log.warn("interrupted"); }
    }
  }

  void send(Client client, Event evt) {
    try { client.send(evt); }
    // SEED 5 [HIGH] (java/print-stack-trace) stderr, outside logging
    catch (java.io.IOException e) { e.printStackTrace(); }
  }

  User find(String email) {
    // SEED 6 [HIGH] (java/ignored-pure-result) result of toLowerCase discarded
    email.toLowerCase();
    return users.findByEmail(email);
  }

  @org.junit.jupiter.api.Test void rejectsNegative() {
    // SEED 7 [HIGH] (java/test-without-assertion) expected exception with no fail()
    try { svc.charge(-1); } catch (IllegalArgumentException expected) { }
  }
}
seeded/java/SeededViolations.java · 70 lines · 2.6 KB
// DO NOT MERGE — Redline validation seed.
// Every `SEED n [SEVERITY] (rule-id)` marker must be flagged at that severity or higher,
// citing that rule id. Score with scripts/score-seeds.mjs.
// Score with: node scripts/score-seeds.mjs --repo <org>/<repo> --pr <n>
package com.redline.seed;

import java.sql.Connection;
import java.sql.Statement;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SeededViolations {

    // SEED 1 [BLOCKER] (core/hardcoded-secrets) hardcoded secret
    private static final String API_KEY = "acme-live-7Fq2Rd9Km4Tz6Hb3Vy8Wn";

    // SEED 2 [BLOCKER] (java/field-injection) field injection instead of constructor injection
    @Autowired
    private AccountRepository accountRepository;

    // SEED 3 [BLOCKER] (java/entity-in-controller-response) JPA entity returned from a controller
    @GetMapping("/accounts")
    public List<AccountEntity> findAccounts(@RequestParam String name, Connection conn) throws Exception {
        Statement st = conn.createStatement();
        // SEED 4 [BLOCKER] (java/jpql-string-concatenation) SQL built by string concatenation with request input
        st.executeQuery("SELECT * FROM accounts WHERE name = '" + name + "'");
        return accountRepository.findAll();
    }

    // SEED 5 [BLOCKER] (java/transactional-self-invocation) @Transactional on a private method — the proxy is bypassed
    @Transactional
    private void updateBalance(String accountId) {
        try {
            accountRepository.adjust(accountId);
        } catch (Exception e) {
            // SEED 6 [BLOCKER] (java/broad-catch) exception swallowed, failure reported as success
        }
    }

    // SEED 7 [BLOCKER] (java/mutable-singleton-state) mutable shared state on a singleton bean
    private int requestCounter = 0;

    // SEED 8 [HIGH] (core/customer-data-in-logs) customer identifier written to logs
    public void audit(String msisdn) {
        System.out.println("charging msisdn=" + msisdn);
        requestCounter++;
    }

    interface AccountRepository {
        List<AccountEntity> findAll();
        void adjust(String id);
    }

    static class AccountEntity {}
}

class Coercion {

    // SEED 9 [BLOCKER] (core/type-checker-suppression) compiler warning suppressed with no explanation and no ticket
    @SuppressWarnings("unchecked")
    static <T> T coerce(Object value) {
        return (T) value;
    }
}