Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: upgrade a string of dependencies to address CVEs report & clean code #110

Merged
merged 9 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ target
gen-java
build
node*
*.versionsBackup
7 changes: 1 addition & 6 deletions hugegraph-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</parent>

<artifactId>hugegraph-common</artifactId>
<name>${artifactId}</name>
<name>${project.artifactId}</name>
<url>https://github.com/apache/incubator-hugegraph-commons/tree/master/hugegraph-common</url>
<description>
hugegraph-common is a common module for HugeGraph and its peripheral components.
Expand Down Expand Up @@ -211,7 +211,6 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${compiler.source}</source>
<target>${compiler.target}</target>
Expand All @@ -226,7 +225,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<index>true</index>
Expand Down Expand Up @@ -281,7 +279,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -294,7 +291,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -307,7 +303,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.InsertionOrderUtil;

import com.google.common.collect.ImmutableList;

public class BatchMapperIterator<T, R> extends WrappedIterator<R> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ public String toECharts() {
sb.append("',");

sb.append("value:");
sb.append(w.totalCost()); // w.totalCost() - w.totalWasted() ?
// w.totalCost() - w.totalWasted() ?
sb.append(w.totalCost());
sb.append(',');

sb.append("cost:");
Expand Down Expand Up @@ -419,7 +420,7 @@ public String toECharts() {
return c.parent().equals(parent.id());
});
// Fill other cost
long sumCost = children.mapToLong(c -> c.totalCost()).sum();
long sumCost = children.mapToLong(Stopwatch::totalCost).sum();
long otherCost = parent.totalCost() - sumCost;
if (otherCost > 0L) {
Stopwatch other = newStopwatch("~", parent.id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ public ClientConfig build() {
public static class BearerRequestFilter implements ClientRequestFilter {

@Override
public void filter(ClientRequestContext context) throws IOException {
public void filter(ClientRequestContext context) {
String token = context.getClient().getConfiguration()
.getProperty(TOKEN_KEY).toString();
context.getHeaders().add(HttpHeaders.AUTHORIZATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public static String encodeNumber(Object number) {

public static Number decodeNumber(String str, Class<?> clazz) {
long value = decodeSortable(str);
Number number = NumericUtil.sortableLongToNumber(value, clazz);
return number;
return NumericUtil.sortableLongToNumber(value, clazz);
}

public static String encodeSortable(long num) {
Expand Down Expand Up @@ -130,10 +129,11 @@ public static long decode(String encoded, String symbols) {
for (char ch : encoded.toCharArray()) {
num *= B;
int pos = symbols.indexOf(ch);
if (pos < 0)
if (pos < 0) {
throw new NumberFormatException(String.format(
"Can't decode symbol '%s' in string '%s'",
ch, encoded));
}
num += pos;
}
return num;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import com.google.common.collect.Ordering;

/**
* Reference: https://stackoverflow.com/questions/109383/sort-a-mapkey-value-by-values
* Reference:
* <a href="https://stackoverflow.com/questions/109383/sort-a-mapkey-value-by-values">...</a>
*/
public class OrderLimitMap<K extends Comparable<K>, V extends Comparable<V>>
extends TreeMap<K, V> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@
public final class ReflectionUtil {

public static boolean isSimpleType(Class<?> type) {
if (type.isPrimitive() ||
type.equals(String.class) ||
type.equals(Boolean.class) ||
type.equals(Character.class) ||
NumericUtil.isNumber(type)) {
return true;
}
return false;
return type.isPrimitive() ||
type.equals(String.class) ||
type.equals(Boolean.class) ||
type.equals(Character.class) ||
NumericUtil.isNumber(type);
}

public static List<Method> getMethodsAnnotatedWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.hugegraph.util;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;

public final class UnitUtil {
Expand All @@ -34,7 +35,7 @@ public static double bytesToGB(long bytes) {

public static double doubleWith2Scale(double value) {
BigDecimal decimal = new BigDecimal(value);
return decimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return decimal.setScale(2, RoundingMode.HALF_UP).doubleValue();
}

public static String bytesToReadableString(long bytes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Objects;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

Expand Down Expand Up @@ -79,7 +80,7 @@ public static String getImplementationVersion(Class<?> clazz) {
* https://stackoverflow.com/questions/1272648/reading-my-own-jars-manifest
*/
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
String classPath = Objects.requireNonNull(clazz.getResource(className)).toString();
if (!classPath.startsWith("jar:file:")) {
// Class not from JAR
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void testAssertEqualsOfIntWithError() {
});

Assert.assertThrows(AssertionError.class, () -> {
Assert.assertEquals(1, (Long) 1l);
Assert.assertEquals(1, (Long) 1L);
}, e -> {
Assert.assertContains("expected: java.lang.Integer",
e.getMessage());
Expand Down Expand Up @@ -192,9 +192,7 @@ public void testAssertThrowsWithError() {
});
Assert.fail("Expect error");
} catch (AssertionError e) {
Assert.assertEquals("No exception was thrown" +
"(expected java.lang.NullPointerException)",
e.getMessage());
Assert.assertContains("java.lang.NullPointerException", e.getMessage());
}

try {
Expand All @@ -203,10 +201,8 @@ public void testAssertThrowsWithError() {
});
Assert.fail("Expect error");
} catch (AssertionError e) {
Assert.assertEquals("Bad exception type " +
"java.lang.RuntimeException" +
"(expected java.lang.NullPointerException)",
e.getMessage());
Assert.assertContains("java.lang.NullPointerException", e.getMessage());
Assert.assertContains("java.lang.RuntimeException", e.getMessage());
}
}

Expand Down Expand Up @@ -254,7 +250,7 @@ public void testAssertGt() {
});

Assert.assertThrows(AssertionError.class, () -> {
Assert.assertGt(1, Character.valueOf('2'));
Assert.assertGt(1, '2');
}, e -> {
Assert.assertContains("Expected: an instance of java.lang.Integer",
e.getMessage());
Expand Down Expand Up @@ -312,7 +308,7 @@ public void testAssertGte() {
});

Assert.assertThrows(AssertionError.class, () -> {
Assert.assertGte(1, Character.valueOf('2'));
Assert.assertGte(1, '2');
}, e -> {
Assert.assertContains("Expected: an instance of java.lang.Integer",
e.getMessage());
Expand Down Expand Up @@ -342,7 +338,7 @@ public void testAssertLt() {
});

Assert.assertThrows(AssertionError.class, () -> {
Assert.assertGt(1, Character.valueOf('0'));
Assert.assertGt(1, '0');
}, e -> {
Assert.assertContains("Expected: an instance of java.lang.Integer",
e.getMessage());
Expand Down Expand Up @@ -379,7 +375,7 @@ public void testAssertLte() {
});

Assert.assertThrows(AssertionError.class, () -> {
Assert.assertLte(1, Character.valueOf('0'));
Assert.assertLte(1, '0');
}, e -> {
Assert.assertContains("Expected: an instance of java.lang.Integer",
e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class BarrierEventTest {

private static int WAIT_THREADS_COUNT = 10;
private static final int WAIT_THREADS_COUNT = 10;

@Test(timeout = 5000)
public void testAWait() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class LockGroupTest extends BaseUnitTest {

private static final String GROUP = "LockGroupTest-test-group";

private LockGroup group = new LockGroup(GROUP);
private final LockGroup group = new LockGroup(GROUP);

@Test
public void testLock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class PausableScheduledThreadPoolTest {

@Test
public void testscheduleWithFixedDelay() throws InterruptedException {
public void testScheduleWithFixedDelay() throws InterruptedException {
PausableScheduledThreadPool executor =
ExecutorUtil.newPausableScheduledThreadPool("test");
long period = 500L;
Expand Down Expand Up @@ -64,7 +64,7 @@ public void testscheduleWithFixedDelay() throws InterruptedException {
}

@Test
public void testscheduleWithFixedRate() throws InterruptedException {
public void testScheduleWithFixedRate() throws InterruptedException {
PausableScheduledThreadPool executor =
ExecutorUtil.newPausableScheduledThreadPool(2, "test");
long period = 500L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void testOptionDesc() {

@Test
public void testOptionRequired() {
Assert.assertEquals(false, TestOptions.text1.required());
Assert.assertEquals(true, TestSubOptions.text2.required());
Assert.assertFalse(TestOptions.text1.required());
Assert.assertTrue(TestSubOptions.text2.required());
}

@Test
Expand Down Expand Up @@ -670,6 +670,6 @@ protected boolean forList() {

public enum WeekDay {

SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY;
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
}
Loading