This is an automated email from the ASF dual-hosted git repository.

rubenql pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new fbe6982  [CALCITE-4393] ExceptionInInitializerError due to NPE in 
SqlCallBinding caused by circular dependency
fbe6982 is described below

commit fbe69824ffb13f847d1db6e26f0030ddec7b0e8c
Author: rubenada <rube...@gmail.com>
AuthorDate: Wed Nov 11 15:01:02 2020 +0000

    [CALCITE-4393] ExceptionInInitializerError due to NPE in SqlCallBinding 
caused by circular dependency
---
 .../java/org/apache/calcite/sql/SqlCallBinding.java     | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java 
b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
index 00823bb..f85a5c4 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
@@ -56,8 +56,17 @@ import static java.util.Objects.requireNonNull;
  * analyzing to the operands of a {@link SqlCall} with a {@link SqlValidator}.
  */
 public class SqlCallBinding extends SqlOperatorBinding {
-  private static final SqlCall DEFAULT_CALL =
-      SqlStdOperatorTable.DEFAULT.createCall(SqlParserPos.ZERO);
+
+  /** Static nested class required due to
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-4393";>[CALCITE-4393]
+   * ExceptionInInitializerError due to NPE in SqlCallBinding caused by 
circular dependency</a>.
+   * The static field inside it cannot be part of the outer class: it must be 
defined
+   * within a nested class in order to break the cycle during class loading. */
+  private static class DefaultCallHolder {
+    private static final SqlCall DEFAULT_CALL =
+        SqlStdOperatorTable.DEFAULT.createCall(SqlParserPos.ZERO);
+  }
+
   //~ Instance fields --------------------------------------------------------
 
   private final SqlValidator validator;
@@ -148,7 +157,7 @@ public class SqlCallBinding extends SqlOperatorBinding {
       while (list.size() < range.getMax()
           && checker.isOptional(list.size())
           && checker.isFixedParameters()) {
-        list.add(DEFAULT_CALL);
+        list.add(DefaultCallHolder.DEFAULT_CALL);
       }
       return list;
     }
@@ -201,7 +210,7 @@ public class SqlCallBinding extends SqlOperatorBinding {
             // with DEFAULT and then convert to nulls during sql-to-rel 
conversion.
             // Thus, there is no need to show the optional operands in the 
plan and
             // decide if the optional operand is null when code generation.
-            permuted.add(DEFAULT_CALL);
+            permuted.add(DefaultCallHolder.DEFAULT_CALL);
           }
         }
       }

Reply via email to