Skip to content

Fix Feature Filter#64

Merged
AngeloTadeucci merged 1 commit intoMS2Community:masterfrom
Zintixx:filter-fix
May 4, 2026
Merged

Fix Feature Filter#64
AngeloTadeucci merged 1 commit intoMS2Community:masterfrom
Zintixx:filter-fix

Conversation

@Zintixx
Copy link
Copy Markdown

@Zintixx Zintixx commented May 4, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved deterministic resolution of feature locale entries. When multiple entries share the same version priority, the system now applies consistent tie-breaking logic to ensure stable and predictable results instead of depending on encounter order, strengthening overall system reliability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

📝 Walkthrough

Walkthrough

The PR adds deterministic tie-breaking to feature locale resolution when multiple entries share the same highest version, selecting the lexicographically greater feature by StringComparison.Ordinal, and bumps the package version from 2.4.6 to 2.4.7.

Changes

Feature Locale Deterministic Resolution & Package Release

Layer / File(s) Summary
Core Logic
Maple2.File.Generator/Resource/FeatureLocaleFilter.cs
Resolve<T> adds lexicographic tie-breaking by comparing entry.Feature vs result.Feature using StringComparison.Ordinal when multiple entries share the same highest version, preferring the greater feature name.
Package Versioning
Maple2.File.Parser/Maple2.File.Parser.csproj
Version bumped from 2.4.6 to 2.4.7 to release the updated resolution behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • MS2Community/Maple2.File#43: Also modifies Maple2.File.Parser.csproj PackageVersion, indicating coordinated version bumping across related PRs.

Poem

🐰 When versions tie, we don't despair,
A lexicon brings order fair,
The greater name now claims its place,
Deterministic, swift, and full of grace!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix Feature Filter' directly relates to the main change: improving the feature locale filter resolution logic with a deterministic tie-breaker for entries with the same version.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Maple2.File.Generator/Resource/FeatureLocaleFilter.cs`:
- Around line 68-70: The tie-breaker condition in FeatureLocaleFilter that reads
(version == maxVersion && string.Compare(entry.Feature, result.Feature,
StringComparison.Ordinal) > 0) can dereference result (default(T) / null) when
the first seen entry has version == maxVersion (e.g. Features[entry.Feature] ==
-1); modify the condition to first check result == null before accessing
result.Feature so that any entry at the same version always replaces a null
result. In practice update the if in the method using variables version,
maxVersion, entry and result to: if (version > maxVersion || (version ==
maxVersion && (result == null || string.Compare(entry.Feature, result.Feature,
StringComparison.Ordinal) > 0))) so result is not dereferenced.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b3b8d8e-3443-4655-9ccb-956bfccb1f8f

📥 Commits

Reviewing files that changed from the base of the PR and between 6257646 and 4984747.

📒 Files selected for processing (2)
  • Maple2.File.Generator/Resource/FeatureLocaleFilter.cs
  • Maple2.File.Parser/Maple2.File.Parser.csproj

Comment on lines +68 to +70
if (version > maxVersion ||
// This is how the client resolves same version matches. Dumb as bricks.
(version == maxVersion && string.Compare(entry.Feature, result.Feature, StringComparison.Ordinal) > 0)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Latent NullReferenceException when the first feature entry has version −1

result starts as default(T)null for any reference-type T. The tie-breaker arm version == maxVersion fires the moment a feature entry's version matches the initial sentinel value of −1 (i.e. Features[entry.Feature] == -1). If that happens before any prior entry has set result, the expression result.Feature dereferences a null object and throws.

Note that string.Compare itself is null-safe for its string arguments (one or both comparands can be null — by definition, any string compares greater than a null reference), so the problem is specifically the member access on result, not the comparison call.

The correct guard also covers the semantics correctly: a null result should always be replaced by any feature entry at the same version (just as any feature beats no-feature).

🛡️ Proposed fix
-            if (version > maxVersion ||
-                // This is how the client resolves same version matches. Dumb as bricks.
-                (version == maxVersion && string.Compare(entry.Feature, result.Feature, StringComparison.Ordinal) > 0)) {
+            if (version > maxVersion ||
+                // This is how the client resolves same version matches. Dumb as bricks.
+                (version == maxVersion && (result == null || string.Compare(entry.Feature, result.Feature, StringComparison.Ordinal) > 0))) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (version > maxVersion ||
// This is how the client resolves same version matches. Dumb as bricks.
(version == maxVersion && string.Compare(entry.Feature, result.Feature, StringComparison.Ordinal) > 0)) {
if (version > maxVersion ||
// This is how the client resolves same version matches. Dumb as bricks.
(version == maxVersion && (result == null || string.Compare(entry.Feature, result.Feature, StringComparison.Ordinal) > 0))) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Maple2.File.Generator/Resource/FeatureLocaleFilter.cs` around lines 68 - 70,
The tie-breaker condition in FeatureLocaleFilter that reads (version ==
maxVersion && string.Compare(entry.Feature, result.Feature,
StringComparison.Ordinal) > 0) can dereference result (default(T) / null) when
the first seen entry has version == maxVersion (e.g. Features[entry.Feature] ==
-1); modify the condition to first check result == null before accessing
result.Feature so that any entry at the same version always replaces a null
result. In practice update the if in the method using variables version,
maxVersion, entry and result to: if (version > maxVersion || (version ==
maxVersion && (result == null || string.Compare(entry.Feature, result.Feature,
StringComparison.Ordinal) > 0))) so result is not dereferenced.

@AngeloTadeucci AngeloTadeucci merged commit 714f64d into MS2Community:master May 4, 2026
3 checks passed
@Zintixx Zintixx deleted the filter-fix branch May 5, 2026 03:33
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