You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/02/08 16:22:05 UTC

[GitHub] [avro] radai-rosenblatt commented on a change in pull request #1526: WIP AVRO-3375 - initial impl for better NPE messages

radai-rosenblatt commented on a change in pull request #1526:
URL: https://github.com/apache/avro/pull/1526#discussion_r801817666



##########
File path: lang/java/avro/src/main/java/org/apache/avro/generic/TracingNullPointException.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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
+ *
+ *     https://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.avro.generic;
+
+import org.apache.avro.Schema;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * a {@link NullPointerException} with extra fields used to trace back the path
+ * to a null value through an object graph
+ */
+public class TracingNullPointException extends NullPointerException {
+  private final NullPointerException cause;
+  private final Schema expected;
+  private final List<PathStep> reversePath;
+
+  public TracingNullPointException(NullPointerException cause, Schema expected) {
+    this.cause = cause;
+    this.expected = expected;
+    this.reversePath = new ArrayList<>(1); //assume short
+  }
+
+  public void tracePath(PathStep step) {
+    reversePath.add(step);
+  }
+
+  @Override
+  public synchronized NullPointerException getCause() {
+    return cause;
+  }
+
+  /**
+   * @return a hopefully helpful error message
+   */
+  public NullPointerException summarize() {
+    StringBuilder sb = new StringBuilder();
+    PathStep lastStep = reversePath.get(0);

Review comment:
       will fix




-- 
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: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org