version compatibility - jspecify/jspecify GitHub Wiki

JSpecify supports any version of Java from 8 up (which is when type-use annotations made their debut).

We don't know of any issues affecting Java 9 or higher. But...

Issues with Java 8

Compile time

If you compile with javac from JDK 8, and use @NullMarked on any methods or constructors, you may be affected by this javac bug. It hasn't been fixed, and our attempts to work around it on our side haven't been fruitful.

Your workarounds:

  • "Don't do that" (don't apply @NullMarked to methods or constructors; on the other hand, we think @NullUnmarked should be fine)
  • Of course, if upgrading to JDK 9 is possible, that would fix it. You can still build with --release 8 so that you can still run on Java 8. There are sometimes issues with doing this.
  • IF the linked bug is ever fixed, upgrade to a new enough javac patch release. You still won't be able to use the -Werror option.
  • Continue to build with JDK 8 but switching to use the JDK 8-compatible javac9 codebase, as explained here TODO. (and TODO: does the `-Werror problem still apply?)

TODO: Note that JDK 8 is more likely to have problems with type-use annotations in general (example)

Runtime

If you run with JDK 8, do not put the JSpecify annotations on your classpath, and use reflection on types that use type-use annotations like @Nullable and @NonNull, Java may throw exceptions. This is caused by JDK-8152174, which is fixed under newer JDKs. (This problem exists with any type-use annotations; it's not specific to JSpecify annotations.)