Skip to content

Commit c6107eb

Browse files
ministatporunov
authored andcommitted
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 <timerzhj@hotmail.com> Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com>
1 parent 4cec993 commit c6107eb

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

janusgraph-core/src/main/java/org/janusgraph/graphdb/database/management/ModifierType.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
* @author Joshua Shinavier (http://fortytwo.net)
2121
*/
2222
public enum ModifierType {
23-
CONSISTENCY(TypeDefinitionCategory.CONSISTENCY_LEVEL),
24-
TTL(TypeDefinitionCategory.TTL);
23+
CONSISTENCY,
24+
TTL;
2525

26-
private final TypeDefinitionCategory category;
26+
private TypeDefinitionCategory category;
2727

28-
ModifierType(final TypeDefinitionCategory category) {
29-
this.category = category;
28+
static {
29+
CONSISTENCY.category = TypeDefinitionCategory.CONSISTENCY_LEVEL;
30+
TTL.category = TypeDefinitionCategory.TTL;
3031
}
3132

3233
public TypeDefinitionCategory getCategory() {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2024 JanusGraph Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package org.janusgraph.graphdb;
16+
17+
import org.janusgraph.graphdb.database.management.ModifierType;
18+
import org.junit.jupiter.api.Test;
19+
20+
import static org.junit.jupiter.api.Assertions.fail;
21+
22+
public class TestModifierType {
23+
// Verify whether the circular initialization dependency was resolved for ModifierType and TypeDefinitionCategory
24+
@Test
25+
public void testLoadModifierType() {
26+
try {
27+
ModifierType m = ModifierType.CONSISTENCY;
28+
assert(m != null);
29+
} catch (Exception | Error e) {
30+
fail("Fail to access ModifierType");
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)