Bug: ParseException.Details will crash when error does not provide a Details list

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug: ParseException.Details will crash when error does not provide a Details list

William Lahti
If you receive a ParseException and try to inspect it's Details property, it may crash if the exception has a null 'details' field, as get_Details tries to make a copy of the 'details' field without checking if it's null. 

Here's the exception I received:

System.ArgumentNullException: Collection cannot be null.
Parameter name: c
   at System.Collections.ArrayList..ctor(ICollection c)
   at PerCederberg.Grammatica.Runtime.ParseException.get_Details()
   ...

Here's the offending property:

       public ArrayList Details {
            get {
                return new ArrayList(details);
            }
        }

It's found at line 208 in src/csharp/PerCederberg.Grammatica.Runtime/ParseException.cs

The fix is easy:

       public ArrayList Details {
            get {
                if (details == null)
                       return new ArrayList (); // or just null, but an empty list makes more sense imho
                return new ArrayList(details);
            }
        }

Sorry I couldn't provide a patch, but I don't have a proper diff tool on this Windows box and it's a really minor change (though hard to get around without recompiling Grammatica).
--
rezonant

long name: William Lahti
handle :: rezonant
freenode :: xfury
blog :: http://xfurious.blogspot.com/
site :: http://komodocorp.com/~wilahti

_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: Bug: ParseException.Details will crash when error does not provide a Details list

Per Cederberg
Thanks for the bug report. I've added it to the bug tracker for the
next update to Grammatica:

https://savannah.nongnu.org/bugs/index.php?25986

Cheers,

/Per

2009/3/24 William Lahti <[hidden email]>:

> If you receive a ParseException and try to inspect it's Details property, it
> may crash if the exception has a null 'details' field, as get_Details tries
> to make a copy of the 'details' field without checking if it's null.
> Here's the exception I received:
> System.ArgumentNullException: Collection cannot be null.
> Parameter name: c
>    at System.Collections.ArrayList..ctor(ICollection c)
>    at PerCederberg.Grammatica.Runtime.ParseException.get_Details()
>    ...
> Here's the offending property:
>
>        public ArrayList Details {
>             get {
>                 return new ArrayList(details);
>             }
>         }
> It's found at line 208 in
> src/csharp/PerCederberg.Grammatica.Runtime/ParseException.cs
> The fix is easy:
>        public ArrayList Details {
>             get {
>                 if (details == null)
>                        return new ArrayList (); // or just null, but an
> empty list makes more sense imho
>                 return new ArrayList(details);
>             }
>         }
> Sorry I couldn't provide a patch, but I don't have a proper diff tool on
> this Windows box and it's a really minor change (though hard to get around
> without recompiling Grammatica).
> --
> rezonant
>
> long name: William Lahti
> handle :: rezonant
> freenode :: xfury
> blog :: http://xfurious.blogspot.com/
> site :: http://komodocorp.com/~wilahti
>
> _______________________________________________
> Grammatica-users mailing list
> [hidden email]
> http://lists.nongnu.org/mailman/listinfo/grammatica-users
>
>


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users