Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom Fulton 2030 posts 4998 karma points c-trib
    Oct 27, 2010 @ 20:43
    Tom Fulton
    0

    Bug (and fix) for exception with Numeric sorting

    Hi Matt,

    Finally got a chance to use this awesome package recently!  I ran into a bug when using Numeric sorting, if you try to create a new document, you get the exception below.  I did some debugging and it appears to be because the field doesn't have a value yet, but it's coming through as "" instead of null.  The code has a check for null but not "".

    The exception also happens in some cases when you delete the value of the numeric field on other nodes.

    I seem to have fixed by changing the commented lines to the ones below, in the NumericComparer:

                //var xNum = (x.Field == null) ? int.MaxValue : Convert.ToInt32(x.Field);
                //var yNum = (y.Field == null) ? int.MaxValue : Convert.ToInt32(y.Field);
                var xNum = (String.IsNullOrEmpty(x.Field.ToString())) ? int.MaxValue : Convert.ToInt32(x.Field);
                var yNum = (String.IsNullOrEmpty(y.Field.ToString())) ? int.MaxValue : Convert.ToInt32(y.Field);

    I suspect the same thing is also happening in the AlphaComparer, but probably not as big an issue since an exception isn't raised.  It also looks to be receiving "" instead of null and therefore doesn't seem to be assigning the "zzz.." value, causing the new node to be sorted first.

    Anyway, thought I'd let you know.  I would be glad to try and update on codeplex if it would help, I've never done that so wanted to post here first :)

    Thanks,
    Tom

    The Exception was:

     

    Input string was not in a correct format.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.FormatException: Input string was not in a correct format.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

     

    [FormatException: Input string was not in a correct format.]
      
    System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +12630485
      
    System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +224
      
    TheOutfield.UmbExt.DocumentSorter.NumericComparer.Compare(SimpleDocument x, SimpleDocument y) +307
      
    System.Collections.Generic.ArraySortHelper`1.SwapIfGreaterWithItems(T[] keys, IComparer`1 comparer, Int32 a, Int32 b) +145
      
    System.Collections.Generic.ArraySortHelper`1.QuickSort(T[] keys, Int32 left, Int32 right, IComparer`1 comparer) +524
      
    System.Collections.Generic.ArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer) +205

    [InvalidOperationException: Failed to compare two elements in the array.]
      
    System.Collections.Generic.ArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer) +12682246
      
    System.Collections.Generic.List`1.Sort(Int32 index, Int32 count, IComparer`1 comparer) +118
      
    TheOutfield.UmbExt.DocumentSorter.ApplicationBase.Document_Sort(Document doc, Object e) +3270
      
    umbraco.cms.businesslogic.web.SaveEventHandler.Invoke(Document sender, SaveEventArgs e) +0
      
    umbraco.cms.businesslogic.web.Document.FireAfterSave(SaveEventArgs e) +131
      
    umbraco.cms.businesslogic.web.Document.Save() +318
      
    umbraco.cms.presentation.editContent.Save(Object sender, EventArgs e) +2849
      
    System.EventHandler.Invoke(Object sender, EventArgs e) +0
      
    umbraco.controls.ContentControl.saveClick(Object Sender, ImageClickEventArgs e) +791
      
    umbraco.controls.ContentControl.savePublish(Object Sender, ImageClickEventArgs e) +73
      
    System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +178
      
    System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +165
      
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 28, 2010 @ 09:40
    Matt Brailsford
    0

    Hi Tom,

    Nice work.

    I'd probably be tempted to change it slightly though to the following:

    var xNum = (x.Field != null && x.Field.ToString() != string.Empty) ? int.MaxValue : Convert.ToInt32(x.Field);
    var yNum = (y.Field != null && y.Field.ToString() != string.Empty) ? int.MaxValue : Convert.ToInt32(y.Field);

    Just because I think calling ToString() on a null would cause an excepetion also.

    You are more than welcome to submit a patch, as I'm always on the lookout for people to help out on these packages (I have a fair few now, and this is one of the ones lower down on my priority list, so any fixes the community want to submit or definatley a good thing).

    All the best

    Matt

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Oct 28, 2010 @ 22:04
    Tom Fulton
    0

    Hi Matt,

    Makes sense, thanks.  I'll have a look at adding to Codeplex tomorrow.  I know you are busy working on other awesome packages :)

    -Tom

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 29, 2010 @ 09:23
    Matt Brailsford
    0

    Great stuff

    Thanks Tom

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft