Fix StringBuilder concurrency crash in JdkInfo.GetJavaProperties#337
Merged
jonathanpeppers merged 3 commits intomainfrom Apr 27, 2026
Merged
Fix StringBuilder concurrency crash in JdkInfo.GetJavaProperties#337jonathanpeppers merged 3 commits intomainfrom
jonathanpeppers merged 3 commits intomainfrom
Conversation
ProcessUtils.Exec hooks both OutputDataReceived and ErrorDataReceived to the same handler, which fire on separate background threads. The handler accesses shared mutable state (StringBuilder, Dictionary, etc.) without synchronization, causing ArgumentException crashes. Add a lock around the entire callback body to serialize access. Agent-Logs-Url: https://github.com/dotnet/android-tools/sessions/951b65a7-f1cc-4e46-9ea5-f8bc2a7ad108 Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix macOS CI test host crash in JdkInfo.GetJavaProperties
Fix StringBuilder concurrency crash in JdkInfo.GetJavaProperties
Apr 23, 2026
Narrow the lock to just the output.AppendLine() call since the StringBuilder is the only shared state causing the crash. The property parsing state (props, curKey, foundPS) is only meaningfully modified by stderr data. Lock on the StringBuilder instance directly instead of a separate gate object. Agent-Logs-Url: https://github.com/dotnet/android-tools/sessions/77b6b815-b6d2-4fb8-8cfc-d8452c742f43 Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a CI crash in Xamarin.Android.Tools.AndroidSdk JDK property discovery by making JdkInfo.GetJavaProperties() safe when ProcessUtils.Exec() invokes the same DataReceivedEventHandler concurrently from both stdout and stderr threads.
Changes:
- Serialize writes to the shared
StringBuilderused for capturingjavaoutput by adding alockaroundoutput.AppendLine(e.Data).
jonathanpeppers
approved these changes
Apr 23, 2026
simonrozsival
approved these changes
Apr 27, 2026
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.
ProcessUtils.Execsubscribes the same handler to bothOutputDataReceivedandErrorDataReceived, which fire on separate threads. The handler inGetJavaPropertiesappends to a sharedStringBuilderwithout synchronization, causingArgumentException: Destination is too shortcrashes in CI.lockaround theStringBuilder.AppendLine()call to serialize access to the sharedStringBuilderThe lock is scoped to just the
StringBuildersince Java outputs property settings to stderr and version info to stdout — the property parsing state (props,curKey,foundPS) is only meaningfully modified by stderr data and doesn't have concurrent writers.