From a5cdb5bb5c1f5c69fb4f62f0f89b27dd2ac0b14d Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 5 Jan 2021 13:43:25 -0800 Subject: [PATCH] Couple more lgtm.com fixes (including revising one earlier unsuccessful fix) --- release-notes/VERSION | 1 + .../com/fasterxml/aalto/in/Utf8Scanner.java | 28 +++++++++---------- .../aalto/stax/OutputFactoryImpl.java | 26 ++++++++--------- .../com/fasterxml/aalto/util/TextBuilder.java | 5 ++-- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/release-notes/VERSION b/release-notes/VERSION index 1d9828b..2a46d45 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -7,6 +7,7 @@ Project: aalto-xml 1.2.3 (not yet released) * Fix minor offset check bug in `AsyncByteArrayScanner`/`AsyncByteBufferScanner` +* Various minor fixes based on lgtm.com suggestions 1.2.2 (14-Sep-2019) diff --git a/src/main/java/com/fasterxml/aalto/in/Utf8Scanner.java b/src/main/java/com/fasterxml/aalto/in/Utf8Scanner.java index 3e71fd4..0e8b465 100644 --- a/src/main/java/com/fasterxml/aalto/in/Utf8Scanner.java +++ b/src/main/java/com/fasterxml/aalto/in/Utf8Scanner.java @@ -440,22 +440,20 @@ private void handleNsDeclaration(PName name, byte quoteByte) ++_inputPtr; } markLF(); - } else { - if (c > 0x7F) { - c = decodeMultiByteChar(c, _inputPtr); - if (c < 0) { // surrogate pair - c = -c; - // Let's add first part right away: - if (attrPtr >= attrBuffer.length) { - _nameBuffer = attrBuffer = DataUtil.growArrayBy(attrBuffer, attrBuffer.length); - } - c -= 0x10000; - attrBuffer[attrPtr++] = (char) (0xD800 | (c >> 10)); - c = 0xDC00 | (c & 0x3FF); - } - } else if (c != INT_TAB) { - throwInvalidSpace(c); + } else if (c != INT_TAB) { + throwInvalidSpace(c); + } + } else if (c > 0x7F) { + c = decodeMultiByteChar(c, _inputPtr); + if (c < 0) { // surrogate pair + c = -c; + // Let's add first part right away: + if (attrPtr >= attrBuffer.length) { + _nameBuffer = attrBuffer = DataUtil.growArrayBy(attrBuffer, attrBuffer.length); } + c -= 0x10000; + attrBuffer[attrPtr++] = (char) (0xD800 | (c >> 10)); + c = 0xDC00 | (c & 0x3FF); } } } diff --git a/src/main/java/com/fasterxml/aalto/stax/OutputFactoryImpl.java b/src/main/java/com/fasterxml/aalto/stax/OutputFactoryImpl.java index d342a1f..f39c4a7 100644 --- a/src/main/java/com/fasterxml/aalto/stax/OutputFactoryImpl.java +++ b/src/main/java/com/fasterxml/aalto/stax/OutputFactoryImpl.java @@ -188,21 +188,18 @@ public void configureForSpeed() /********************************************************************** */ - /** - * Bottleneck factory method used internally; needs to take care of passing - * proper settings to stream writer. - * - * @param autoCloseOutput Whether writer should automatically close the - * output stream or Writer, when close() is called on stream writer. - */ + // Bottleneck factory method used internally; needs to take care of passing + // proper settings to stream writer. + // + // @param forceAutoClose Whether writer should automatically close the + // output stream or Writer, when close() is called on stream writer. private XMLStreamWriter2 createSW(OutputStream out, Writer w, String enc, - boolean forceAutoClose) + boolean forceAutoClose) throws XMLStreamException { - /* Need to ensure that the configuration object is not shared - * any more; otherwise later changes via factory could be - * visible half-way through output... - */ + // Need to ensure that the configuration object is not shared + // any more; otherwise later changes via factory could be + // visible half-way through output... WriterConfig cfg = _config.createNonShared(); if (forceAutoClose) { cfg.doAutoCloseOutput(true); @@ -214,9 +211,8 @@ private XMLStreamWriter2 createSW(OutputStream out, Writer w, String enc, if (enc == null) { enc = XmlConsts.STAX_DEFAULT_OUTPUT_ENCODING; } else { - /* Canonical ones are interned, so we may have - * normalized encoding already... - */ + // Canonical ones are interned, so we may have + // normalized encoding already... if (enc != CharsetNames.CS_UTF8 && enc != CharsetNames.CS_ISO_LATIN1 && enc != CharsetNames.CS_US_ASCII) { diff --git a/src/main/java/com/fasterxml/aalto/util/TextBuilder.java b/src/main/java/com/fasterxml/aalto/util/TextBuilder.java index ae003bd..fdf2f55 100644 --- a/src/main/java/com/fasterxml/aalto/util/TextBuilder.java +++ b/src/main/java/com/fasterxml/aalto/util/TextBuilder.java @@ -459,13 +459,12 @@ public boolean isAllWhitespace() return true; } - /** + /* * Method that can be used to check if the contents of the buffer end * in specified String. * * @return True if the textual content buffer contains ends with the * specified String; false otherwise - */ public boolean endsWith(String str) { int segIndex = (_segments == null) ? 0 : _segments.size(); @@ -488,9 +487,9 @@ public boolean endsWith(String str) bufIndex = buf.length-1; } } - return true; } + */ /** * Note: it is assumed that this method is not used often enough to