Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/incubator-flink/pull/236#discussion_r20934292
  
    --- Diff: 
flink-java/src/main/java/org/apache/flink/api/java/typeutils/runtime/PojoSerializer.java
 ---
    @@ -195,22 +289,44 @@ public void serialize(T value, DataOutputView target) 
throws IOException {
                        throw new RuntimeException("Error during POJO copy, 
this should not happen since we check the fields" +
                                        "before.");
                }
    +
    +           // Serialize subclass fields as well.
    +           if (!(clazz == value.getClass())) {
    +                   Class<?> subclass = value.getClass();
    +                   TypeSerializer subclassSerializer = 
getSubclassSerializer(subclass);
    +                   subclassSerializer.serialize(value, target);
    +           }
        }
     
        @Override
    +   @SuppressWarnings("unchecked")
        public T deserialize(DataInputView source) throws IOException {
                boolean isNull = source.readBoolean();
                if(isNull) {
                        return null;
                }
    +
                T target;
    -           try {
    -                   target = clazz.newInstance();
    -           }
    -           catch (Throwable t) {
    -                   throw new RuntimeException("Cannot instantiate class.", 
t);
    +
    +           Class<?> subclass = null;
    +           TypeSerializer subclassSerializer = null;
    +
    +           boolean isExactClass = source.readBoolean();
    +           if (!isExactClass) {
    +                   String subclassName = source.readUTF();
    +                   try {
    +                           subclass = Class.forName(subclassName, true, 
this.getClass().getClassLoader());
    +                   } catch (ClassNotFoundException e) {
    +                           throw new RuntimeException("Cannot instantiate 
class.", e);
    +                   }
    +                   subclassSerializer = getSubclassSerializer(subclass);
    +                   target = (T) subclassSerializer.createInstance();
    +                   // also initialize fields for which the subclass 
serializer is not responsible
    +                   initializeFields(target);
    +           } else {
    +                   target = createInstance();
    --- End diff --
    
    you are swallowing instantiation exceptions here


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to