Search in sources :

Example 1 with BLangNullReferenceException

use of org.ballerinalang.util.exceptions.BLangNullReferenceException in project ballerina by ballerina-lang.

the class ParseHeader method execute.

@Override
public void execute(Context context) {
    String errMsg;
    try {
        String headerValue = context.getStringArgument(0);
        if (headerValue.contains(COMMA)) {
            headerValue = headerValue.substring(0, headerValue.indexOf(COMMA));
        }
        // Set value and param map
        String value = headerValue.trim();
        if (headerValue.contains(SEMICOLON)) {
            value = HeaderUtil.getHeaderValue(value);
        }
        BRefValueArray contentTuple = new BRefValueArray(parseHeaderTupleType);
        contentTuple.add(0, new BString(value));
        contentTuple.add(1, HeaderUtil.getParamMap(headerValue));
        context.setReturnValues(contentTuple);
        return;
    } catch (BLangNullReferenceException ex) {
        errMsg = PARSER_ERROR + "header value cannot be null";
    } catch (BallerinaException ex) {
        errMsg = PARSER_ERROR + ex.getMessage();
    }
    // set parse error
    context.setReturnValues(MimeUtil.getParserError(context, errMsg));
}
Also used : BString(org.ballerinalang.model.values.BString) BLangNullReferenceException(org.ballerinalang.util.exceptions.BLangNullReferenceException) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BString(org.ballerinalang.model.values.BString) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 2 with BLangNullReferenceException

use of org.ballerinalang.util.exceptions.BLangNullReferenceException in project ballerina by ballerina-lang.

the class BLangFunctions method invokeNativeCallable.

private static WorkerExecutionContext invokeNativeCallable(CallableUnitInfo callableUnitInfo, WorkerExecutionContext parentCtx, int[] argRegs, int[] retRegs, int flags) {
    WorkerData parentLocalData = parentCtx.workerLocal;
    BType[] retTypes = callableUnitInfo.getRetParamTypes();
    WorkerData caleeSF = BLangVMUtils.createWorkerDataForLocal(callableUnitInfo.getDefaultWorkerInfo(), parentCtx, argRegs, callableUnitInfo.getParamTypes());
    Context ctx = new NativeCallContext(parentCtx, callableUnitInfo, caleeSF);
    NativeCallableUnit nativeCallable = callableUnitInfo.getNativeCallableUnit();
    if (nativeCallable == null) {
        return parentCtx;
    }
    try {
        if (nativeCallable.isBlocking()) {
            nativeCallable.execute(ctx, null);
            BLangVMUtils.populateWorkerDataWithValues(parentLocalData, retRegs, ctx.getReturnValues(), retTypes);
            if (TraceManagerWrapper.getInstance().isTraceEnabled() && FunctionFlags.isObserved(flags)) {
                TraceUtil.finishTraceSpan(TraceUtil.getTracer(parentCtx));
            }
            /* we want the parent to continue, since we got the response of the native call already */
            return parentCtx;
        } else {
            CallableUnitCallback callback;
            if (TraceManagerWrapper.getInstance().isTraceEnabled() && FunctionFlags.isObserved(flags)) {
                callback = new TraceableCallbackWrapper(parentCtx, new BLangCallableUnitCallback(ctx, parentCtx, retRegs, retTypes));
            } else {
                callback = new BLangCallableUnitCallback(ctx, parentCtx, retRegs, retTypes);
            }
            nativeCallable.execute(ctx, callback);
            /* we want the parent to suspend (i.e. go to wait for response state) and stay until notified */
            return null;
        }
    } catch (BLangNullReferenceException e) {
        return BLangVMUtils.handleNativeInvocationError(parentCtx, BLangVMErrors.createNullRefException(callableUnitInfo));
    } catch (Throwable e) {
        return BLangVMUtils.handleNativeInvocationError(parentCtx, BLangVMErrors.createError(callableUnitInfo, e.getMessage()));
    }
}
Also used : InitWorkerResponseContext(org.ballerinalang.bre.bvm.InitWorkerResponseContext) SyncCallableWorkerResponseContext(org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext) NativeCallContext(org.ballerinalang.bre.NativeCallContext) ForkJoinWorkerResponseContext(org.ballerinalang.bre.bvm.ForkJoinWorkerResponseContext) WorkerResponseContext(org.ballerinalang.bre.bvm.WorkerResponseContext) Context(org.ballerinalang.bre.Context) CallableWorkerResponseContext(org.ballerinalang.bre.bvm.CallableWorkerResponseContext) WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) AsyncInvocableWorkerResponseContext(org.ballerinalang.bre.bvm.AsyncInvocableWorkerResponseContext) BLangCallableUnitCallback(org.ballerinalang.bre.BLangCallableUnitCallback) BType(org.ballerinalang.model.types.BType) TraceableCallbackWrapper(org.ballerinalang.util.tracer.TraceableCallbackWrapper) BLangNullReferenceException(org.ballerinalang.util.exceptions.BLangNullReferenceException) NativeCallContext(org.ballerinalang.bre.NativeCallContext) NativeCallableUnit(org.ballerinalang.model.NativeCallableUnit) WorkerData(org.ballerinalang.bre.bvm.WorkerData) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback) BLangCallableUnitCallback(org.ballerinalang.bre.BLangCallableUnitCallback)

Aggregations

BLangNullReferenceException (org.ballerinalang.util.exceptions.BLangNullReferenceException)2 BLangCallableUnitCallback (org.ballerinalang.bre.BLangCallableUnitCallback)1 Context (org.ballerinalang.bre.Context)1 NativeCallContext (org.ballerinalang.bre.NativeCallContext)1 AsyncInvocableWorkerResponseContext (org.ballerinalang.bre.bvm.AsyncInvocableWorkerResponseContext)1 CallableUnitCallback (org.ballerinalang.bre.bvm.CallableUnitCallback)1 CallableWorkerResponseContext (org.ballerinalang.bre.bvm.CallableWorkerResponseContext)1 ForkJoinWorkerResponseContext (org.ballerinalang.bre.bvm.ForkJoinWorkerResponseContext)1 InitWorkerResponseContext (org.ballerinalang.bre.bvm.InitWorkerResponseContext)1 SyncCallableWorkerResponseContext (org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext)1 WorkerData (org.ballerinalang.bre.bvm.WorkerData)1 WorkerExecutionContext (org.ballerinalang.bre.bvm.WorkerExecutionContext)1 WorkerResponseContext (org.ballerinalang.bre.bvm.WorkerResponseContext)1 NativeCallableUnit (org.ballerinalang.model.NativeCallableUnit)1 BType (org.ballerinalang.model.types.BType)1 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)1 BString (org.ballerinalang.model.values.BString)1 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)1 TraceableCallbackWrapper (org.ballerinalang.util.tracer.TraceableCallbackWrapper)1