History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: RSRP-30924
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Eugene Pasynkov
Reporter: Andrey Simanovsky
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
ReSharper

NullReference analysis behaves strangely

Created: 01 Nov 06 16:51   Updated: 04 Jun 07 17:52
Component/s: Code Analysis
Fix Version/s: Future Versions
Security Level: Everybody (All jira users)

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 300


 Description  « Hide
public IClass GetClass(string qualifiedName, ClassCreateHandler classCreateHandler)
    {
      ITypeElement declaredElement = TypeChooser.GetDeclaredElement(qualifiedName);
      if (declaredElement == null && classCreateHandler(qualifiedName))
      {
        IDeclaration declaration = null;
        PsiManager manager = myConstructor.GetManager();
        CommandProcessor.Instance.BeginCommand("Create class");
        try
        {
          TransactionResult result = manager.DoTransaction(delegate
            {
              declaration = LanguageSpecificUtil.GetImplementation(myConstructor).LocateAndCreateClass(myConstructor, qualifiedName);
              if (declaration != null) manager.UpdateCaches();
            });
          if (!result.Succeded) declaration = null;
        }
        finally
        {
          CommandProcessor.Instance.EndCommand();
        }
        return declaration == null ? null : (IClass) declaration.DeclaredElement;
      }
      return declaredElement as IClass;
    }

I have possible null reference on last use of 'declaration', which may seem ok. Now I comment 'if (!result.Succeded) declaration = null;' and possible null reference disappears. Very fishy.



 All   Comments   Work Log   Change History      Sort Order:
Eugene Pasynkov - 17 May 07 19:46
Simplified sample:
public delegate void D();
class C
{
  public object Foo(bool cond)
  {
    object declaration = null;
    D d = delegate {declaration = new object();};
    if (cond) declaration = null;
    return declaration == null ? null : declaration.ToString();
  }
}

Eugene Pasynkov - 17 May 07 19:50
delegate void D();
class C
{
  public object Foo(bool cond)
  {
    object declaration;
    D d = delegate {declaration = null;};
    declaration = null;
    return declaration == null ? null : declaration.ToString();
  }
}