In org.springframework.core.SerializableTypeWrapper
(version 5.2.3), there is the following code at line 112:
if (GraalDetector.inImageCode() || !Serializable.class.isAssignableFrom(Class.class)) {
// Let's skip any wrapping attempts if types are generally not serializable in
// the current runtime environment (even java.lang.Class itself, e.g. on Graal)
return providedType;
}
I'm curious about the second check (!Serializable.class.isAssignableFrom(Class.class)
): is it possible for it to evaluate to true
(that is, for Serialazable.class
to be not assignable from Class.class
)?
Here is what Class#isAssignableFrom()
javadoc says:
Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter.
Looking at the code of Class
, I see the following:
public final class Class<T> implements java.io.Serializable
So Serializable
is a superinterface of Class
and should always be assignable from Class
. But the check in the Spring code suggests that sometimes it's not.
How come? In what situations can this happen and why don't they violate the Java Language Specification?