Why can't the compiler detect this error regarding Serializable declaration at compile time?-Collection of common programming errors
The compiler is designed to check the code based on the requirements of the language, not an individual library. The language could be changed to add a keyword or annotation which perform additional checks and the library could use those in theory.
What would be useful is if the compiler could run library specific checking code in the way it can load annotations (which are currently purely data) This way additional checks could be performed at compile time without it knowing the behaviour of any individual library.