OpenDDRdotORG / OpenDDR-CSharp

C# Implementation of OpenDDR-Simple-API
https://github.com/OpenDDRmobi/openddr-csharp/
GNU General Public License v3.0
5 stars 3 forks source link

null ref in TwoStepDeviceBuilder.ElaborateTwoStepDeviceWithToken with some user agent strings from googlebot and bingbot #3

Open jamesmanning opened 11 years ago

jamesmanning commented 11 years ago
Exception type: NullReferenceException 
Exception message: Object reference not set to an instance of an object.
   at Oddr.Builders.Devices.TwoStepDeviceBuilder.ElaborateTwoStepDeviceWithToken(UserAgent userAgent, String step1Token, String step2Token)
   at Oddr.Builders.Devices.TwoStepDeviceBuilder.Build(UserAgent userAgent, Int32 confidenceTreshold)
   at Oddr.Identificators.DeviceIdentificator.Get(UserAgent userAgent, Int32 confidenceTreshold)
   at Oddr.ODDRService.GetPropertyValues(IEvidence evdnc, IPropertyRef[] prs)
   at Oddr.ODDRService.GetPropertyValue(IEvidence evdnc, IPropertyRef pr)

User agent strings that appear to trigger it include these (the +'s are there

bubbafat commented 11 years ago

The problem is that in TwoStepDeviceBuilder.AferOrderingCompleteInit the collection orderedRules is modified during enumeration. It causes an exception to be thrown which results in the devices field to never be set which results in the null ref exception in ElaborateTwoStepDeviceWithToken

bubbafat commented 11 years ago

This fixes it.

    protected override void AfterOrderingCompleteInit(Dictionary<string, Device> devices)
    {
        List<string> keys = new List<string>();
        foreach (string key in orderedRules.Keys)
        {
            keys.Add(key);
        }

        foreach (String step1Token in keys)
        {

            SortElement(step1Token);
        }...