Created
June 19, 2012 15:21
-
-
Save micahlmartin/2954744 to your computer and use it in GitHub Desktop.
Error Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Example of a basic bug that causes an infinite loop | |
public static IEnumerable<Filter> Create(IEnumerable<string> filters) | |
{ | |
if (filters == null) | |
throw new ArgumentNullException("filters"); | |
if (filters.Count() == 0) | |
throw new ArgumentException("At least 1 filter must be specified", "filters"); | |
var filterList = new List<Filter>(); | |
foreach (var filter in filters) | |
filterList.AddRange(Create(filters)); //<-- Causes infinite loop | |
return filterList; | |
} | |
public static IEnumerable<Filter> Create(string filter) | |
{ | |
if (string.IsNullOrEmpty(filter)) | |
return Enumerable.Empty<Filter>(); | |
if (SubSelector.IsMatch(filter)) | |
return GetFiltersFromSubSelector(filter); | |
return new List<Filter> { new Filter(filter, false) }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<Filter> Create(IEnumerable<string> filters) | |
{ | |
if (filters == null) | |
throw new ArgumentNullException("filters"); | |
if (filters.Count() == 0) | |
throw new ArgumentException("At least 1 filter must be specified", "filters"); | |
var filterList = new List<Filter>(); | |
foreach (var filter in filters) | |
filterList.AddRange(Create(filters)); | |
return filterList; | |
} | |
public static IEnumerable<Filter> Create(string filter) | |
{ | |
if (string.IsNullOrEmpty(filter)) | |
return Enumerable.Empty<Filter>(); | |
if (SubSelector.IsMatch(filter)) | |
return GetFiltersFromSubSelector(filter); | |
return new List<Filter> { new Filter(filter, false) }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Simple example of a possible IndexOutOfRangeException | |
public static string GetReturnAddress(Address value, Address target) | |
{ | |
var machine = target.Machine; | |
IPAddress ipAddress; | |
//see if the target is an IP address, if so, get our own local ip address | |
if (IPAddress.TryParse(machine, out ipAddress)) | |
{ | |
string myIp = null; | |
var networkInterfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); | |
foreach(var ni in networkInterfaces) | |
if (ni.OperationalStatus == OperationalStatus.Up && ni.NetworkInterfaceType != NetworkInterfaceType.Loopback) | |
{ | |
var ipProps = ni.GetIPProperties(); | |
if (ipProps.UnicastAddresses.Count > 0) //<-- checks if there is at least 1 adddress | |
{ | |
myIp = ipProps.UnicastAddresses[1].Address.ToString(); //<-- Grabs the 2nd address but there may be only one. | |
break; | |
} | |
} | |
if (myIp == null) | |
myIp = "127.0.0.1"; | |
return PREFIX_TCP + myIp + PRIVATE + value.Queue; | |
} | |
return PREFIX + GetFullPathWithoutPrefix(value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetReturnAddress(Address value, Address target) | |
{ | |
var machine = target.Machine; | |
IPAddress ipAddress; | |
//see if the target is an IP address, if so, get our own local ip address | |
if (IPAddress.TryParse(machine, out ipAddress)) | |
{ | |
string myIp = null; | |
var networkInterfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); | |
foreach(var ni in networkInterfaces) | |
if (ni.OperationalStatus == OperationalStatus.Up && ni.NetworkInterfaceType != NetworkInterfaceType.Loopback) | |
{ | |
var ipProps = ni.GetIPProperties(); | |
if (ipProps.UnicastAddresses.Count > 0) | |
{ | |
myIp = ipProps.UnicastAddresses[1].Address.ToString(); | |
break; | |
} | |
} | |
if (myIp == null) | |
myIp = "127.0.0.1"; | |
return PREFIX_TCP + myIp + PRIVATE + value.Queue; | |
} | |
return PREFIX + GetFullPathWithoutPrefix(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment