Copilot commented on code in PR #2940:
URL: 
https://github.com/apache/incubator-hugegraph/pull/2940#discussion_r2734860893


##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java:
##########
@@ -52,11 +51,29 @@
 public class CoreTestSuite {
 
     private static boolean registered = false;

Review Comment:
   The `registered` variable should be marked as `volatile` to ensure proper 
visibility across threads. Since this variable is checked and modified from 
within a synchronized block in the lazy initialization pattern, there's a 
potential race condition where one thread might not see the updated value set 
by another thread. Making it `volatile` ensures thread-safe publication of the 
variable's value.
   ```suggestion
       private static volatile boolean registered = false;
   ```



##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java:
##########
@@ -52,11 +51,29 @@
 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) {
+                    try {
+                        initEnv();
+                        init();
+                    } catch (Throwable e) {
+                        LOG.error("Failed to initialize HugeGraph instance", 
e);
+                        graph = null;

Review Comment:
   The assignment `graph = null` is redundant here. At this point in the code 
flow, `graph` is guaranteed to be null because it's only assigned a value in 
the `init()` method at line 95. This redundant assignment has no effect and can 
be removed.



-- 
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]

Reply via email to