Tsz-wo Sze created HDDS-8551:
--------------------------------
Summary: CodecRegistry should not get coder from super classes and
interfaces
Key: HDDS-8551
URL: https://issues.apache.org/jira/browse/HDDS-8551
Project: Apache Ozone
Issue Type: Sub-task
Components: db
Reporter: Tsz-wo Sze
Assignee: Tsz-wo Sze
{code:java}
//CodecRegistry.java
private <T> Codec<T> getCodec(Class<T> format) {
final List<Class<?>> classes = new ArrayList<>();
classes.add(format);
classes.addAll(ClassUtils.getAllSuperclasses(format));
classes.addAll(ClassUtils.getAllInterfaces(format));
for (Class<?> clazz : classes) {
final Codec<?> codec = valueCodecs.get(clazz);
if (codec != null) {
return (Codec<T>) codec;
}
}
throw new IllegalStateException(
"Codec is not registered for type: " + format);
}
{code}
In the code above, it tries to get a codec from the super classes and
interfaces of T.
Suppose Class<T> is not in valueCodecs and Class<S> is in valueCodecs, where S
is a super class/interface of T and S != T. The method will return Codec<S>.
However, Codec<S> is a lossy codec:
- Codec<S> can serialize T as S, possibly losing the extra information in T
but not in S;
- Codec<S> cannot deserialize T – it will return S instead.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]