imbajin commented on code in PR #2940:
URL:
https://github.com/apache/incubator-hugegraph/pull/2940#discussion_r2731177449
##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java:
##########
@@ -52,11 +51,18 @@
public class CoreTestSuite {
private static boolean registered = false;
- private static HugeGraph graph = null;
+ private static volatile HugeGraph graph = null;
public static HugeGraph graph() {
- Assert.assertNotNull(graph);
//Assert.assertFalse(graph.closed());
Review Comment:
‼️ **Critical: Missing space before opening brace**
Code style issue - there should be a space before `{` according to project
conventions.
```suggestion
if (graph == null) {
synchronized (CoreTestSuite.class) {
if (graph == null) {
```
##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java:
##########
@@ -52,11 +51,18 @@
public class CoreTestSuite {
private static boolean registered = false;
- private static HugeGraph graph = null;
+ private static volatile HugeGraph graph = null;
public static HugeGraph graph() {
- Assert.assertNotNull(graph);
//Assert.assertFalse(graph.closed());
+ if (graph == null) {
+ synchronized (CoreTestSuite.class){
+ if (graph == null) {
+ initEnv();
+ init();
Review Comment:
‼️ **Critical: Exception handling concern in lazy initialization**
The `initEnv()` and `init()` methods can throw exceptions. If an exception
occurs inside the synchronized block:
1. `graph` remains `null`
2. Subsequent calls will retry initialization (possibly desirable, but may
cause repeated failures)
Consider whether failed initialization should be remembered to provide a
clearer error message on subsequent calls, or at minimum document this behavior.
Also, there's an ordering dependency: `initEnv()` must complete before
`init()`. While this works with the current `registered` flag, consider whether
you need additional error handling if `initEnv()` succeeds but `init()` fails.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]