diff --git a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java index f9963b0d4..f6299c4c6 100644 --- a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java +++ b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java @@ -1679,7 +1679,10 @@ public int getTextLength() throws IOException || (_currToken == JsonToken.VALUE_NUMBER_FLOAT)) { return getNumberValue().toString().length(); } - return _currToken.asCharArray().length; + final char[] ch = _currToken.asCharArray(); + if (ch != null) { + return ch.length; + } } return 0; } diff --git a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java index 494c757af..9e11b2d12 100644 --- a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java +++ b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java @@ -314,7 +314,8 @@ public char[] getTextCharacters() throws IOException { @Override public int getTextLength() throws IOException { - return getText().length(); + String str = getText(); + return (str == null) ? 0 : str.length(); } @Override diff --git a/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufParser.java b/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufParser.java index 229491939..01c6ae98b 100644 --- a/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufParser.java +++ b/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufParser.java @@ -1373,13 +1373,15 @@ public int getTextLength() throws IOException return _textBuffer.size(); case FIELD_NAME: return _parsingContext.getCurrentName().length(); - // fall through case VALUE_NUMBER_INT: case VALUE_NUMBER_FLOAT: return getNumberValue().toString().length(); - default: - return _currToken.asCharArray().length; + // fall through + } + final char[] ch = _currToken.asCharArray(); + if (ch != null) { + return ch.length; } } return 0; diff --git a/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java b/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java index d85ab72b3..c27ce3602 100644 --- a/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java +++ b/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java @@ -1139,7 +1139,10 @@ public int getTextLength() throws IOException // TODO: optimize return getNumberValue().toString().length(); } - return _currToken.asCharArray().length; + final char[] ch = _currToken.asCharArray(); + if (ch != null) { + return ch.length; + } } return 0; } diff --git a/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/async/NonBlockingParserBase.java b/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/async/NonBlockingParserBase.java index 8753d5ce4..4d06d200a 100644 --- a/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/async/NonBlockingParserBase.java +++ b/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/async/NonBlockingParserBase.java @@ -328,7 +328,11 @@ public int getTextLength() throws IOException case JsonTokenId.ID_NOT_AVAILABLE: return 0; // or throw exception? default: - return _currToken.asCharArray().length; + final char[] ch = _currToken.asCharArray(); + if (ch != null) { + return ch.length; + } + return 0; } }