From b39cc4d55e57e1fe028b95b2d878ee4dbabbdd91 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sat, 16 Jan 2010 15:23:55 +0000 Subject: [PATCH] [FIXED HUDSON-5155] in 1.342. The root cause of the problem is that the backing byte[] of ByteBuffer can be bigger than the actual current content that's on it --- in the case of the reporter he got byte[3] as the backing buffer when only two bytes of it is in use. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@25962 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/Util.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index c465de1403..bf397369ee 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -64,6 +64,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.CharsetEncoder; @@ -745,7 +746,9 @@ public class Util { buf.put(0,c); buf.rewind(); try { - for (byte b : enc.encode(buf).array()) { + ByteBuffer bytes = enc.encode(buf); + while (bytes.hasRemaining()) { + byte b = bytes.get(); out.append('%'); out.append(toDigit((b >> 4) & 0xF)); out.append(toDigit(b & 0xF));