Skip to content

fix: no recreate hashmap in getter. - #50

Merged
ksqeib merged 1 commit into
HyperZoneLogin:masterfrom
qyl27:fix/properties-holder-default-props
Nov 12, 2026
Merged

ksqeib merged 1 commit into
HyperZoneLogin:masterfrom
qyl27:fix/properties-holder-default-props

Conversation

@qyl27

@qyl27 qyl27 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

变更说明

IPropertiesHolder#properties的getter不应该在每次调用都返回新的hashmap。

关联范围

  • openvc
  • auth-yggd
  • auth-offline
  • data-merge
  • profile-skin
  • api
  • 文档
  • GitHub 工作流 / 仓库配置

变更类型

  • Bug 修复
  • 新功能
  • 重构
  • 文档更新
  • 构建 / CI 调整
  • 其他

测试与验证

请说明你做了哪些验证,例如:

  • 已本地构建通过
  • 已运行相关测试
  • 已验证配置生成 / 加载正常
  • 已验证迁移逻辑或命令行为
  • 已更新相关文档

兼容性与风险

API破坏:实现IPropertiesHolder的类都需要自己实现properties字段(或者by PropertiesHolder组合默认实现)。

其他补充

如有截图、日志、配置示例或后续 TODO,请在此补充。

Summary by Sourcery

Fix property storage so credential metadata is retained and safely accessible across API calls.

Bug Fixes:

  • Ensure properties persist across accesses instead of creating a new map for every getter call.
  • Return nullable property values without unsafe casting.

Enhancements:

  • Add a reusable concurrent properties-holder implementation and update credential implementations and test fakes to use it.

@sourcery-ai

sourcery-ai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add a reusable properties holder backed by a persistent concurrent map for credential implementations.

  • api/src/main/kotlin/icu/h2l/api/util/PropertiesHolder.kt L1-28

API

Require implementations to provide persistent mutable property storage and return nullable values for missing keys.

  • api/src/main/kotlin/icu/h2l/api/util/IPropertiesHolder.kt L25-28, L42 (removed lines)

Uses of the API

Delegate credential property storage to PropertiesHolder, and store the Yggdrasil entry ID without lowercasing it.

  • subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt L25-26, L37
  • subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt L25-26, L39
  • subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt L25-26, L37, L42

Tests

Update fake credentials in service tests to use persistent properties storage.

  • velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt L31-32, L267
  • velocity/src/test/kotlin/icu/h2l/login/profile/UserUnbindServiceTest.kt L31-32, L105

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="api/src/main/kotlin/icu/h2l/api/util/IPropertiesHolder.kt" line_range="25" />
<code_context>
 interface IPropertiesHolder {
-    val properties: HashMap<String, String>
-        get() = HashMap()
+    val properties: MutableMap<String, String>

-    fun getProperty(key: String): String {
</code_context>
<issue_to_address>
**Existing plugins fail to link**

When a downstream plugin was compiled against the previous API and is loaded or upgraded without rebuilding, the changed `properties` JVM signature and removal of its default getter break callers and implementations compiled against the old interface; the nullable `getProperty` contract also breaks callers expecting a non-null result. Plugins fail to compile or encounter linkage errors at runtime.

Preserve the previous `properties` and `getProperty` contracts, including the default getter, or provide compatible bridges.

Also at `api/src/main/kotlin/icu/h2l/api/util/IPropertiesHolder.kt:27`.
</issue_to_address>

### Comment 2
<location path="subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt" line_range="37" />
<code_context>
     private val suggestedProfileCreateUuid: UUID?,
     private val knownUserUUID: UUID? = null,
-) : HyperZoneCredential {
+) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() {
     override val channelId: String = CHANNEL_ID
     override val credentialId: String = trustedUuid.toString()
</code_context>
<issue_to_address>
**Renaming loses custom properties**

When a caller sets properties on a Floodgate or offline credential and then renames it, the rename methods create a credential with a fresh, empty `PropertiesHolder` and do not copy the original entries, so the replacement credential loses the custom properties.

Copy the original credential's properties into the renamed credential's holder.

Also at `subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt:39`.
</issue_to_address>

### Comment 3
<location path="api/src/main/kotlin/icu/h2l/api/util/PropertiesHolder.kt" line_range="25" />
<code_context>
+package icu.h2l.api.util
+
+class PropertiesHolder(vararg initial: Pair<String, String>) : IPropertiesHolder {
+    override val properties: MutableMap<String, String> = hashMapOf(*initial)
+}
</code_context>
<issue_to_address>
**Concurrent property updates disappear**

When two threads mutate or read and mutate the same credential's properties concurrently, `PropertiesHolder.properties` is a plain `HashMap`, so concurrent mutations through `setProperty`, `removeProperty`, or the exposed map race; updates can be lost or readers can observe stale contents, and callers see missing credential metadata.

Use a thread-safe map or synchronize property access and mutation, including access through the exposed `properties` map.

Also at `api/src/main/kotlin/icu/h2l/api/util/IPropertiesHolder.kt:25`.
</issue_to_address>

Sourcery assessment

Approval pending. 3 findings to address first.

Blocking findings: api/src/main/kotlin/icu/h2l/api/util/IPropertiesHolder.kt:25, subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt:37, api/src/main/kotlin/icu/h2l/api/util/PropertiesHolder.kt:25


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

private val suggestedProfileCreateUuid: UUID?,
private val knownUserUUID: UUID? = null,
) : HyperZoneCredential {
) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Renaming loses custom properties

When a caller sets properties on a Floodgate or offline credential and then renames it, the rename methods create a credential with a fresh, empty PropertiesHolder and do not copy the original entries, so the replacement credential loses the custom properties.

Copy the original credential's properties into the renamed credential's holder.

Also at subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt:39.

Prompt for AI agents
In `subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt` at line 37:

**Renaming loses custom properties**

When a caller sets properties on a Floodgate or offline credential and then renames it, the rename methods create a credential with a fresh, empty `PropertiesHolder` and do not copy the original entries, so the replacement credential loses the custom properties.

Copy the original credential's properties into the renamed credential's holder.

Also at `subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt:39`.

@qyl27
qyl27 force-pushed the fix/properties-holder-default-props branch from 2f9c373 to 8b00018 Compare November 11, 2026 10:01
Signed-off-by: 秋雨落 <i@rain.cx>
@qyl27
qyl27 force-pushed the fix/properties-holder-default-props branch from 8b00018 to 71d416e Compare November 12, 2026 12:30
@qyl27 qyl27 mentioned this pull request Nov 12, 2026
5 of 19 tasks
@ksqeib
ksqeib merged commit 259de35 into HyperZoneLogin:master Nov 12, 2026
1 of 2 checks passed
@qyl27
qyl27 deleted the fix/properties-holder-default-props branch November 13, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants