Bug 25895 - Wrong exception is thrown when calling System.Globalization.CharUnicodeInfo.GetNumericValue(string s, int index) with invalid index
Summary: Wrong exception is thrown when calling System.Globalization.CharUnicodeInfo.G...
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: master
Hardware: PC Windows
: Normal normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2015-01-09 17:36 UTC by nader
Modified: 2015-01-13 05:22 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description nader 2015-01-09 17:36:27 UTC
Based on the MSDN documentation, CharUnicodeInfo.GetNumericValue Method (string s, int index), should throw an ArgumentOutOfRangeException when being passed an invalid index. 

Exception	Condition
ArgumentNullException	s is null.
ArgumentOutOfRangeException	index is outside the range of valid indexes in s."
from http://msdn.microsoft.com/en-us/library/h5x38zsw(v=vs.110).aspx

Instead, an IndexOutOfRangeException is thrown. To reproduce this bug. Create a Xamarin Andriod project and call the following code snippet:

    string s = "test";
    Int32 index = -1;
    Double val = System.Globalization.CharUnicodeInfo.GetNumericValue(s, index);
catch (System.Exception e)
    return e.GetType().FullName;
    //expected result: "System.ArgumentOutOfRangeException"
    //actual result: "System.IndexOutOfRangeException"
return "-1";

Looking at the mono source code at 
(lines 289-294), Looks like the ArgumentOutOfRangeException is never thrown. Instead, after indexing s[index] at line 293, an IndexOutOfRangeException will be thrown. 

I've ran this on Visual Studio 2013 with the following Xamarin version:
Version: 4.16.0 (Business Edition)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39

The test was conducted on an Android 4.0.3 emulator
Comment 1 Sadik Ali 2015-01-12 05:45:03 UTC
I have checked this issue and I am able to reproduce this behavior.

When I call the CharUnicodeInfo.GetNumericValue(string s, int index) method I observed that it doesn't through the "System.ArgumentOutOfRangeException" exception instead of it throws the "System.IndexOutOfRangeException".

Screencast: http://www.screencast.com/t/21BHYM2yX

Build output: https://gist.github.com/RamChBachkheti/a11397f4fb3c4fa7eea8
Debug Output: https://gist.github.com/RamChBachkheti/2495fcb7b67a89a3d007

Additional Info: I have also checked this issue with console application on both VS and XS with same test case and observed that for console it is working fine. I am getting "System.ArgumentOutOfRangeException".

Screencast: http://www.screencast.com/t/5cyS0WLf

Environment Info:

Windows 6.2.9200.0 (64-bit)
Microsoft Visual Studio Professional 2012
Version 11.0.61030.00 Update 4
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

LightSwitch for Visual Studio 2012   04938-004-0033001-02335
Microsoft LightSwitch for Visual Studio 2012

Office Developer Tools   04938-004-0033001-02335
Microsoft Office Developer Tools

Team Explorer for Visual Studio 2012   04938-004-0033001-02335
Microsoft Team Explorer for Visual Studio 2012

Visual Basic 2012   04938-004-0033001-02335
Microsoft Visual Basic 2012

Visual C# 2012   04938-004-0033001-02335
Microsoft Visual C# 2012

Visual C++ 2012   04938-004-0033001-02335
Microsoft Visual C++ 2012

Visual F# 2012   04938-004-0033001-02335
Microsoft Visual F# 2012

Visual Studio 2012 Code Analysis Spell Checker   04938-004-0033001-02335
Microsoft® Visual Studio® 2012 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Visual Studio 2012 SharePoint Developer Tools   04938-004-0033001-02335
Microsoft Visual Studio 2012 SharePoint Developer Tools

ASP.NET and Web Tools   2012.3.41009
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Windows Azure Web Sites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Windows Azure

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone

NuGet Package Manager   2.6.40627.9000
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.0
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   11.1.20627.00
Microsoft SQL Server Data Tools

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin (7f1c1f6)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS (dfb682fa615491b012ed24198d2bdcd641e1874f)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 2 Marek Safar 2015-01-13 05:22:04 UTC
Fixed in master