Skip to content

java.lang.NegativeArraySizeException #26

Description

@marll

Hi,
in the server/client application the server send 49678 byte (the error also occurs with smaller sizes )
In the client application:
java.lang.NegativeArraySizeException: -15858
at com.simplenet.utility.exposed.data.StringReader.lambda$processBytes$4(StringReader.java:169)
at com.simplenet.utility.exposed.data.DataReader.lambda$read$0(DataReader.java:76)
at com.simplenet.Client.lambda$readUntil$4(Client.java:529)
at com.simplenet.Client$Listener.completed(Client.java:137)
at com.simplenet.Client$Listener.completed(Client.java:83)
at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:127)
at java.base/sun.nio.ch.Invoker$2.run(Invoker.java:219)
at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:831)

Following the function in error:
private void processBytes(short n, Consumer consumer, Charset charset, ByteOrder order) {
int length = order == ByteOrder.LITTLE_ENDIAN ? Short.reverseBytes(n) : n;

    read(Byte.BYTES * (length & 0xFFFF), buffer -> {
        var b = new byte[length];
        buffer.get(b);
        consumer.accept(new String(b, charset));
    }, order);
}

Which is the problem?
Many Thanks

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