Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NegativeArraySizeException #26

Open
marll opened this issue Jul 2, 2021 · 0 comments
Open

java.lang.NegativeArraySizeException #26

marll opened this issue Jul 2, 2021 · 0 comments

Comments

@marll
Copy link

marll commented Jul 2, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant