Integer is too large for an Int32.

Jun 29, 2010 at 3:54 PM

Hi,

First off YamlSerializer is great! Many thanks for your hard work.

I have one bug report and one question:

If I have an integer valued double (ex. "315360126776046") the tag resolution rule recognizes it as an integer (even though it is too large for the int32 datatype) and then fails when trying to "Convert.ToInt32".

I think a fix could be adding another range term to the regex, but it seems more difficult than necessary.

My question is why the serializer is converting the number to a string and then parsing it back to a number in the first place when serializing?

 

Thanks again,

Andrew Hanlon 

 

Jun 29, 2010 at 4:30 PM

Hi again,

Temporarily I have used the following regex which checks for a number beneath the int.maxvalue number:

            AddRule<int>("!!int", @"^([-+]?[0-9]{1,9}|[0-1][0-9]{1,8}|20[0-9]{1,8}|21[0-3][0-9]{1,7}|214[0-6][0-9]{1,7}|2147[0-3][0-9]{1,6}|21474[0-7][0-9]{1,5}|214748[0-2][0-9]{1,4}|2147483[0-5][0-9]{1,3}|21474836[0-3][0-9]{1,2}|214748364[0-7]{1,1})$",                 m => Convert.ToInt32(m.Value.Replace("_", "")), null);

 

This works to eliminate the overflow issue.

best regards,

Coordinator
Jun 29, 2010 at 7:52 PM
Edited Jun 29, 2010 at 7:59 PM

Thanks for trying YamlSerializer and sending the report.

I confirmed the problem.

There, the serializer is trying to see if the node can be expressed in a plain style or not.
If not, it serializes the value in a quoted style or in a literal style, instead of in a plain style.

To judge it, the serializer invokes an trial decoding of the plain style expression and
see if it can be deserialized without any problem.
(YamlPresenter.cs: 213 -> YamlPresenter.cs: 244 = IsValidPlainText )

I agree with you that the trial decoding does not have to parse the string back to a
number or, at least, should not cause a runtime error. I'll look into the code and find
the best way to fix the problem. Your workaround is a good candidate but there
may be some more fundamental solution.

Thanks again for your report.

Best regards,
Osamu Takeuchi

Coordinator
Jun 30, 2010 at 12:43 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.