diff --git a/core/src/main/java/io/undertow/protocols/ajp/AjpResponseParser.java b/core/src/main/java/io/undertow/protocols/ajp/AjpResponseParser.java index 9c7d654712..7619c0fd0a 100644 --- a/core/src/main/java/io/undertow/protocols/ajp/AjpResponseParser.java +++ b/core/src/main/java/io/undertow/protocols/ajp/AjpResponseParser.java @@ -224,11 +224,6 @@ public int getReadBodyChunkSize() { */ public int stringLength = -1; - /** - * The current string being read - */ - public StringBuilder currentString; - /** * when reading the first byte of an integer this stores the first value. It is set to -1 to signify that * the first byte has not been read yet. @@ -248,7 +243,6 @@ public void reset() { reasonPhrase = null; headers = new HeaderMap(); stringLength = -1; - currentString = null; currentIntegerPart = -1; readHeaders = 0; } @@ -300,12 +294,8 @@ protected StringHolder parseString(ByteBuffer buf, boolean header) { this.stringLength = -1; return new StringHolder(null, true, false); } - StringBuilder builder = this.currentString; + final StringBuilder builder = new StringBuilder(); - if (builder == null) { - builder = new StringBuilder(); - this.currentString = builder; - } int length = builder.length(); while (length < stringLength) { if (!buf.hasRemaining()) { @@ -323,7 +313,6 @@ protected StringHolder parseString(ByteBuffer buf, boolean header) { if (buf.hasRemaining()) { buf.get(); //null terminator - this.currentString = null; this.stringLength = -1; this.containsUrlCharacters = false; return new StringHolder(builder.toString(), true, containsUrlCharacters); diff --git a/core/src/main/java/io/undertow/protocols/http2/HpackDecoder.java b/core/src/main/java/io/undertow/protocols/http2/HpackDecoder.java index 3c1da0bee1..ce5ec6fd01 100644 --- a/core/src/main/java/io/undertow/protocols/http2/HpackDecoder.java +++ b/core/src/main/java/io/undertow/protocols/http2/HpackDecoder.java @@ -73,8 +73,6 @@ public class HpackDecoder { private boolean first = true; - private final StringBuilder stringBuilder = new StringBuilder(); - public HpackDecoder(int maxAllowedMemorySize) { this.specifiedMemorySize = Math.min(Hpack.DEFAULT_TABLE_SIZE, maxAllowedMemorySize); this.maxAllowedMemorySize = maxAllowedMemorySize; @@ -247,11 +245,11 @@ private String readHpackString(ByteBuffer buffer) throws HpackException { if (huffman) { return readHuffmanString(length, buffer); } + StringBuilder stringBuilder = new StringBuilder(length); for (int i = 0; i < length; ++i) { stringBuilder.append((char) (buffer.get() & 0xFF)); } String ret = stringBuilder.toString(); - stringBuilder.setLength(0); if (ret.isEmpty()) { //return the interned empty string, rather than allocating a new one each time return ""; @@ -260,12 +258,12 @@ private String readHpackString(ByteBuffer buffer) throws HpackException { } private String readHuffmanString(int length, ByteBuffer buffer) throws HpackException { + StringBuilder stringBuilder = new StringBuilder(length); HPackHuffman.decode(buffer, length, stringBuilder); String ret = stringBuilder.toString(); if (ret.isEmpty()) { return ""; } - stringBuilder.setLength(0); return ret; }