Skip to content

NullPointerException when a Null CalValue is returned from a foreign function. #3

@rdwebster

Description

@rdwebster

In certain situations, a NullPointerException will be generated in the CAL runtime code when a foreign function returns a Null value for a CalValue result.
My code was attempting to test for the null value, but the exception seems to happen before it gets to this.

This seems to happen in more cases with the 'debug_capable' option turned on.

The following code demonstrates the problem:

nullTest :: Maybe String;
public nullTest = 
    let
        val :: CalValue;
        val = eager nullCalValue;
    in
        if isNullCalValue val then Nothing
        else Just $ unsafeFromCalValue val;

Running this code in ICE with the org.openquark.cal.machine.debug_capable option on will result in a NullPointerException.
If the 'eager' function is removed, then the problem happens when the debug_capable option is on or off.

The call stack for the error:
java.lang.NullPointerException
at org.openquark.cal.internal.runtime.lecc.RTResultFunction.setResult(RTResultFunction.java:63)
at org.openquark.cal.internal.runtime.lecc.RTFullApp$General$_0.reduce(RTFullApp.java:225)
at org.openquark.cal.internal.runtime.lecc.RTResultFunction.unsynchronizedEvaluate(RTResultFunction.java:136)
at org.openquark.cal.internal.runtime.lecc.RTResultFunction.evaluate(RTResultFunction.java:103)
at org.openquark.cal_RichSandbox_NullLookupBugTest.Null_Test.val$1$def_Strict(Null_Test.java)
at org.openquark.cal_RichSandbox_NullLookupBugTest.Null_Test.f(Null_Test.java)
at org.openquark.cal.internal.runtime.lecc.RTFullApp$General$_0.reduce(RTFullApp.java:225)
at org.openquark.cal.internal.runtime.lecc.RTResultFunction.unsynchronizedEvaluate(RTResultFunction.java:136)
at org.openquark.cal.internal.runtime.lecc.RTResultFunction.evaluate(RTResultFunction.java:103)
at org.openquark.cal_RichSandbox_NullLookupBugTest.Io__iceruntarget__0__0.f(Io__iceruntarget__0__0.java)
at org.openquark.cal.internal.runtime.lecc.RTFullApp$General$_0.reduce(RTFullApp.java:225)
at org.openquark.cal.internal.runtime.lecc.RTResultFunction.unsynchronizedEvaluate(RTResultFunction.java:136)
at org.openquark.cal.internal.runtime.lecc.RTResultFunction.evaluate(RTResultFunction.java:103)
at org.openquark.cal_Cal_Core_Prelude.Id.f(Id.java)
at org.openquark.cal.internal.runtime.lecc.RTApplication.reduce(RTApplication.java:156)
at org.openquark.cal.internal.runtime.lecc.RTResultFunction.unsynchronizedEvaluate(RTResultFunction.java:136)
at org.openquark.cal.internal.runtime.lecc.RTResultFunction.evaluate(RTResultFunction.java:103)
at org.openquark.cal.internal.machine.lecc.Executor.exec(Executor.java:173)
at org.openquark.cal.ICE$FunctionRunThread.run(ICE.java:7226)
at java.lang.Thread.run(Thread.java:637)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions