You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "Tsz-wo Sze (Jira)" <ji...@apache.org> on 2023/05/05 15:41:00 UTC

[jira] [Created] (HDDS-8551) CodecRegistry should not get coder from super classes and interfaces

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: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org