Platinum Partner
java,agile,computer science,tips and tricks

Challenge: Spot the Bug

Speaking of unfair interview questions, this would be a pretty evil one.

public MemoryMapPager(string file, FlushMode flushMode = FlushMode.Full)
{
     _flushMode = flushMode;
     var fileInfo = new FileInfo(file);
     if (fileInfo.Exists == false || file.Length == 0)
     {
          _allocatedPages = 0;
          fileInfo.Create().Close();
     }
     else
     {
          _allocatedPages = file.Length / PageSize;
     }
     _fileStream = fileInfo.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
}

Can you see the bug? How would you fix it?



Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}