URLDecoder: Illegal hex characters in escape (%) pattern

原因:后台发布文章的时候,内容里面有%,导致后台URLDecoder.decode()转码的时候报错。

看了java.net.URLDecoderdecode()的源码,原来是转码错误。

贴出部分代码,意思是取%后面的两位,从16进制转成10进制,要是转码错误就会报出这个异常。

while ( ((i+2) < numChars) && (c=='%')) {
    int v = Integer.parseInt(s.substring(i+1,i+3),16);
    if (v < 0)
        throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - negative value");
    bytes[pos++] = (byte) v;
    i+= 3;
    if (i < numChars)
    c = s.charAt(i);
}
原文地址:https://www.cnblogs.com/jarjune/p/8343022.html