From f2216ad108319fd45037c50e383cb6dc229675ba Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 22 Mar 2016 12:51:04 -0700 Subject: [PATCH] Issue #437 - Avoid NPE on receiving empty message though MessageHandler.Partial Minor updates to use features elsewhere in Jetty. --- .../jsr356/messages/BinaryPartialMessage.java | 2 +- .../websocket/jsr356/MessageReceivingTest.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/messages/BinaryPartialMessage.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/messages/BinaryPartialMessage.java index 7acb6807514..2dd077e5574 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/messages/BinaryPartialMessage.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/messages/BinaryPartialMessage.java @@ -51,7 +51,7 @@ public class BinaryPartialMessage implements MessageAppender // Supported Partial<> Type #1: ByteBuffer if (msgWrapper.isMessageType(ByteBuffer.class)) { - partialHandler.onMessage(payload==null?ByteBuffer.allocate(0): + partialHandler.onMessage(payload==null?BufferUtil.EMPTY_BUFFER: payload.slice(),isLast); return; } diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/MessageReceivingTest.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/MessageReceivingTest.java index 92676d2c06a..485ef0a4bf5 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/MessageReceivingTest.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/MessageReceivingTest.java @@ -18,12 +18,12 @@ package org.eclipse.jetty.websocket.jsr356; -import static org.hamcrest.Matchers.instanceOf; - import java.io.IOException; import java.net.URI; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; @@ -45,6 +45,8 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import static org.hamcrest.Matchers.instanceOf; + /** * This class tests receiving of messages by different types of {@link MessageHandler} */ @@ -57,11 +59,9 @@ public class MessageReceivingTest { private final String VERY_LONG_STRING; public MessageReceivingTest() { - final StringBuilder sb = new StringBuilder(); - for (int i = 0; i < 1024 * 1024; i++) { - sb.append(i & 1); - } - VERY_LONG_STRING = sb.toString(); + byte raw[] = new byte[1024 * 1024]; + Arrays.fill(raw, (byte)'x'); + VERY_LONG_STRING = new String(raw, StandardCharsets.UTF_8); } @BeforeClass