Interfacesmedium3-5 years

A platform team adds `boolean healthy();` to their published `Plugin` interface and ships it as a minor release, reasoning "every plugin author will just recompile." Forty third-party plugins, none of them recompiled, are loaded into the platform the next day. What happens, and what should the team have shipped instead?

Every one of the forty plugin jars still compiles fine against nothing (they were built last year, against the old interface, and nobody rebuilt them), and every one of them still loads fine, because the JVM doesn't check whether a class implements every interface method at load time. The failure happens later and separately, at the exact moment the platform actually calls plugin.healthy() on one of those old plugin objects: the JVM looks for a healthy() implementation in that class and its supertypes, finds none, and throws AbstractMethodError — one crash per plugin, in production, the first time each one's health check is invoked, because none of those plugin jars are in the platform's own build and so nothing caught this before release. The fix is a default method — default boolean healthy() { return true; } — which gives every old, unrecompiled class file a working implementation to inherit, so the interface gains a new method without breaking anyone who hasn't rebuilt against it.

The lesson behind it →
More on Interfaces