imbajin commented on code in PR #685:
URL:
https://github.com/apache/incubator-hugegraph-toolchain/pull/685#discussion_r2464735910
##########
hugegraph-client/src/main/java/org/apache/hugegraph/client/RestClient.java:
##########
@@ -39,6 +40,7 @@
public class RestClient extends AbstractRestClient {
private static final int SECOND = 1000;
+ private final String version = new VersionManager(this).getCoreVersion();;
Review Comment:
‼️ **潜在的空指针异常风险 (Critical)**
这行代码存在严重的设计问题:
1. **构造函数中调用可能失败的网络请求**:`new VersionManager(this).getCoreVersion()` 会在构造
RestClient 时立即发起网络请求
2. **字段初始化顺序问题**:如果在构造函数中还有其他初始化逻辑未完成,可能导致 NPE
3. **性能问题**:每次创建 RestClient 都会创建新的 VersionManager 并请求版本信息
**建议改为懒加载模式:**
```java
private String version;
private boolean supportGs;
private synchronized boolean isSupportGs() {
if (version == null) {
version = new VersionManager(this).getCoreVersion();
supportGs = VersionUtil.gte(version, "1.7.0");
}
return supportGs;
}
```
或者在 `HugeClient` 的构造逻辑中统一处理版本检查后设置。
##########
hugegraph-client/src/main/java/org/apache/hugegraph/client/RestClient.java:
##########
@@ -39,6 +40,7 @@
public class RestClient extends AbstractRestClient {
private static final int SECOND = 1000;
+ private final String version = new VersionManager(this).getCoreVersion();;
Review Comment:
🧹 **代码风格问题 (Minor)**
行末有多余的分号:`;;" 应改为:
```java
private final String version = new VersionManager(this).getCoreVersion();
```
不过基于前面的评论,建议重新设计这个字段的初始化方式。
--
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]