Constructing a FastByteArrayInputStream
from a byte array without specifying the length to create a JSON parser could cause deserialization problem. Specify the length of the byte array to avoid the issue.
1 public void createJsonParserNoncompliant(Text text) throws IOException {
2 // Noncompliant: length of input byte array not specified.
3 new JsonFactory().createJsonParser(new FastByteArrayInputStream(text.getBytes()));
4 }
1public void createJsonParserCompliant(Text text) throws IOException {
2 // Compliant: length of input byte array specified.
3 new JsonFactory().createJsonParser(new FastByteArrayInputStream(text.getBytes(), text.getLength()));
4}