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

    https://github.com/apache/flink/pull/1048#discussion_r37754281
  
    --- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/util/SerializedThrowable.java
 ---
    @@ -0,0 +1,106 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.flink.runtime.util;
    +
    +import com.google.common.base.Preconditions;
    +import org.apache.flink.util.ExceptionUtils;
    +import org.apache.flink.util.InstantiationUtil;
    +
    +import java.io.Serializable;
    +import java.util.Arrays;
    +
    +/**
    + * Utility class for dealing with serialized Throwables.
    + * Needed to send around user-specific exception classes with Akka.
    + */
    +public class SerializedThrowable implements Serializable {
    +   private final byte[] serializedError;
    +
    +   // The exception must not be (de)serialized with the class, as its
    +   // class may not be part of the system class loader.
    +   private transient Throwable cachedError;
    +
    +
    +   /**
    +    * Create a new SerializedThrowable.
    +    * @param error The exception to serialize.
    +    */
    +   public SerializedThrowable(Throwable error) {
    +           Preconditions.checkNotNull(error, "The exception to serialize 
has to be set");
    +           this.cachedError = error;
    +           byte[] serializedError;
    +           try {
    +                   serializedError = 
InstantiationUtil.serializeObject(error);
    +           }
    +           catch (Throwable t) {
    +                   // could not serialize exception. send the stringified 
version instead
    +                   try {
    +                           this.cachedError = new 
Exception(ExceptionUtils.stringifyException(error));
    +                           serializedError = 
InstantiationUtil.serializeObject(this.cachedError);
    +                   }
    +                   catch (Throwable tt) {
    +                           // seems like we cannot do much to report the 
actual exception
    +                           // report a placeholder instead
    +                           try {
    +                                   this.cachedError = new Exception("Cause 
is a '" + error.getClass().getName()
    +                                                   + "' (failed to 
serialize or stringify)");
    +                                   serializedError = 
InstantiationUtil.serializeObject(this.cachedError);
    +                           }
    +                           catch (Throwable ttt) {
    +                                   // this should never happen unless the 
JVM is fubar.
    +                                   // we just report the state without the 
error
    +                                   this.cachedError = null;
    +                                   serializedError = null;
    +                           }
    +                   }
    +           }
    +           this.serializedError = serializedError;
    +   }
    +
    +   public Throwable getError(ClassLoader usercodeClassloader) {
    --- End diff --
    
    What kind of camel case is `usercodeClassloader`?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to