[ 
https://issues.apache.org/jira/browse/CALCITE-4393?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17229998#comment-17229998
 ] 

Ruben Q L commented on CALCITE-4393:
------------------------------------

{code:title=1) RexToLixTranslator.java}
/*90*/ public class RexToLixTranslator implements 
RexVisitor<RexToLixTranslator.Result> {
/*91*/  public static final Map<Method, SqlOperator> JAVA_TO_SQL_METHOD_MAP =
/*92*/      Util.mapOf(
/*93*/          findMethod(String.class, "toUpperCase"), 
SqlStdOperatorTable.UPPER,
// --> LOAD SqlStdOperatorTable
{code}

{code:title=2) SqlStdOperatorTable.java}
/*118*/  public static final SqlMultisetSetOperator MULTISET_UNION_DISTINCT =
/*119*/      new SqlMultisetSetOperator("MULTISET UNION DISTINCT", 14, false);
// --> LOAD SqlMultisetSetOperator
{code}

{code:title=3) SqlMultisetSetOperator.java}
/*42*/  public SqlMultisetSetOperator(String name, int prec, boolean all) {
/*43*/    super(
/*44*/        name,
/*45*/        SqlKind.OTHER,
/*46*/        prec,
/*47*/        true,
/*48*/        ReturnTypes.MULTISET_NULLABLE,
/*49*/        InferTypes.FIRST_KNOWN, // --> LOAD InferTypes
/*50*/        OperandTypes.MULTISET_MULTISET);
/*51*/    this.all = all;
/*52*/  }
{code}

{code:title=4) InferTypes.java}
/*41*/  public static final SqlOperandTypeInference FIRST_KNOWN =
/*42*/      (callBinding, returnType, operandTypes) -> {
/*43*/        final RelDataType unknownType =
/*44*/            callBinding.getValidator().getUnknownType();
/*45*/        RelDataType knownType = unknownType;
/*46*/        for (SqlNode operand : callBinding.operands()) {
/*47*/          knownType = SqlTypeUtil.deriveType(callBinding, operand);
/*48*/          if (!knownType.equals(unknownType)) {
/*49*/            break;
/*50*/          }
/*51*/        }
 // --> LOAD SqlCallBinding
{code}

{code:title=5) SqlCallBinding.java}
/*59*/  private static final SqlCall DEFAULT_CALL =
/*60*/      SqlStdOperatorTable.DEFAULT.createCall(SqlParserPos.ZERO);
// SqlStdOperatorTable is still loading in 2)! SqlStdOperatorTable.DEFAULT in 
SqlStdOperatorTable:185 is null => NPE!
{code}

> ExceptionInInitializerError due to NPE in SqlCallBinding caused by circular 
> dependency
> --------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4393
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4393
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Ruben Q L
>            Assignee: Ruben Q L
>            Priority: Major
>             Fix For: 1.27.0
>
>
> See discussion here: 
> https://lists.apache.org/thread.html/red0fc146f78a196af6fdaa5393b2c0906e0a49361a1734a850185777%40%3Cdev.calcite.apache.org%3E
> ExceptionInInitializerErroron WebSphere 9 (on Ubuntu) when trying to start an 
> application that uses Calcite (shaded) library. The exception message reads:
> {noformat}
>  **         error [-]: Unexpected error.
>  **               ...
>  **               Caused by: java.lang.BootstrapMethodError: 
> java.lang.ExceptionInInitializerError
>  **               
> com.onwbp.org.apache.calcite.sql.type.InferTypes.<clinit>(InferTypes.java:41)
>  **               
> com.onwbp.org.apache.calcite.sql.fun.SqlMultisetSetOperator.<init>(SqlMultisetSetOperator.java:43)
>  **               
> com.onwbp.org.apache.calcite.sql.fun.SqlStdOperatorTable.<clinit>(SqlStdOperatorTable.java:118)
>  **               
> com.onwbp.org.apache.calcite.adapter.enumerable.RexToLixTranslator.<clinit>(RexToLixTranslator.java:93)
>  **               java.lang.Class.forNameImpl(Native Method)
>  **               java.lang.Class.forName(Class.java:348)
>  **               
> java.lang.invoke.MethodType.nonPrimitiveClassFromString(MethodType.java:311)
>  **               
> java.lang.invoke.MethodType.parseIntoClasses(MethodType.java:373)
>  **               
> java.lang.invoke.MethodType.fromMethodDescriptorString(MethodType.java:286)
>  **               java.lang.invoke.MethodHandle.getCPMethodTypeAt(Native 
> Method)
>  **               
> java.lang.invoke.MethodHandle.resolveInvokeDynamic(MethodHandle.java:849)
>  **               ... 74 more
>  **               Caused by: java.lang.ExceptionInInitializerError
>  **               java.lang.J9VMInternals.ensureError(J9VMInternals.java:141)
>  **               
> java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:130)
>  **               java.lang.Class.forNameImpl(Native Method)
>  **               java.lang.Class.forName(Class.java:348)
>  **               
> java.lang.invoke.MethodType.nonPrimitiveClassFromString(MethodType.java:311)
>  **               
> java.lang.invoke.MethodType.parseIntoClasses(MethodType.java:373)
>  **               
> java.lang.invoke.MethodType.fromMethodDescriptorString(MethodType.java:286)
>  **               java.lang.invoke.MethodHandle.getCPMethodTypeAt(Native 
> Method)
>  **               
> java.lang.invoke.MethodHandle.resolveInvokeDynamic(MethodHandle.java:849)
>  **               ... 85 more
>  **               Caused by: java.lang.NullPointerException
>  **               
> com.onwbp.org.apache.calcite.sql.SqlCallBinding.<clinit>(SqlCallBinding.java:60)
>  **               ... 92 more
>  ****** 1 errors, 5 infos. 
> {noformat}
> As we can see there is a NPE in 
> [SqlCallBinding:60|https://github.com/apache/calcite/blob/2e9edae7fc57ab9c9c7c097008724ac99a1791a3/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java#L60],
>  when it tries to call a method on {{SqlStdOperatorTable.DEFAULT}}, which 
> seems to be null.
> According to the logs, what I think is happening is a circular dependency 
> issue when classes get loaded (more details in first comment).
> However, so far I have only seen this error in WebSphere, in other 
> environments the same application is correctly initialized and launched, and 
> this exception does not happen.
> Since WebSphere uses IBM's own JVM, my hypothesis is that its class loader 
> follows a different (and unlucky) order to load Calcite classes.
> So far I have not been able to reproduce the issue with a unit test, neither 
> on [Github CI|https://github.com/apache/calcite/pull/2251], nor in a local 
> environment.



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

Reply via email to