[ 
https://issues.apache.org/jira/browse/BEAM-12474?focusedWorklogId=622686&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-622686
 ]

ASF GitHub Bot logged work on BEAM-12474:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/Jul/21 19:50
            Start Date: 14/Jul/21 19:50
    Worklog Time Spent: 10m 
      Work Description: kennknowles commented on a change in pull request 
#15037:
URL: https://github.com/apache/beam/pull/15037#discussion_r669906553



##########
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/util/ComparableThrowable.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.beam.sdk.util;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import javax.annotation.Nullable;
+
+/**
+ * A wrapper around a {@link Throwable} for use with coders.
+ *
+ * <p>The {@link Throwable} class is serializable. However, it, along with man 
child classes like
+ * {@link Exception}, does not override {@link Object#equals(Object)}. As a 
result, t1.equals(t2)
+ * will return false if t2 is a deserialized instance of serialized t1. This 
makes it appear as if
+ * coders are mutating the value, which can lead to things like log spam. This 
wrapper overrides
+ * {@link Object#equals(Object)} to get around this issue. The hash code 
remains the same as the
+ * underlying {@link Throwable}.
+ *
+ * <p>The equality comparison is transitive, meaning that for two {@link 
Throwable}s t1 and t2, the
+ * causes must be equal. This can occur either because they are both null or 
because they are both
+ * equal after being wrapped.
+ *
+ * <p>Note that this is simply a best effort based on properties like instance 
type, stack trace,
+ * message, and cause. It cannot guarantee that the state that led to the 
exception is the same,
+ * unless it is fully captured in the message, nor can it differentiate 
between two exceptions
+ * thrown at different times or in different processes. For this reason, this 
is not suitable for a
+ * general-purpose {@link Throwable} equality comparison. It merely exists to 
try to avoid false
+ * positives in a mutation check for coders.
+ *
+ * <p>Due to the above, this does not support comparison to a raw {@link 
Throwable}.
+ */
+public class ComparableThrowable implements Serializable {
+  private Throwable throwable;
+
+  private ComparableThrowable() {
+    // Can't set this to null without adding a pointless @Nullable annotation 
to the field. It also
+    // needs to be set from the constructor to avoid a checkstyle violation.
+    this.throwable = new Throwable();
+  }
+
+  /** Wraps {@code throwable} and returns the result. */
+  public static ComparableThrowable forThrowable(Throwable throwable) {
+    ComparableThrowable comparable = new ComparableThrowable();
+    comparable.throwable = throwable;
+    return comparable;
+  }
+
+  /** Returns the underlying {@link Throwable}. */
+  public Throwable throwable() {
+    return throwable;
+  }
+
+  @Override
+  public int hashCode() {
+    return throwable.hashCode();
+  }
+
+  @Override
+  public boolean equals(@Nullable Object obj) {
+    if (!(obj instanceof ComparableThrowable)) {
+      return false;
+    }
+    Throwable other = ((ComparableThrowable) obj).throwable;
+
+    boolean currentLevelEqual =
+        throwable.getClass().isInstance(other)

Review comment:
       Yea




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 622686)
    Time Spent: 5h 40m  (was: 5.5h)

> Configure PubsubIO with dead-letter topic
> -----------------------------------------
>
>                 Key: BEAM-12474
>                 URL: https://issues.apache.org/jira/browse/BEAM-12474
>             Project: Beam
>          Issue Type: Improvement
>          Components: io-java-gcp
>            Reporter: Zachary Houfek
>            Assignee: Zachary Houfek
>            Priority: P2
>          Time Spent: 5h 40m
>  Remaining Estimate: 0h
>
> Based on discussion from [PR14971|https://github.com/apache/beam/pull/14971].
> Currently, PubsubIO throws a RuntimeException when it can't parse a payload. 
> It would perhaps be helpful if users could configure PubsubIO.Read with a 
> dead-letter topic so that parsing errors instead write to the topic rather 
> than just throw an exception.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to