Project
ReSharper
Priority
Normal
Type
Bug
Fix versions
4.1
State
Fixed
Assignee
Evgeny Pasynkov
Subsystem
No subsystem
Affected versions
No Affected versions
Fixed in build
5.0.1612.107  
  • Created by   Ron Gross
    3 years ago (28 Jul 2008 13:23)
  • Updated by   Ron Gross
    3 years ago (29 Jul 2008 14:05)
  • Jira: RSRP-75982
    (history, comments)
 
RSRP-75982 Refactoring "parameter can be declared as value" introduces bugs
0
Issue is visible to: All Users
  The issue is visible to the selected user group only
The version is 4.0.819.19

I applied this refactoring and it introduced bugs - a method can wait for external modification of a value by another thread.



private void Foo()
{
bool b = false;
new Thread((ThreadStart)delegate { b = true;}).Start();
WaitForBool(ref b);
}

private void WaitForBool(ref bool b)
{
while (!b)
{
Thread.Sleep(1000);
}
}

See
http://qimmortal.blogspot.com/2008/07/my-arrogance-in-finding-bugs.html

Issue was closed
Comments (4)
 
History
 
Linked Issues (?)
 
TeamCity Changes (0)
 
Ilya Ryzhenkov
  Ilya Ryzhenkov
28 Jul 2008 15:22
3 years ago
It turns out that this suggestion can never be triggered for value types?
Ron Gross
  Ron Gross
28 Jul 2008 18:35
3 years ago
I guess so, unfortunately (barring global analysis).
Vladimir Reshetnikov
  Vladimir Reshetnikov
29 Jul 2008 13:47
3 years ago
The same problem for reference types:

class A
{
    private void Foo()
    {
        string b = null;
        new Thread((ThreadStart)delegate { b = ""; }).Start();
        WaitForString(ref b);
    }

    private void WaitForString(ref string b)
    {
        while (b==null)
        { Thread.Sleep(1000); }

    }
}
Ron Gross
  Ron Gross
29 Jul 2008 14:05
3 years ago
Crap.

Too bad, in most cases it does look like a useful refactor. Can it be categorized as a different class of hint ? (something to urge the developer to pay more attention when he applies it)