Skip to content

Commit

Permalink
Fix code inspections (#31217)
Browse files Browse the repository at this point in the history
* Fix code inspection for agent module

* Fix code inspection for agent module

* Fix code inspection for agent module

* Fix code inspections

* Fix code inspections

* Fix code inspections
  • Loading branch information
terrymanu authored May 12, 2024
1 parent 830dfc8 commit 1fbc4fd
Show file tree
Hide file tree
Showing 40 changed files with 93 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ private void appendProperties(final Builder builder, final Map<String, Object> p
return;
}
if (EXP_TYPE_KEY.equals(buckets.get(TYPE_KEY))) {
double start = null == buckets.get(START_KEY) ? 1 : Double.parseDouble(buckets.get(START_KEY).toString());
double factor = null == buckets.get(FACTOR_KEY) ? 1 : Double.parseDouble(buckets.get(FACTOR_KEY).toString());
double start = null == buckets.get(START_KEY) ? 1D : Double.parseDouble(buckets.get(START_KEY).toString());
double factor = null == buckets.get(FACTOR_KEY) ? 1D : Double.parseDouble(buckets.get(FACTOR_KEY).toString());
int count = null == buckets.get(COUNT_KEY) ? 1 : (int) buckets.get(COUNT_KEY);
builder.exponentialBuckets(start, factor, count);
} else if (LINEAR_TYPE_KEY.equals(buckets.get(TYPE_KEY))) {
double start = null == buckets.get(START_KEY) ? 1 : Double.parseDouble(buckets.get(START_KEY).toString());
double width = null == buckets.get(WIDTH_KEY) ? 1 : Double.parseDouble(buckets.get(WIDTH_KEY).toString());
double start = null == buckets.get(START_KEY) ? 1D : Double.parseDouble(buckets.get(START_KEY).toString());
double width = null == buckets.get(WIDTH_KEY) ? 1D : Double.parseDouble(buckets.get(WIDTH_KEY).toString());
int count = null == buckets.get(COUNT_KEY) ? 1 : (int) buckets.get(COUNT_KEY);
builder.linearBuckets(start, width, count);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PrometheusMetricsHistogramCollectorTest {
void assertCreate() throws ReflectiveOperationException {
PrometheusMetricsHistogramCollector collector = new PrometheusMetricsHistogramCollector(new MetricConfiguration("foo_histogram",
MetricCollectorType.HISTOGRAM, "foo_help", Collections.emptyList(), Collections.emptyMap()));
collector.observe(1);
collector.observe(1D);
Histogram histogram = (Histogram) Plugins.getMemberAccessor().get(PrometheusMetricsHistogramCollector.class.getDeclaredField("histogram"), collector);
assertThat(histogram.collect().size(), is(1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PrometheusSummaryWrapperTest {
void assertCreate() throws ReflectiveOperationException {
PrometheusMetricsSummaryCollector collector = new PrometheusMetricsSummaryCollector(new MetricConfiguration("foo_summary",
MetricCollectorType.SUMMARY, "foo_help", Collections.emptyList(), Collections.emptyMap()));
collector.observe(1);
collector.observe(1D);
Summary summary = (Summary) Plugins.getMemberAccessor().get(PrometheusMetricsSummaryCollector.class.getDeclaredField("summary"), collector);
assertThat(summary.collect().size(), is(1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static void decodeValue(final int type, final int offset, final ByteBuf

private static BigInteger readUnsignedLongLE(final ByteBuf byteBuf) {
long value = byteBuf.readLongLE();
return 0 <= value ? BigInteger.valueOf(value) : MAX_BIG_INTEGER_VALUE.add(BigInteger.valueOf(1 + value));
return 0L <= value ? BigInteger.valueOf(value) : MAX_BIG_INTEGER_VALUE.add(BigInteger.valueOf(1L + value));
}

private static void decodeJsonObject(final boolean isSmall, final ByteBuf byteBuf, final StringBuilder stringBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ public final class MySQLDatetime2BinlogProtocolValue implements MySQLBinlogProto
@Override
public Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload) {
long datetime = readDatetimeV2FromPayload(payload);
return 0 == datetime ? MySQLTimeValueUtils.DATETIME_OF_ZERO : readDatetime(columnDef, datetime, payload);
return 0L == datetime ? MySQLTimeValueUtils.DATETIME_OF_ZERO : readDatetime(columnDef, datetime, payload);
}

private long readDatetimeV2FromPayload(final MySQLPacketPayload payload) {
long result = 0;
long result = 0L;
for (int i = 4; i >= 0; i--) {
result |= (long) payload.readInt1() << (8 * i);
}
return result;
}

private Serializable readDatetime(final MySQLBinlogColumnDef columnDef, final long datetime, final MySQLPacketPayload payload) {
long datetimeWithoutSign = datetime & (0x8000000000L - 1);
long datetimeWithoutSign = datetime & (0x8000000000L - 1L);
if (0 == datetimeWithoutSign) {
return MySQLTimeValueUtils.DATETIME_OF_ZERO;
}
long date = datetimeWithoutSign >> 17;
long yearAndMonth = date >> 5;
int year = (int) (yearAndMonth / 13);
int month = (int) (yearAndMonth % 13);
int day = (int) (date % (1 << 5));
long time = datetimeWithoutSign % (1 << 17);
int year = (int) (yearAndMonth / 13L);
int month = (int) (yearAndMonth % 13L);
int day = (int) (date % (1L << 5L));
long time = datetimeWithoutSign % (1L << 17L);
int hour = (int) (time >> 12);
int minute = (int) ((time >> 6) % (1 << 6));
int second = (int) (time % (1 << 6));
int minute = (int) ((time >> 6) % (1L << 6L));
int second = (int) (time % (1L << 6L));
MySQLFractionalSeconds fractionalSeconds = new MySQLFractionalSeconds(columnDef.getColumnMeta(), payload);
return Timestamp.valueOf(LocalDateTime.of(year, month, day, hour, minute, second, fractionalSeconds.getNanos()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public final class MySQLDatetimeBinlogProtocolValue implements MySQLBinlogProtoc
@Override
public Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload) {
long datetime = payload.readInt8();
return 0 == datetime ? MySQLTimeValueUtils.DATETIME_OF_ZERO : readDateTime(datetime);
return 0L == datetime ? MySQLTimeValueUtils.DATETIME_OF_ZERO : readDateTime(datetime);
}

private Date readDateTime(final long datetime) {
int date = (int) (datetime / 1000000);
int date = (int) (datetime / 1000000L);
int year = date / 10000;
int month = (date % 10000) / 100;
int day = date % 100;
int time = (int) (datetime % 1000000);
int time = (int) (datetime % 1000000L);
int hour = time / 10000;
int minute = (time % 10000) / 100;
int second = time % 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void writeInt4(final int value) {
* @return 6 byte fixed length integer
*/
public long readInt6() {
long result = 0;
long result = 0L;
for (int i = 0; i < 6; i++) {
result |= ((long) (0xff & byteBuf.readByte())) << (8 * i);
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public long readIntLenenc() {
return firstByte;
}
if (0xfb == firstByte) {
return 0;
return 0L;
}
if (0xfc == firstByte) {
return readInt2();
Expand All @@ -182,12 +182,12 @@ public void writeIntLenenc(final long value) {
byteBuf.writeByte((int) value);
return;
}
if (value < Math.pow(2, 16)) {
if (value < Math.pow(2D, 16D)) {
byteBuf.writeByte(0xfc);
byteBuf.writeShortLE((int) value);
return;
}
if (value < Math.pow(2, 24)) {
if (value < Math.pow(2D, 24D)) {
byteBuf.writeByte(0xfd);
byteBuf.writeMediumLE((int) value);
return;
Expand All @@ -203,7 +203,7 @@ public void writeIntLenenc(final long value) {
* @return fixed length long
*/
public long readLong(final int length) {
long result = 0;
long result = 0L;
for (int i = 0; i < length; i++) {
result = result << 8 | readInt1();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ void assertDecodeSmallJsonObjectWithDouble() {
void assertDecodeSmallJsonObjectWithString() {
List<JsonEntry> jsonEntries = new LinkedList<>();
String value1 = "";
String value2 = Strings.repeat("1", (int) (Math.pow(2, 7) - 1));
String value3 = Strings.repeat("1", (int) (Math.pow(2, 7) - 1 + 1));
String value4 = Strings.repeat("1", (int) (Math.pow(2, 14) - 1));
String value2 = Strings.repeat("1", (int) (Math.pow(2D, 7D) - 1D));
String value3 = Strings.repeat("1", (int) (Math.pow(2D, 7D) - 1D + 1D));
String value4 = Strings.repeat("1", (int) (Math.pow(2D, 14D) - 1D));
jsonEntries.add(new JsonEntry(JsonValueTypes.STRING, "key1", value1));
jsonEntries.add(new JsonEntry(JsonValueTypes.STRING, "key2", value2));
jsonEntries.add(new JsonEntry(JsonValueTypes.STRING, "key3", value3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void setUp() {

@Test
void assertReadWithoutFraction() {
int currentSeconds = Long.valueOf(System.currentTimeMillis() / 1000).intValue();
int currentSeconds = Long.valueOf(System.currentTimeMillis() / 1000L).intValue();
when(byteBuf.readInt()).thenReturn(currentSeconds);
assertThat(new MySQLTimestamp2BinlogProtocolValue().read(columnDef, payload), is(new Timestamp(currentSeconds * 1000L)));
}
Expand All @@ -61,8 +61,8 @@ void assertReadWithoutFraction() {
void assertReadWithFraction() {
columnDef.setColumnMeta(1);
long currentTimeMillis = 1678795614082L;
int currentSeconds = Long.valueOf(currentTimeMillis / 1000).intValue();
int currentMilliseconds = Long.valueOf(currentTimeMillis % 100).intValue();
int currentSeconds = Long.valueOf(currentTimeMillis / 1000L).intValue();
int currentMilliseconds = Long.valueOf(currentTimeMillis % 100L).intValue();
when(payload.readInt1()).thenReturn(currentMilliseconds);
when(byteBuf.readInt()).thenReturn(currentSeconds);
assertThat("currentTimeMillis:" + currentTimeMillis, new MySQLTimestamp2BinlogProtocolValue().read(columnDef, payload), is(new Timestamp(currentSeconds * 1000L + currentMilliseconds * 10L)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ void assertWrite() {
MySQLFieldCountPacket actual = new MySQLFieldCountPacket(payload);
assertThat(actual.getColumnCount(), is(3));
actual.write(payload);
verify(payload).writeIntLenenc(3);
verify(payload).writeIntLenenc(3L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MySQLTimeBinaryProtocolValueTest {

@Test
void assertReadWithZeroByte() throws SQLException {
assertThat(new MySQLTimeBinaryProtocolValue().read(payload, false), is(new Timestamp(0)));
assertThat(new MySQLTimeBinaryProtocolValue().read(payload, false), is(new Timestamp(0L)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void assertWrite() {

@Test
void assertTimestampWithoutNanos() {
long now = System.currentTimeMillis() / 1000 * 1000;
long now = System.currentTimeMillis() / 1000L * 1000L;
Timestamp timestamp = new Timestamp(now);
MySQLTextResultSetRowPacket actual = new MySQLTextResultSetRowPacket(Arrays.asList(null, "value", BigDecimal.ONE, new byte[]{}, timestamp));
actual.write(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,23 @@ void assertWriteIntLenencWithOneByte() {

@Test
void assertWriteIntLenencWithTwoBytes() {
new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2, 16)).longValue() - 1);
new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2D, 16D)).longValue() - 1L);
verify(byteBuf).writeByte(0xfc);
verify(byteBuf).writeShortLE(Double.valueOf(Math.pow(2, 16)).intValue() - 1);
verify(byteBuf).writeShortLE(Double.valueOf(Math.pow(2D, 16D)).intValue() - 1);
}

@Test
void assertWriteIntLenencWithThreeBytes() {
new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2, 24)).longValue() - 1);
new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2D, 24D)).longValue() - 1L);
verify(byteBuf).writeByte(0xfd);
verify(byteBuf).writeMediumLE(Double.valueOf(Math.pow(2, 24)).intValue() - 1);
verify(byteBuf).writeMediumLE(Double.valueOf(Math.pow(2D, 24D)).intValue() - 1);
}

@Test
void assertWriteIntLenencWithFourBytes() {
new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2, 25)).longValue() - 1);
new MySQLPacketPayload(byteBuf, StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2D, 25D)).longValue() - 1L);
verify(byteBuf).writeByte(0xfe);
verify(byteBuf).writeLongLE(Double.valueOf(Math.pow(2, 25)).intValue() - 1);
verify(byteBuf).writeLongLE(Double.valueOf(Math.pow(2D, 25D)).intValue() - 1L);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ private static long convertJavaEpochToPgEpoch(final long seconds) {
}

private static long convertToJulianSeconds(final long seconds) {
return seconds - TimeUnit.DAYS.toSeconds(10);
return seconds - TimeUnit.DAYS.toSeconds(10L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void assertRead() {
byteBuf.readInt();
PostgreSQLPacketPayload payload = new PostgreSQLPacketPayload(byteBuf, StandardCharsets.UTF_8);
Object actual = newInstance().read(payload, parameterValue.length());
assertThat(actual, is(new long[]{11, 12}));
assertThat(actual, is(new long[]{11L, 12L}));
assertThat(byteBuf.readerIndex(), is(expectedLength));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PostgreSQLCommandCompletePacketTest {
@ParameterizedTest(name = "{0}")
@ArgumentsSource(TestCaseArgumentsProvider.class)
void assertReadWrite(final String sqlCommand, final String expectedDelimiter) {
long rowCount = 1;
long rowCount = 1L;
String expectedString = sqlCommand + expectedDelimiter + rowCount;
int expectedStringLength = expectedString.length();
PostgreSQLPacketPayload payload = new PostgreSQLPacketPayload(ByteBufTestUtils.createByteBuf(expectedStringLength + 1), StandardCharsets.ISO_8859_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private DecoratedEncryptShowCreateTableMergedResult createDecoratedEncryptShowCr
when(sqlStatementContext.getAllTables()).thenReturn(Collections.singleton(simpleTableSegment));
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "MySQL"));
RuleMetaData ruleMetaData = mock(RuleMetaData.class);
when(ruleMetaData.getSingleRule(SQLParserRule.class)).thenReturn(new SQLParserRule(new SQLParserRuleConfiguration(new CacheOption(128, 1024), new CacheOption(2000, 65535))));
when(ruleMetaData.getSingleRule(SQLParserRule.class)).thenReturn(new SQLParserRule(new SQLParserRuleConfiguration(new CacheOption(128, 1024L), new CacheOption(2000, 65535L))));
return new DecoratedEncryptShowCreateTableMergedResult(ruleMetaData, mergedResult, sqlStatementContext, encryptRule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private MergedEncryptShowCreateTableMergedResult createMergedEncryptShowCreateTa
when(sqlStatementContext.getAllTables()).thenReturn(Collections.singleton(simpleTableSegment));
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "MySQL"));
RuleMetaData ruleMetaData = mock(RuleMetaData.class);
when(ruleMetaData.getSingleRule(SQLParserRule.class)).thenReturn(new SQLParserRule(new SQLParserRuleConfiguration(new CacheOption(128, 1024), new CacheOption(2000, 65535))));
when(ruleMetaData.getSingleRule(SQLParserRule.class)).thenReturn(new SQLParserRule(new SQLParserRuleConfiguration(new CacheOption(128, 1024L), new CacheOption(2000, 65535L))));
return new MergedEncryptShowCreateTableMergedResult(ruleMetaData, queryResult, sqlStatementContext, encryptRule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static void checkDuplicateRuleNamesWithSelf(final String databaseName, f

private static Collection<String> getDuplicated(final Collection<String> required) {
return required.stream().collect(Collectors.groupingBy(each -> each, Collectors.counting())).entrySet().stream()
.filter(each -> each.getValue() > 1).map(Entry::getKey).collect(Collectors.toSet());
.filter(each -> each.getValue() > 1L).map(Entry::getKey).collect(Collectors.toSet());
}

private static void checkDuplicateRuleNamesWithExistsDataSources(final ShardingSphereDatabase database, final Collection<ReadwriteSplittingRuleSegment> segments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void checkExisted(final Collection<String> requiredRules, final Co

private static Collection<String> getDuplicated(final Collection<String> names) {
return names.stream().collect(Collectors.groupingBy(each -> each, Collectors.counting())).entrySet().stream()
.filter(each -> each.getValue() > 1).map(Entry::getKey).collect(Collectors.toSet());
.filter(each -> each.getValue() > 1L).map(Entry::getKey).collect(Collectors.toSet());
}

private static Collection<String> getDuplicated(final Collection<String> required, final Collection<String> current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class AutoIntervalShardingAlgorithm implements StandardShardingAlgo
public void init(final Properties props) {
dateTimeLower = getDateTime(props);
shardingSeconds = getShardingSeconds(props);
autoTablesAmount = (int) (Math.ceil((double) (parseDate(props.getProperty(DATE_TIME_UPPER_KEY)) / shardingSeconds)) + 2);
autoTablesAmount = (int) (Math.ceil((double) (parseDate(props.getProperty(DATE_TIME_UPPER_KEY)) / shardingSeconds)) + 2D);
}

private LocalDateTime getDateTime(final Properties props) {
Expand Down Expand Up @@ -113,7 +113,7 @@ private int getLastPartition(final Range<Comparable<?>> valueRange) {

private long parseDate(final Comparable<?> shardingValue) {
LocalDateTime dateValue = LocalDateTime.from(DateTimeFormatterFactory.getStandardFormatter().parse(shardingValue.toString(), new ParsePosition(0)));
return Duration.between(dateTimeLower, dateValue).toMillis() / 1000;
return Duration.between(dateTimeLower, dateValue).toMillis() / 1000L;
}

@Override
Expand Down
Loading

0 comments on commit 1fbc4fd

Please sign in to comment.