Skip to content

Commit

Permalink
[#2164][#2166] improvement: enable MutablePublicArray and ReferenceEq…
Browse files Browse the repository at this point in the history
…uality error-prone
  • Loading branch information
coolderli committed Mar 12, 2024
1 parent a9c6d2b commit 29c6b00
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ subprojects {
"MathRoundIntLong",
"MissingSuperCall",
"ModifyingCollectionWithItself",
"MutablePublicArray",
"NonCanonicalStaticImport",
"NonFinalCompileTimeConstant",
"NonRuntimeAnnotation",
Expand All @@ -281,6 +282,7 @@ subprojects {
"ParametersButNotParameterized",
"RandomCast",
"RandomModInteger",
"ReferenceEquality",
"SelfAssignment",
"SelfComparison",
"SelfEquals",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ private int getNextId() {
return nextId++;
}

@SuppressWarnings("ReferenceEquality")
@Override
public Type struct(com.datastrato.gravitino.rel.types.Types.StructType struct, List<Type> types) {
com.datastrato.gravitino.rel.types.Types.StructType.Field[] fields = struct.fields();
List<Types.NestedField> newFields = Lists.newArrayListWithExpectedSize(fields.length);
// Comparing the root node by reference equality.
boolean isRoot = root == struct;
for (int i = 0; i < fields.length; i += 1) {
com.datastrato.gravitino.rel.types.Types.StructType.Field field = fields[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public void testConfWithDefaultValue() {
.stringConf()
.checkValue(value -> value == null, "error")
.toSequence()
.checkValue(
valueList -> valueList.stream().allMatch(element -> element == "test-string"),
"error")
.checkValue(valueList -> valueList.stream().allMatch("test-string"::equals), "error")
.createWithDefault(Lists.newArrayList("test-string", "test-string", "test-string"));
List<String> valueList = testConf.readFrom(configMapEmpty);
Assertions.assertEquals(null, configMapEmpty.get("gravitino.test.string.list"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ void evictStaleNodes(TreeLockNode treeNode, TreeLockNode parent) {
* @param identifier The identifier of the tree lock.
* @return The created tree lock.
*/
@SuppressWarnings("ReferenceEquality")
public TreeLock createTreeLock(NameIdentifier identifier) {
checkTreeNodeIsFull();

Expand All @@ -227,6 +228,8 @@ public TreeLock createTreeLock(NameIdentifier identifier) {
lockNode.addReference();
treeLockNodes.add(lockNode);

// Avoid to use value equality instead of reference equality here.
// Otherwise, there will be an unexpected result when using NameIdentifier.of("/").
if (identifier == ROOT) {
// The lock tree root node
return new TreeLock(treeLockNodes, identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,4 +649,11 @@ void testDeadLockChecker() throws InterruptedException, ExecutionException {
service.take().get();
}
}

@Test
public void testMockRootTreeLock() {
LockManager lockManager = new LockManager(getConfig());
lockManager.createTreeLock(NameIdentifier.of("/"));
Assertions.assertEquals(2L, lockManager.totalNodeCount.get(), "Should have 2 nodes");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testMissingConfig() {
GravitinoConfig config = new GravitinoConfig(configMap);
assertEquals(gravitinoUrl, config.getURI());
} catch (TrinoException e) {
if (e.getErrorCode() != GRAVITINO_MISSING_CONFIG.toErrorCode()) {
if (GRAVITINO_MISSING_CONFIG.toErrorCode().equals(e.getErrorCode())) {
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void testGetGravitinoType() {
try {
dataTypeTransformer.getGravitinoType(HyperLogLogType.HYPER_LOG_LOG);
} catch (TrinoException e) {
if (e.getErrorCode() != GRAVITINO_UNSUPPORTED_TRINO_DATATYPE.toErrorCode()) {
if (!GRAVITINO_UNSUPPORTED_TRINO_DATATYPE.toErrorCode().equals(e.getErrorCode())) {
throw e;
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public void testGetTrinoType() {
try {
dataTypeTransformer.getTrinoType(Types.BinaryType.get());
} catch (TrinoException e) {
if (e.getErrorCode() != GRAVITINO_UNSUPPORTED_GRAVITINO_DATATYPE.toErrorCode()) {
if (!GRAVITINO_UNSUPPORTED_GRAVITINO_DATATYPE.toErrorCode().equals(e.getErrorCode())) {
throw e;
}
}
Expand Down

0 comments on commit 29c6b00

Please sign in to comment.