Over a million developers have joined DZone.
Platinum Partner

Challenge: Spot the Bug

· Agile Zone

The Agile Zone is brought to you in partnership with DZone Software. Build your own privately managed community, like Stack Overflow, for your team with AnswerHub, a DZone Software product. 

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?



The Agile Zone is brought to you in partnership with DZone Software. Capture, organize, and share your team’s knowledge with AnswerHub, a DZone Software product. Designed for developer teams, by developers.

Topics:

Published at DZone with permission of Ayende Rahien , DZone MVB .

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}