migrate core library to use nullable reference types - #157
Draft
hahn-kev wants to merge 6 commits into
Draft
Conversation
…o 9, and add PolySharp to be able to use nullible attributes.
This comment was marked as outdated.
This comment was marked as outdated.
* Address NRT review feedback and clear remaining warnings - MapToExistingLanguageIfPossible now returns the empty string (not null) for empty input, honoring its [return: NotNullIfNotNull] contract. - Removed the incorrect [MemberNotNullWhen(false, Id, Source, Target)] from XLiffTransUnit.IsEmpty: IsEmpty is a conjunction, so !IsEmpty does not imply all three members are non-null. Adjusted ToString and XLiffBody.AddTransUnitRaw, which relied on that bogus guarantee. - DefaultInstalledStringFilePath now throws a clear InvalidOperationException instead of passing a possibly-null folder to Path.Combine. - StringCache is backed by a nullable field and throws a clear InvalidOperationException instead of being `null!` and NREing when the minimal constructor was used. - MergeXliffDocuments hoists the trans-unit id once per iteration and skips units without one, replacing ten null-forgiving `tu.Id!` uses. - Fixed the four remaining warnings: CS8604 in XLiffBody (hoisted documented locals) and CS8618 for DefaultStringFilePath (defaults to string.Empty). Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
imnasnainaec
marked this pull request as draft
September 9, 2026 13:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
After seeing some fixes from @imnasnainaec, I figured I'd try my hand at enabling NRT and fixing some issues that came up.
There's currently 4 warnings still in place, I wasn't sure what the right call would be, so we can leave them in or come up with a fix together. They are:
There's a lot of code that used
XLiffTransUnit.Idwith the assumption that it's not null, however it can be, I've fixed many of those.Some places I've added checks like
if x is null throw new exceptionthis is only in cases where we would have thrown anyway when accessing a property on x later down, so while this may not fix a bug, it does give much better feedback as to what was null.There's a few places where code may have been returning null, which are now returning an empty string, these were changed due to the method already returning an empty string elsewhere, with the assumption that the method was written to never return null, and these cases were missed.
One change I did make is to constrain
ILocalizationManagerInternal<T>T to only be a class, this may effect consumers, but I don't think that's possible as the only implementation of this internal interface is a T ofXLiffDocument, and I think if anything else were to be used there would be a crash at runtime, so I don't think it's a problem.This change is