Beyond Vibe Coding: Automating Log-Driven Java Defect Remediation with Local LLMs, ArchUnit, and PMD 7
How to turn production stack traces into verified Spring Boot pull requests on local hardware without sacrificing architectural integrity.
Production Spring Boot services emit thousands of structured log events and distributed traces every hour. When an unhandled database error or configuration failure surfaces in those logs, the recovery workflow still looks remarkably manual: an engineer hunts down the stack frame, untangles tightly coupled legacy classes, writes a regression test, and opens a pull request.
In theory, large language models should accelerate that loop. In practice, sending proprietary Java repositories and sensitive production logs to external cloud APIs often hits immediate data governance and compliance walls. To find out whether open-weight models running entirely on local hardware can close that gap safely, I built an open-source reference pipeline in Java 21 and Spring Boot 3.5: autonomous-java-refactoring-guardrails.
The Starting Point: Runtime Failures Inside Legacy Code
Real production defects rarely hide inside clean, freshly scaffolded modules. They usually live in older service classes where infrastructure concerns and business logic have grown together over the years. In the legacymess branch of the repository, a single @Service class intentionally combines three common enterprise anti-patterns:
- Field-injected configuration (
@Value): Credentials and connection settings are injected directly into private fields, blocking plain constructor instantiation in fast unit tests. - Inline JDBC calls (
DriverManagerandResultSet): SQL execution and connection management sit directly inside domain logic. - Swallowed exceptions (
e.printStackTrace()): Database failures are caught, printed to standard error, and masked behind empty list returns.
When the database becomes unreachable or credentials expire, runtime logs capture raw PSQLException stack traces pointing straight to that service method. The goal of the harness is straightforward: take that captured log context, use a local LLM to extract a clean repository boundary with proper retry and exception-translation semantics, and prove architectural compliance before a human reviewer ever sees a pull request.
Preventing the “Green Build Illusion” with ArchUnit 1.3 and PMD 7
Running local code models across 3B, 7B, and 14B parameter sizes quickly reveals a trap I call the green build illusion. When prompted only to make the compiler and unit tests pass, smaller models routinely take shortcuts that undermine the codebase:
- Leaving
@Valuefields untouched while wrapping the method signature to satisfy a prompt. - Importing
java.sql.*directly inside@Serviceclasses instead of isolating persistence behind a repository interface. - Returning hardcoded
List.of()stubs or duplicating Mockito setup so assertions pass vacuously.
To prevent subtle architectural drift from slipping past a green Maven build, every automated refactoring pass is gated by an executable fitness function combining three verification layers:
@AnalyzeClasses(packages = "com.aiops.governance", importOptions = ImportOption.DoNotIncludeTests.class)
public class ArchitectureGuardrailTest {
@ArchTest
static final ArchRule services_should_not_use_field_injection =
noFields().that().areDeclaredInClassesThat().areAnnotatedWith(Service.class)
.should().beAnnotatedWith(Autowired.class)
.orShould().beAnnotatedWith(Value.class);
@ArchTest
static final ArchRule services_should_not_access_jdbc_directly =
noClasses().that().areAnnotatedWith(Service.class)
.should().dependOnClassesThat()
.resideInAnyPackage("java.sql..", "org.springframework.jdbc..");
}
Alongside ArchUnit 1.3 structural assertions, the Maven build enforces PMD 7 static rules to reject swallowed exceptions, unused imports, console print calls, and high cyclomatic complexity, while JUnit 5 and Mockito verify normal delegation, transient timeout propagation, and non-transient exception wrapping without booting a Spring context.
What Happened Across 3B, 7B, and 14B Local Models
Benchmarking identical log-driven refactoring tasks across three local model tiers highlighted clear operational trade-offs:
| Model Tier | Where It Excels | Where It Struggles |
|---|---|---|
3B (qwen2.5-coder:3b) |
Fast generation of Java record DTOs, custom exception hierarchies, and initial class skeletons on low-memory edge hardware. |
Prone to hallucinating Spring Data method signatures or leaving subtle Mockito stubbing mismatches across files. |
7B (qwen2.5-coder:7b) |
Strong at resolving cross-file compiler errors, constructor injection, and Java 21 stream generics when fed structured Maven error output. | Occasionally requires a second repair pass when refactoring deeply nested JDBC resource blocks. |
14B (qwen2.5-coder:14b) |
Highest single-pass accuracy across multi-class Spring Boot 3.5 wiring and architectural decomposition. | Noticeably slower prompt ingestion on CPU-bound systems; benefits from stage-level model unloading. |
Key Takeaway: Models Are Frozen — Your Harness Learns
Core Engineering Principle: An open-weight model does not retain memory across retries; its weights are static. Reliable automation comes from encoding every recurring failure mode into deterministic code outside the model.
Instead of writing longer prompts whenever a model stumbled on Java 21 generics or missing imports, three deterministic patterns delivered far higher reliability:
- Bottom-Up Batch Decomposition: Generate domain records and repository interfaces first, verify compilation, and only then wire service classes and unit tests.
- Deterministic AST & Import Normalization: Promote recurring import resolutions and type fixes out of LLM retry loops into deterministic code recipes (such as OpenRewrite rules).
- Explicit Memory Management: Unload models (
keep_alive: 0) between pipeline stages so local workstations and edge devices stay responsive during Maven compilation and test runs.
Scaling to Enterprise Observability: Jaeger, Kafka, and Automated PRs
To move from a local prototype to an enterprise microservice environment, the same verification loop connects directly to standard observability infrastructure:
- Trace & Log Ingestion: OpenTelemetry and Jaeger export runtime exceptions to a dedicated Kafka topic (
prod.exceptions.triaged). - Fingerprinting & Triage: A consumer groups duplicate stack traces, maps stack frames to exact source repositories and commit SHAs, and filters transient network noise from actionable code defects.
- Isolated Local Remediation: A worker checks out a
fix/<trace-id>branch, runs a planner to map affected interfaces, and escalates edits across3B → 7B → 14Blocal models paired with deterministic recipes. - Zero-Trust Pull Request Gate: A pull request is opened on GitHub only if
mvn test—including JUnit 5, Mockito, ArchUnit 1.3, and PMD 7—passes completely. Reviewers receive the diff alongside the original Jaeger trace link and guardrail report.
You can inspect the complete before-and-after code, guardrail tests, and batch orchestrator across the main, legacymess, and refactored branches in the autonomous-java-refactoring-guardrails GitHub repository.




