A Java compatibility pitfall is explored where compiling code with JDK 9+ while targeting Java 1.8 causes a NoSuchMethodError at runtime. The root cause is that Java 9 introduced covariant return type overrides in ByteBuffer (e.g., position(int) now returns ByteBuffer instead of Buffer), so the compiler records the new signature in bytecode, which doesn't exist in Java 1.8. The fix is to use the --release=8 compiler flag instead of --source/--target, which enforces use of the correct API signatures for the target version via the ct.sym file bundled in the JDK. In Maven, this is set via the maven.compiler.release property.
Sort: