-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Remove always true "if" and unreachable code in System.Xml.Linq.XObject.SkipNotify method. #13863
Comments
As mentioned on this pull request dotnet/corefx#55, we'd like to see some test coverage proving the bug, before we fix the bug. |
I want to fix this issue. Regarding @davkean comment in dotnet/corefx#55 I found out the following: If we check the C# 5.0 Language Specification, section 10.14.4 states (in part): Then, by design, a call to a function defining an iterator block (such as yield) returns an enumerator object whose MoveNext method implements the function that uses the yield statement. As such, we have a guarantee that it is impossible for o.Annotations() to be null, since in ALL cases, we will receive an object. So it is impossible to create a test that will use that part of the code, since it is impossible for the method to return null. At the same time, we know for a fact that the method will always return an object and the check is redundant. |
Carlos's analysis is correct, you cannot write a test to "expose a bug" that can never occur. Rather, this is simple code-path analysis that calls out dead code. |
Sorry, I should clarify - I agree with the assessment of that the code is dead. However, I do not agree to the removal of said dead code, I would rather see the code changed to follow the spirit of which it was written (which appears to be to raise some Changing/Changed events). ie My statement is, write some tests that show that these Changing/Changed events do not fire when they are supposed to, and then change the code to make them fire. |
While pull request dotnet/corefx#55 is a correct interpretation of the original code, I believe the original code did not behave as intended. I believe the original code was meant to read as follows: if (o.Annotations<XObjectChangeAnnotation>().Any()) return false; If the condition was written like this, the meaning of the method would be:
As it was actually written, and as dotnet/corefx#55 preserved, the meaning of the method is:
|
#54 (Remove always true "if" and unreachable code in System.Xml.Linq.XObject.SkipNotify method.) Tests fails because XObject.Annotations<T>() returns an enumerator object which is always not null.
#54 (Remove always true "if" and unreachable code in System.Xml.Linq.XObject.SkipNotify method.) Uses XObject.Annotation<T>() method to check XObjectChangeAnnotation is present in XObject.annotations list
#54 (Remove always true "if" and unreachable code in System.Xml.Linq.XObject.SkipNotify method.) Uses XObject.Annotation<T>() method to check XObjectChangeAnnotation is present in XObject.annotations list
…tify-Fix Fixes #54 (Remove always true "if" and unreachable code in System.Xml.Linq.XObject.SkipNotify method.)
Restore `HttpConnectionResponseContent` from `release/2.1`.
This: if (o.Annotations() != null)
is always true because the above while can finish only in two conditions: when o != null or when o.annotations == null. The first condition will be catched by " if (o == null)" and if the second one is true, "o.Annotations() != null" will also always be true i think.
The text was updated successfully, but these errors were encountered: