Uploaded image for project: 'Apache Ozone'
  1. Apache Ozone
  2. HDDS-2274 Avoid buffer copying in Codec
  3. HDDS-8551

Fix the generic type of CodecRegistry.getCodec

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.4.0
    • db

    Description

      //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);
        }
      

      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>.

      Attachments

        Issue Links

          Activity

            People

              szetszwo Tsz-wo Sze
              szetszwo Tsz-wo Sze
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: