Repository navigation
fix: no recreate hashmap in getter. - #50
Conversation
Reviewer's GuideData structuresAdd a reusable properties holder backed by a persistent concurrent map for credential implementations.
APIRequire implementations to provide persistent mutable property storage and return nullable values for missing keys.
Uses of the APIDelegate credential property storage to PropertiesHolder, and store the Yggdrasil entry ID without lowercasing it.
TestsUpdate fake credentials in service tests to use persistent properties storage.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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
| private val suggestedProfileCreateUuid: UUID?, | ||
| private val knownUserUUID: UUID? = null, | ||
| ) : HyperZoneCredential { | ||
| ) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { |
There was a problem hiding this comment.
🟡 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`.2f9c373 to
8b00018
Compare
Signed-off-by: 秋雨落 <i@rain.cx>
8b00018 to
71d416e
Compare
变更说明
IPropertiesHolder#properties的getter不应该在每次调用都返回新的hashmap。
关联范围
openvcauth-yggdauth-offlinedata-mergeprofile-skinapi变更类型
测试与验证
请说明你做了哪些验证,例如:
兼容性与风险
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:
Enhancements: