Skip to content

Double(Single).Parse(string) and Double(Single).Parse(ReadOnlySpan<char) throws different exception for null #76442

@TrayanZapryanov

Description

@TrayanZapryanov
    please file an issue on that with repro, that sounds like a bug

Originally posted by @krwq in #75452 (comment)

This makes migration from string to ReadOnlySpan a bit tricky.
Repro:

//Parse with null

string test = null;
		ReadOnlySpan<char> ros = test.AsSpan().Trim();
		try
		{
			double dVal = double.Parse(ros, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo);
		}
		catch (FormatException){}

		try
		{
			double dVal = double.Parse(test, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo);
		}
		catch (ArgumentNullException) { }

		//Parse with empty
		string testEmpty = "";
		ReadOnlySpan<char> rosEmpty = testEmpty.AsSpan().Trim();
		try
		{
			double dVal = double.Parse(rosEmpty, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo);
		}
		catch (FormatException) { }

		try
		{
			double dVal = double.Parse(testEmpty, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo);
		}
		catch (FormatException) { }

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.RuntimequestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions