From 95b762049fa1690d03c0ae5483ba40d6702c8ee9 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 7 Jan 2021 10:36:06 -0800 Subject: [PATCH] Some more lgtm.com fixes/work-arounds --- .../dataformat/avro/deser/JacksonAvroParserImpl.java | 1 + .../dataformat/avro/schema/AvroSchemaHelper.java | 12 +++++++----- .../dataformat/protobuf/ProtobufGenerator.java | 2 ++ .../jackson/dataformat/protobuf/ProtobufParser.java | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/JacksonAvroParserImpl.java b/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/JacksonAvroParserImpl.java index c64218316..688a2f329 100644 --- a/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/JacksonAvroParserImpl.java +++ b/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/JacksonAvroParserImpl.java @@ -1099,6 +1099,7 @@ protected final void _loadToHaveAtLeast(int minAvailable) throws IOException // No input stream, no leading (either we are closed, or have non-stream input source) if (_inputStream == null) { _reportError("Needed to read %d bytes, reached end-of-input", minAvailable); + return; // never gets here, but sec tools complain without } while (_inputEnd < minAvailable) { int count = _inputStream.read(_inputBuffer, _inputEnd, _inputBuffer.length - _inputEnd); diff --git a/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/AvroSchemaHelper.java b/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/AvroSchemaHelper.java index 9c509647a..6424551bf 100644 --- a/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/AvroSchemaHelper.java +++ b/avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/AvroSchemaHelper.java @@ -151,11 +151,13 @@ public static Schema simpleSchema(JsonFormatTypes type, JavaType hint) return Schema.create(Schema.Type.NULL); case NUMBER: // 16-Feb-2017, tatu: Fixed as suggested by `baharclerode@github` - if (hint.hasRawClass(float.class)) { - return Schema.create(Schema.Type.FLOAT); - } - if (hint.hasRawClass(long.class)) { - return Schema.create(Schema.Type.LONG); + if (hint != null) { + if (hint.hasRawClass(float.class)) { + return Schema.create(Schema.Type.FLOAT); + } + if (hint.hasRawClass(long.class)) { + return Schema.create(Schema.Type.LONG); + } } return Schema.create(Schema.Type.DOUBLE); case STRING: diff --git a/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufGenerator.java b/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufGenerator.java index bfa6491c9..b64faab92 100644 --- a/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufGenerator.java +++ b/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufGenerator.java @@ -394,6 +394,7 @@ public final void writeStartArray() throws IOException } if (_currField == null) { // just a sanity check _reportError("Can not write START_ARRAY without field (message type "+_currMessage.getName()+")"); + return; // never gets here but code analyzers can't see that } if (!_currField.isArray()) { _reportError("Can not write START_ARRAY: field '"+_currField.name+"' not declared as 'repeated'"); @@ -568,6 +569,7 @@ private void _verifyArrayWrite(Object array) throws IOException } if (_currField == null) { // inlined _verifyValueWrite _reportError("Can not write START_ARRAY without field (message type "+_currMessage.getName()+")"); + return; // never gets here but need to help code analyzers } if (!_currField.isArray()) { _reportError("Can not write START_ARRAY: field '"+_currField.name+"' not declared as 'repeated'"); 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 b1739131f..949e2b0e6 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 @@ -545,6 +545,7 @@ public JsonToken nextToken() throws IOException case STATE_INITIAL: if (_schema == null) { _reportError("No Schema has been assigned: can not decode content"); + return null; // never gets here but needed for code analyzers benefit } _currentMessage = _schema.getRootType(); _currentField = _currentMessage.firstField();