Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Challenge: Spot the Bug

DZone's Guide to

Challenge: Spot the Bug

· Agile Zone
Free Resource

See how three solutions work together to help your teams have the tools they need to deliver quality software quickly. Brought to you in partnership with CA Technologies

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?



Discover how TDM Is Essential To Achieving Quality At Speed For Agile, DevOps, And Continuous Delivery. Brought to you in partnership with CA Technologies

Topics:

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}