ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

WebSocket `remote` function throws runtime error when returning `array` #6611

Open hasathcharu opened 5 months ago

hasathcharu commented 5 months ago

Description: The remote function in a websocket:Service class which returns an array type throws the following error and does not return the array to the console.

[2024-06-05 13:52:41,770] SEVERE {b7a.log.crash} - null 
java.lang.NullPointerException
        at java.base/java.lang.System.arraycopy(Native Method)
        at io.ballerina.runtime.internal.values.ArrayValueImpl.getBytes(ArrayValueImpl.java:990)
        at io.ballerina.stdlib.websocket.WebSocketResourceCallback.sendBinaryMessage(WebSocketResourceCallback.java:125)
        at io.ballerina.stdlib.websocket.WebSocketResourceCallback.notifySuccess(WebSocketResourceCallback.java:81)
        at io.ballerina.runtime.internal.scheduling.Scheduler.postProcess(Scheduler.java:387)
        at io.ballerina.runtime.internal.scheduling.Scheduler.run(Scheduler.java:336)
        at io.ballerina.runtime.internal.scheduling.Scheduler.runSafely(Scheduler.java:287)
        at java.base/java.lang.Thread.run(Thread.java:833)

Steps to reproduce:

public type Info record {|
    string event;
|};
service class WsServiceUser {
    *websocket:Service;
    remote function onArray(Info info) returns int[] {
        int[] arr = [1,3,5,6,7];
        return arr;
    }
}
websocat ws://localhost:9092/user
{"event":"array"}

Affected Versions: Ballerina Swan Lake Update 09

OS, DB, other environment details and versions: OS: Ubuntu 22.04.4 LTS Websocat: 1.13.0

Related Issues: https://github.com/ballerina-platform/ballerina-library/issues/4290