Diagnose Test Failure
Overview
Systematic diagnosis of test failures in the Morphia project. Run the test, read the full error, trace the root cause through source and generated code, fix minimally, and verify.
Workflow
Run the failing test
./mvnw test -pl :module-name -Dtest="ClassName#methodName" -Ddeploy.skip=true- Use
-Ddeploy.skip=trueto skip dokka - Do NOT use
-amwith-Dtest=(applies test filter to all modules) - If dependencies need rebuilding first:
./mvnw install -pl :dep1,:dep2 -DskipTests -Ddeploy.skip=true -Dinvoker.skip=true
- Use
Read the full error - stack trace, error message, line numbers. Don't skip anything.
Find relevant code - Read both source AND generated code:
- Source:
src/main/,src/test/ - Generated bytecode:
target/test-classes/- usejavap -c -p ClassNameto decompile - Generated sources:
target/generated-sources/ - Interfaces from dependencies: check
~/.m2/repository/source jars withunzip -p
- Source:
Trace the root cause - Follow the error backward:
- What method is missing/wrong?
- What generated it? (Gizmo generator? ASM generator?)
- What does the interface/superclass require?
- Compare with working examples (ASM-based generators have bridge methods; check if Gizmo-based ones do too)
Fix minimally - One change at a time. Rebuild affected modules:
./mvnw install -pl :critter-core,:critter-maven -DskipTests -Ddeploy.skip=true -Dinvoker.skip=trueVerify - Re-run the failing test AND related tests in the same class.
Common Morphia/Critter Issues
| Error | Likely Cause |
|---|---|
AbstractMethodError |
Missing bridge methods in generated bytecode (generic interface erasure) |
Cannot checkcast to primitive |
Gizmo checkCast doesn't work on primitives - use smartCast |
Cannot convert primitive to Object |
Need boxing: smartCast(result, wrapperType) |
NoSuchMethodError __read*/__write* |
Accessor methods not generated on entity class |
ClassNotFoundException __morphia.* |
Critter code generation didn't run or class not registered |
Key Gotchas
- Gizmo does NOT auto-generate bridge methods for generic interfaces
- Primitive types need explicit boxing/unboxing via
smartCast checkCast(Object -> wrapper)thensmartCast(wrapper -> primitive)for unboxingsmartCast(primitive -> wrapper)for boxing- Always check both Gizmo (
parser/gizmo/) and ASM (parser/asm/) generators for patterns