The Java type system is broken
The Java type system is full of loopholes. Some are deliberate, some are accidental. The difference is that some generate compiler warnings, and some do not. The kind of compiler warnings that most programmers ignore or suppress, without giving it much thought. In practice any sufficiently large Java program makes use of the deliberate loopholes in unsafe ways; because it’s the most practical thing to do. That includes the Java collections library. It’s unlikely you’ll run into the accidental loopholes of this post by accident.
Everything is broken. Everything is fine.