今天莫名其妙的出现问题,表现为部分数据造成服务端500错误,出现java.lang.ArrayIndexOutOfBoundsException异常。
第一反应是特殊字符,仔细检查果然如此。
UTF-8编码:C2A0
Unicode序号:00A0
Unicode字符:NO-BREAK SPACE
HTML实体编码:
低版本(<=1.1.39)的FastJSON在序列化时,会出现数组越界异常,升级为高版本(>=1.1.41)即可(为什么不是1.1.40版本?)。看来又被集团类库坑了(为什么要说“又”呢?)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package com.alibaba.fastjson.serializer; public final class SerializeWriter extends Writer { ... private void writeStringWithDoubleQuote(String text, final char seperator, boolean checkSpecial) { ... if (ch < CharTypes.specicalFlags_doubleQuotes.length && CharTypes.specicalFlags_doubleQuotes[ch] != 0 || (ch == '/' && isEnabled(SerializerFeature.WriteSlashAsSpecial))) { buf[bufIndex++] = ''; buf[bufIndex++] = replaceChars[(int) ch]; //replaceChars长度为128 end++; } else { buf[bufIndex++] = ch; } ... } ... } |
参考资料:
Unicode®字符百科
The Unicode Standard, Version 8.0
FastJSON序列化特殊字符BUG