[ 
https://issues.apache.org/jira/browse/HDDS-8551?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tsz-wo Sze resolved HDDS-8551.
------------------------------
    Fix Version/s: 1.4.0
       Resolution: Fixed

The pull request is now merged.

> Fix the generic type of CodecRegistry.getCodec
> ----------------------------------------------
>
>                 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
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.4.0
>
>
> {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.
> In such cases, the returned Codec<S> does not match the return type Codec<T>.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to