Gavin Williams details accidental CLR backdoors on DOTNET-CLR list
Here's the problem in a nutshell: Because class instances are always passed by reference and are often mutable, it is very easy to accidentally create back doors in your classes, causing:
1. Unexpected changes in internal state 2. Race conditions in methods executing asynchronously 3. Modification of properties you thought were read-only ("immutability leakage", a special case of #1)
He gives an example of problem #3 in System.Net code:
using System.Net; class Main { static void Main(string[] args) { IPAddress ip = IPAddress.Loopback;
// Do something interesting with ip...
// Now set a new value ip.Address = 2345235;
// Congratulations! // You've just changed IPAddress.Loopback to // 19.201.35.0 // and broken the IPAddress.IsLoopback method. } }
So far, the discussion on the list offers no solutions to what appers to be pretty serious problem.
|