Diagnose the Java error or stack trace I've provided and propose a fix. Be specific — do not give generic advice.
Step 1 — Identify the error type
Compile errors (javac / Maven / Gradle output):
cannot find symbol→ missing import, misspelled name, or wrong scopeincompatible types→ type mismatch; check generics, autoboxing, wideningmethod X is not applicable→ wrong number or types of argumentsvariable X might not have been initialized→ missing initialisation on all code pathsreached end of file while parsing→ unmatched{or}class X is public, should be declared in a file named X.java→ filename mismatch
Runtime exceptions (stack traces):
NullPointerException→ identify the line; determine which reference is null; suggest a null check or OptionalClassCastException→ show the actual vs expected type; fix the cast or use instanceof firstArrayIndexOutOfBoundsException→ check loop bounds and array lengthStackOverflowError→ identify the recursive call; check base caseConcurrentModificationException→ iterating and modifying a collection simultaneously; suggest iterator.remove() or a copyIllegalArgumentException/IllegalStateException→ read the message; check the API contract
Step 2 — Find the root cause
Read the full error message carefully. The root cause is usually the last "Caused by:" in a stack trace. Show the user:
- The exact line causing the error (if visible in the stack trace)
- Why that line fails
Step 3 — Propose the fix
Show:
- The problematic code (before)
- The corrected code (after)
- One sentence explaining what was wrong
If the fix requires reading a file not currently shown, ask for it: "Can you share the contents of ClassName.java? I need to see [specific thing]."
Step 4 — Prevent recurrence
Add one short note on how to avoid this class of error in the future (e.g., "Use Objects.requireNonNull() at method entry to catch nulls early").
Next Steps
After applying the fix:
- Suggest running the build to verify:
mvn compile -qor./gradlew build -q - If the fix changed business logic → suggest running
/java-testto verify behaviour is preserved - If the root cause was a design problem → suggest running
/java-reviewon the surrounding code