4 ms·
Using casts between types with different generics can cause "heap corruption", but the compiler will give warnings on them (except if explicitly suppressed). Th
by dzaima 5y ago
Using casts between types with different generics can cause "heap corruption", but the compiler will give warnings on them (except if explicitly suppressed). The article doesn't use any such casts, but can still "cast" any non-null object of any type to any other, without any warnings emitted.
The behavior used to get that to happen, as far as I remember, uses the java spec giving a concrete way on how to parse generics. Multiple other compilers (including the official Java 9 one, if I'm reading correctly) actually emitted an error on it, despite "technically" it being "valid" Java code, to emphasize how weird the situation is.
edit: this is of similar (mostly academic) significance to, say, finding a case where you can double-free in Rust without any unsafe code. Sure, rust is unsafe if you use "unsafe", but other than that, you should hope it's sound. It's not at all as catastrophic as JVMs are already pretty much just dynamically typed though, but it's still a bad thing to have.
- 3836293648 5y agoMore accurate comparison: A double drop in rust. A double free would generally be a library bug