Skip to content

Commit fbe6982

Browse files
committed
[CALCITE-4393] ExceptionInInitializerError due to NPE in SqlCallBinding caused by circular dependency
1 parent 99251a5 commit fbe6982

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,17 @@
5656
* analyzing to the operands of a {@link SqlCall} with a {@link SqlValidator}.
5757
*/
5858
public class SqlCallBinding extends SqlOperatorBinding {
59-
private static final SqlCall DEFAULT_CALL =
60-
SqlStdOperatorTable.DEFAULT.createCall(SqlParserPos.ZERO);
59+
60+
/** Static nested class required due to
61+
* <a href="https://issues.apache.org/jira/browse/CALCITE-4393">[CALCITE-4393]
62+
* ExceptionInInitializerError due to NPE in SqlCallBinding caused by circular dependency</a>.
63+
* The static field inside it cannot be part of the outer class: it must be defined
64+
* within a nested class in order to break the cycle during class loading. */
65+
private static class DefaultCallHolder {
66+
private static final SqlCall DEFAULT_CALL =
67+
SqlStdOperatorTable.DEFAULT.createCall(SqlParserPos.ZERO);
68+
}
69+
6170
//~ Instance fields --------------------------------------------------------
6271

6372
private final SqlValidator validator;
@@ -148,7 +157,7 @@ public List<SqlNode> operands() {
148157
while (list.size() < range.getMax()
149158
&& checker.isOptional(list.size())
150159
&& checker.isFixedParameters()) {
151-
list.add(DEFAULT_CALL);
160+
list.add(DefaultCallHolder.DEFAULT_CALL);
152161
}
153162
return list;
154163
}
@@ -201,7 +210,7 @@ private List<SqlNode> permutedOperands(final SqlCall call) {
201210
// with DEFAULT and then convert to nulls during sql-to-rel conversion.
202211
// Thus, there is no need to show the optional operands in the plan and
203212
// decide if the optional operand is null when code generation.
204-
permuted.add(DEFAULT_CALL);
213+
permuted.add(DefaultCallHolder.DEFAULT_CALL);
205214
}
206215
}
207216
}

0 commit comments

Comments
 (0)