|
20 | 20 | import java.io.ByteArrayInputStream; |
21 | 21 | import java.io.ByteArrayOutputStream; |
22 | 22 | import java.io.IOException; |
| 23 | +import java.io.InvalidClassException; |
23 | 24 | import java.io.ObjectInputStream; |
24 | 25 | import java.io.ObjectOutputStream; |
25 | 26 | import java.net.ServerSocket; |
|
49 | 50 | import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.annotations.VisibleForTesting; |
50 | 51 | import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Strings; |
51 | 52 | import org.checkerframework.checker.nullness.qual.Nullable; |
| 53 | +import org.slf4j.Logger; |
| 54 | +import org.slf4j.LoggerFactory; |
52 | 55 |
|
53 | 56 | /** |
54 | 57 | * A utility class that allows upgrading transforms of a given pipeline using the Beam Transform |
55 | 58 | * Service. |
56 | 59 | */ |
57 | 60 | public class TransformUpgrader implements AutoCloseable { |
| 61 | + |
| 62 | + private static final Logger LOG = LoggerFactory.getLogger(TransformUpgrader.class); |
58 | 63 | private static final String UPGRADE_NAMESPACE = "transform:upgrade:"; |
59 | 64 |
|
60 | 65 | private ExpansionServiceClientFactory clientFactory; |
@@ -405,10 +410,16 @@ public static byte[] toByteArray(Object object) { |
405 | 410 | * method. |
406 | 411 | * @return re-generated object. |
407 | 412 | */ |
408 | | - public static Object fromByteArray(byte[] bytes) { |
| 413 | + public static Object fromByteArray(byte[] bytes) throws InvalidClassException { |
409 | 414 | try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes); |
410 | 415 | ObjectInputStream in = new ObjectInputStream(bis)) { |
411 | 416 | return in.readObject(); |
| 417 | + } catch (InvalidClassException e) { |
| 418 | + LOG.info( |
| 419 | + "An object cannot be re-generated from the provided byte array. Caller may use the " |
| 420 | + + "default value for the parameter when upgrading. Underlying error: " |
| 421 | + + e); |
| 422 | + throw e; |
412 | 423 | } catch (Exception e) { |
413 | 424 | throw new RuntimeException(e); |
414 | 425 | } |
|
0 commit comments