From dc28a487d6365c3afc9023fb80b42e118301dd63 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sat, 25 May 2024 19:50:06 +0800 Subject: [PATCH] Fix code inspections for db-protocol modules --- .../value/decimal/MySQLDecimalBinlogProtocolValue.java | 7 +++++-- .../row/column/value/string/MySQLJsonValueDecoder.java | 4 +++- .../packet/handshake/MySQLAuthSwitchRequestPacket.java | 3 +-- .../row/column/value/string/MySQLJsonValueDecoderTest.java | 3 ++- .../command/admin/PostgreSQLUnsupportedCommandPacket.java | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/decimal/MySQLDecimalBinlogProtocolValue.java b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/decimal/MySQLDecimalBinlogProtocolValue.java index 55055dd28f51e..a785390c80fce 100644 --- a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/decimal/MySQLDecimalBinlogProtocolValue.java +++ b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/decimal/MySQLDecimalBinlogProtocolValue.java @@ -61,9 +61,10 @@ private static BigDecimal toDecimal(final DecimalMetaData metaData, final byte[] private static BigDecimal decodeIntegerValue(final DecimalMetaData metaData, final byte[] value) { int offset = DIG_TO_BYTES[metaData.getExtraIntegerSize()]; BigDecimal result = offset > 0 ? BigDecimal.valueOf(readFixedLengthIntBE(value, 0, offset)) : BigDecimal.ZERO; - for (; offset < metaData.getIntegerByteLength(); offset += DEC_BYTE_SIZE) { + while (offset < metaData.getIntegerByteLength()) { int i = readFixedLengthIntBE(value, offset, DEC_BYTE_SIZE); result = result.movePointRight(DIG_PER_DEC).add(BigDecimal.valueOf(i)); + offset += DEC_BYTE_SIZE; } return result; } @@ -73,8 +74,10 @@ private static BigDecimal decodeScaleValue(final DecimalMetaData metaData, final int shift = 0; int offset = metaData.getIntegerByteLength(); int scale = metaData.getScale(); - for (; shift + DIG_PER_DEC <= scale; shift += DIG_PER_DEC, offset += DEC_BYTE_SIZE) { + while (shift + DIG_PER_DEC <= scale) { result = result.add(BigDecimal.valueOf(readFixedLengthIntBE(value, offset, DEC_BYTE_SIZE)).movePointLeft(shift + DIG_PER_DEC)); + shift += DIG_PER_DEC; + offset += DEC_BYTE_SIZE; } if (shift < scale) { result = result.add(BigDecimal.valueOf(readFixedLengthIntBE(value, offset, DIG_TO_BYTES[scale - shift])).movePointLeft(scale)); diff --git a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLJsonValueDecoder.java b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLJsonValueDecoder.java index 8da0ac33b98f7..e3f8d29f8612b 100644 --- a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLJsonValueDecoder.java +++ b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLJsonValueDecoder.java @@ -214,12 +214,14 @@ private static String decodeString(final ByteBuf byteBuf) { private static int decodeDataLength(final ByteBuf byteBuf) { int result = 0; - for (int i = 0;; i++) { + int i = 0; + while (true) { int data = byteBuf.readUnsignedByte(); result |= (data & 0x7f) << (7 * i); if (0 == (data & 0x80)) { break; } + i++; } return result; } diff --git a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLAuthSwitchRequestPacket.java b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLAuthSwitchRequestPacket.java index d6d93ea376304..d7265f39ab845 100644 --- a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLAuthSwitchRequestPacket.java +++ b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLAuthSwitchRequestPacket.java @@ -31,6 +31,7 @@ * @see AuthSwitchRequest */ @RequiredArgsConstructor +@Getter public final class MySQLAuthSwitchRequestPacket extends MySQLPacket { /** @@ -38,10 +39,8 @@ public final class MySQLAuthSwitchRequestPacket extends MySQLPacket { */ public static final int HEADER = 0xfe; - @Getter private final String authPluginName; - @Getter private final MySQLAuthenticationPluginData authPluginData; public MySQLAuthSwitchRequestPacket(final MySQLPacketPayload payload) { diff --git a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLJsonValueDecoderTest.java b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLJsonValueDecoderTest.java index 3c5f641c3430d..e8ce970d2a8e0 100644 --- a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLJsonValueDecoderTest.java +++ b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/string/MySQLJsonValueDecoderTest.java @@ -370,10 +370,11 @@ private byte[] codecDataLength(final int length) { } // compress int index = lengthData.length - 1; - for (; index > 0; index--) { + while (index > 0) { if (0 != lengthData[index]) { break; } + index--; } for (int i = 0; i < index; i++) { lengthData[i] |= 0x80; diff --git a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/admin/PostgreSQLUnsupportedCommandPacket.java b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/admin/PostgreSQLUnsupportedCommandPacket.java index 976c968d9574c..1cdf47193d79e 100644 --- a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/admin/PostgreSQLUnsupportedCommandPacket.java +++ b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/admin/PostgreSQLUnsupportedCommandPacket.java @@ -27,9 +27,9 @@ * Unsupported command packet for PostgreSQL. */ @RequiredArgsConstructor +@Getter public final class PostgreSQLUnsupportedCommandPacket extends PostgreSQLCommandPacket { - @Getter private final PostgreSQLIdentifierTag identifier; @Override