From 8042b1207246f2bbe57f24e9344dc06aad8f3175 Mon Sep 17 00:00:00 2001 From: Zhang Hongjiang Date: Mon, 26 Aug 2024 15:37:02 +0800 Subject: [PATCH] Fix the circular initialization dependency ModifierType and TypeDefinitionCategory has circular initialization dependency, as a result, if we access ModifierType before TypeDefinitionCategory, it will cause java.lang.ExceptionInInitializerError problem. Signed-off-by: Hongjiang Zhang (cherry picked from commit 73232fe09a4dff2d447c89b5a63b72a890d3342f) --- .../database/management/ModifierType.java | 11 ++++--- .../janusgraph/graphdb/TestModifierType.java | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 janusgraph-core/src/test/java/org/janusgraph/graphdb/TestModifierType.java diff --git a/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/management/ModifierType.java b/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/management/ModifierType.java index f0d5ac1cbe..9eb75ec383 100644 --- a/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/management/ModifierType.java +++ b/janusgraph-core/src/main/java/org/janusgraph/graphdb/database/management/ModifierType.java @@ -20,13 +20,14 @@ * @author Joshua Shinavier (http://fortytwo.net) */ public enum ModifierType { - CONSISTENCY(TypeDefinitionCategory.CONSISTENCY_LEVEL), - TTL(TypeDefinitionCategory.TTL); + CONSISTENCY, + TTL; - private final TypeDefinitionCategory category; + private TypeDefinitionCategory category; - ModifierType(final TypeDefinitionCategory category) { - this.category = category; + static { + CONSISTENCY.category = TypeDefinitionCategory.CONSISTENCY_LEVEL; + TTL.category = TypeDefinitionCategory.TTL; } public TypeDefinitionCategory getCategory() { diff --git a/janusgraph-core/src/test/java/org/janusgraph/graphdb/TestModifierType.java b/janusgraph-core/src/test/java/org/janusgraph/graphdb/TestModifierType.java new file mode 100644 index 0000000000..e2b828fcd8 --- /dev/null +++ b/janusgraph-core/src/test/java/org/janusgraph/graphdb/TestModifierType.java @@ -0,0 +1,33 @@ +// Copyright 2024 JanusGraph Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.janusgraph.graphdb; + +import org.janusgraph.graphdb.database.management.ModifierType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; + +public class TestModifierType { + // Verify whether the circular initialization dependency was resolved for ModifierType and TypeDefinitionCategory + @Test + public void testLoadModifierType() { + try { + ModifierType m = ModifierType.CONSISTENCY; + assert(m != null); + } catch (Exception | Error e) { + fail("Fail to access ModifierType"); + } + } +}