imbajin commented on code in PR #2906:
URL:
https://github.com/apache/incubator-hugegraph/pull/2906#discussion_r2522208439
##########
hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/RaftEngine.java:
##########
@@ -408,7 +408,7 @@ private Replicator.State getState(Replicator r) {
try {
var f = clz.getDeclaredField("state");
f.setAccessible(true);
- var state = (Replicator.State) f.get(this.raftNode);
+ var state = (Replicator.State) f.get(r);
Review Comment:
⚠️ **Resource cleanup safety**: If `f.get(r)` throws an exception,
`f.setAccessible(false)` won't be called, leaving the field accessible.
Consider using a try-finally block:
```suggestion
try {
var f = clz.getDeclaredField("state");
f.setAccessible(true);
try {
return (Replicator.State) f.get(r);
} finally {
f.setAccessible(false);
}
} catch (NoSuchFieldException | IllegalAccessException e) {
```
##########
hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/RaftEngine.java:
##########
@@ -408,7 +408,7 @@ private Replicator.State getState(Replicator r) {
try {
Review Comment:
🧹 **Code duplication**: The `getState(Replicator r)` method has identical
implementation in both `RaftEngine.java` and `PartitionEngine.java`. Consider
extracting this to a shared utility class to follow DRY principle and make
future fixes easier.
--
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]