Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Guard deserialization and collection nullability in release builds.
Debug.Asserton Line 229 and Line 239 won’t protect Release builds;data.setting(Line 231) anddata.feature(Line 241) can still throwNullReferenceException.🛠️ Proposed defensive fix
public IEnumerable<(string Type, Setting Setting)> ParseFeatureSetting() { XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("table/feature_setting.xml")); - var data = featureSettingSerializer.Deserialize(reader) as FeatureSetting;- Debug.Assert(data != null);+ FeatureSetting data = featureSettingSerializer.Deserialize(reader) as FeatureSetting+ ?? throw new InvalidDataException("Failed to deserialize table/feature_setting.xml");- foreach (Setting setting in data.setting) {+ foreach (Setting setting in data.setting ?? Enumerable.Empty<Setting>()) { yield return (setting.type, setting); } } public IEnumerable<(string Name, Feature Feature)> ParseFeature() { XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("table/feature.xml")); - var data = featureSerializer.Deserialize(reader) as FeatureRoot;- Debug.Assert(data != null);+ FeatureRoot data = featureSerializer.Deserialize(reader) as FeatureRoot+ ?? throw new InvalidDataException("Failed to deserialize table/feature.xml");- foreach (Feature feature in data.feature) {+ foreach (Feature feature in data.feature ?? Enumerable.Empty<Feature>()) { yield return (feature.name, feature); } }Also applies to: 238-243
🤖 Prompt for AI Agents