Program: 130521
Project: 130521
Buggy source:
public static DotNetTypeRef extractToCSharp(DotNetTypeRef typeRef,PsiElement scope){
  if (typeRef == DotNetTypeRef.ERROR_TYPE) {
    return DotNetTypeRef.ERROR_TYPE;
  }
  if (typeRef instanceof MsilNativeTypeRefImpl) {
    String qualifiedText=typeRef.getQualifiedText();
    boolean nullable=false;
    if (DotNetTypes.System.Object.equals(qualifiedText) || DotNetTypes.System.String.equals(qualifiedText)) {
      nullable=true;
    }
    return new DotNetTypeRefByQName(typeRef.getQualifiedText(),CSharpTransform.INSTANCE,nullable);
  }
 else   if (typeRef instanceof MsilArrayTypRefImpl) {
    return new CSharpArrayTypeRef(extractToCSharp(((MsilArrayTypRefImpl)typeRef).getInnerTypeRef(),scope),0);
  }
 else   if (typeRef instanceof DotNetPointerTypeRef) {
    return new DotNetPointerTypeRefImpl(extractToCSharp(((DotNetPointerTypeRef)typeRef).getInnerTypeRef(),scope));
  }
 else   if (typeRef instanceof DotNetRefTypeRef) {
    return new CSharpRefTypeRef(CSharpRefTypeRef.Type.ref,extractToCSharp(((DotNetRefTypeRef)typeRef).getInnerTypeRef(),scope));
  }
 else   if (typeRef instanceof DotNetGenericWrapperTypeRef) {
    val inner=extractToCSharp(((DotNetGenericWrapperTypeRef)typeRef).getInnerTypeRef(),scope);
    DotNetTypeRef[] arguments=((DotNetGenericWrapperTypeRef)typeRef).getArgumentTypeRefs();
    DotNetTypeRef[] newArguments=new DotNetTypeRef[arguments.length];
    for (int i=0; i < newArguments.length; i++) {
      newArguments[i]=extractToCSharp(arguments[i],scope);
    }
    return new DotNetGenericWrapperTypeRef(inner,newArguments);
  }
  return new MsilDelegateTypeRef(typeRef);
}

Fixed version (ground truth):
public static DotNetTypeRef extractToCSharp(DotNetTypeRef typeRef,PsiElement scope){
  if (typeRef == DotNetTypeRef.ERROR_TYPE) {
    return DotNetTypeRef.ERROR_TYPE;
  }
  if (typeRef instanceof MsilNativeTypeRefImpl) {
    String qualifiedText=typeRef.getQualifiedText();
    boolean nullable=false;
    if (DotNetTypes.System.Object.equals(qualifiedText) || DotNetTypes.System.String.equals(qualifiedText)) {
      nullable=true;
    }
    return new DotNetTypeRefByQName(typeRef.getQualifiedText(),CSharpTransform.INSTANCE,nullable);
  }
 else   if (typeRef instanceof MsilArrayTypRefImpl) {
    return new CSharpArrayTypeRef(extractToCSharp(((MsilArrayTypRefImpl)typeRef).getInnerTypeRef(),scope),0);
  }
 else   if (typeRef instanceof DotNetPointerTypeRef) {
    return new DotNetPointerTypeRefImpl(extractToCSharp(((DotNetPointerTypeRef)typeRef).getInnerTypeRef(),scope));
  }
 else   if (typeRef instanceof DotNetRefTypeRef) {
    return new CSharpRefTypeRef(CSharpRefTypeRef.Type.ref,extractToCSharp(((DotNetRefTypeRef)typeRef).getInnerTypeRef(),scope));
  }
 else   if (typeRef instanceof DotNetGenericWrapperTypeRef) {
    val inner=extractToCSharp(((DotNetGenericWrapperTypeRef)typeRef).getInnerTypeRef(),scope);
    DotNetTypeRef[] arguments=((DotNetGenericWrapperTypeRef)typeRef).getArgumentTypeRefs();
    DotNetTypeRef[] newArguments=new DotNetTypeRef[arguments.length];
    for (int i=0; i < newArguments.length; i++) {
      newArguments[i]=extractToCSharp(arguments[i],scope);
    }
    return new DotNetGenericWrapperTypeRef(inner,newArguments);
  }
  PsiElement resolve=typeRef.resolve(scope);
  if (resolve instanceof DotNetTypeDeclaration) {
    CSharpMethodDeclaration delegateMethod=wrapToDelegateMethod((DotNetTypeDeclaration)resolve);
    if (delegateMethod != null) {
      return new CSharpLambdaTypeRef(delegateMethod);
    }
  }
  return new MsilDelegateTypeRef(typeRef);
}