TakahikoKawasaki / nv-websocket-client

High-quality WebSocket client implementation in Java.
Apache License 2.0
2.03k stars 292 forks source link

ClassCastException: int[] cannot be cast to java.lang.String[] #167

Closed maxbaldrighi closed 5 years ago

maxbaldrighi commented 6 years ago

I'm implementing your wonderful library in my Android app.

I received this crash only for one device and for one user, but it happened 17 times before that user probably decided to uninstall the app. Since all the other devices and users are not affected I don't expect you to do anything, but I thought it was best letting you know.

Device: LINGMI M15 OS: Android 4.4.2 - API 19

I received the following stacktrace: Fatal Exception: java.lang.ClassCastException: int[] cannot be cast to java.lang.String[] at com.neovisionaries.ws.client.HandshakeBuilder.build(HandshakeBuilder.java:487) at com.neovisionaries.ws.client.WebSocket.writeHandshake(WebSocket.java:3218) at com.neovisionaries.ws.client.WebSocket.shakeHands(WebSocket.java:3120) at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2155) at com.neovisionaries.ws.client.ConnectThread.runMain(ConnectThread.java:32) at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)

MinnDevelopment commented 6 years ago

What version of this library are you using to receive this stack-trace?

maxbaldrighi commented 6 years ago

Oh, I'm sorry, I forgot to include it: 2.4

TakahikoKawasaki commented 5 years ago

@maxbaldrighi Hmm. I don't understand how the error can happen. The 487th line is for (String[] header : headers) in the following code. How can elements of headers be int[]?

    public static String build(String requestLine, List<String[]> headers)
    {
        StringBuilder builder = new StringBuilder();

        // Append the request line, "GET {path} HTTP/1.1".
        builder.append(requestLine).append(RN);

        // For each header.
        for (String[] header : headers)
        {
            // Append the header, "{name}: {value}".
            builder.append(header[0]).append(": ").append(header[1]).append(RN);
        }

        // Append an empty line.
        builder.append(RN);

        return builder.toString();
    }

If the error occurs on only one device and for one user, probably the virtual machine on the device is broken or compromised.