-
Notifications
You must be signed in to change notification settings - Fork 569
fix(server): fix npe in non-auth mode #2912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -186,6 +186,7 @@ public static Context setAdmin() { | |||||||||||||||||
| public static Context getContext() { | ||||||||||||||||||
| // Return task context first | ||||||||||||||||||
| String taskContext = TaskManager.getContext(); | ||||||||||||||||||
|
|
||||||||||||||||||
| User user = User.fromJson(taskContext); | ||||||||||||||||||
| if (user != null) { | ||||||||||||||||||
| return new Context(user); | ||||||||||||||||||
|
|
@@ -953,6 +954,14 @@ public void updateTime(Date updateTime) { | |||||||||||||||||
| this.hugegraph.updateTime(updateTime); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| public static String username() { | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这是一个 NPE 修复,应该添加单元测试来验证:
建议添加测试类或测试方法覆盖这些场景。
Tsukilc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
| Context context = HugeGraphAuthProxy.getContext(); | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 虽然修复了
Suggested change
或者检查一下 |
||||||||||||||||||
| if (context == null) { | ||||||||||||||||||
| return "anonymous"; | ||||||||||||||||||
| } | ||||||||||||||||||
| return context.user.username(); | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 新增的
Suggested change
请确认非认证模式下的业务预期行为。 |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private <V> Cache<Id, V> cache(String prefix, long capacity, | ||||||||||||||||||
| long expiredTime) { | ||||||||||||||||||
| String name = prefix + "-" + this.hugegraph.spaceGraphName(); | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议搜索整个代码库中所有
HugeGraphAuthProxy.getContext().user().username()的调用点,确保都已替换为新的username()方法,避免遗漏其他潜在的 NPE 风险点。可以使用以下命令检查: