-
Notifications
You must be signed in to change notification settings - Fork 110
Prevent issues when passing a zero-length list to MeasuredResults.ChangeChromatograms #3619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent issues when passing a zero-length list to MeasuredResults.ChangeChromatograms #3619
Conversation
…ograms. Passing a zero-length list causes issues with SequenceTree, undo/redo, Audit Log, and FilesTree. (1) Require callers to pass null to clear a non-empty list of chromatograms. Throw an exception except for one special case described below. (2) Allow passing a zero-length list when MeasuredResults already has no chromatograms. This case happens during XML deserialization. MoleculeDocumentSerializeTest fails unless this is allowed.
Below is the stack trace for the failure during XML deserialization. Stacktrace There is an error in XML document (40, 4). |
What was the code in your branch that was causing the problem? |
I will fix this PR. |
Agreed. Though, I also removed MeasuredResults.Empty, since it was only used in a single function that did not really need it. Having and Empty member just encouraged its use and potential to be set to SrmSettings. Having it around seemed confusing, since we use Empty in place of null in many places. Maybe if we wrote this code today we would use an Empty static, but I did not when I first wrote it and changing now seems not worth the effort. |
// 10.23.12 -- The order of <measured_results> and <data_settings> has been switched to enable parsing (in Panorama) | ||
// of all annotation definitions before reading any replicate annotations in <measured_results>. | ||
// We want Skyline to be able to read older documents where <measured_results> come before <data_settings> | ||
MeasuredResults NullIfEmpty(MeasuredResults val) |
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.
It would probably be cleaner if "NullIfEmpty" were a method on MeasuredResults:
public MeasuredResults NullIfEmpty() { return Chromatograms.Count == 0 ? null : this);}
Then you would do:
MeasuredResults = reader.DeserializeElement<MeasuredResults>()?.NullIfEmpty();
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.
My original implementation was in this direction, but I forgot about using ?.NullIfEmpty(). Yeah. That seems cleaner.
…x' of github.com:ProteoWizard/pwiz into Skyline/work/20251001_MeasuredResults_ZeroLengthList_Fix
Prevent a strange issue in MeasuredResults when calling ChangeChromatograms. Passing a zero-length list causes issues with SequenceTree, undo/redo, Audit Log, and FilesTree.
Instead:
(1) Require callers to pass null to clear a non-empty list of chromatograms. Throw an exception except for one special case described below.
(2) Allow passing a zero-length list when MeasuredResults already has no chromatograms. This case happens during XML deserialization. MoleculeDocumentSerializeTest fails unless this is allowed.