Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Rossignoli <marco.rossignoli@gmail.com>2017-12-29 22:49:39 +0300
committerKrzysztof Wicher <mordotymoja@gmail.com>2017-12-29 22:49:39 +0300
commit270be00f569abea3b4b7fb6e0191130e50b17ecf (patch)
treeb9e0eebe2c12e947db7b64ba5d18675e27285feb /src/System.Private.Xml
parenta011ef1f49a4409c5ed2cb04b9aa7a89476127df (diff)
"Don't directly throw Exception" System.Private.Xml (#25975)
* Don't directly throw Exception * Don't directly throw Exception * Don't directly throw Exception * Don't directly throw Exception * Fix test
Diffstat (limited to 'src/System.Private.Xml')
-rw-r--r--src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs2
-rw-r--r--src/System.Private.Xml/src/System/Xml/Serialization/Xmlcustomformatter.cs4
-rw-r--r--src/System.Private.Xml/src/System/Xml/Xsl/Xslt/XPathPatternBuilder.cs15
-rw-r--r--src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs14
4 files changed, 25 insertions, 10 deletions
diff --git a/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs b/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs
index c27937f055..f9f7084fd6 100644
--- a/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs
+++ b/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs
@@ -3593,7 +3593,7 @@ namespace System.Xml
ThrowInvalidChar(_ps.chars, _ps.charsUsed, _ps.charPos + offset);
}
//should never hit here
- throw new Exception();
+ throw new XmlException(SR.Xml_InternalError);
}
private async Task<ValueTuple<int, int, int, bool>> ParseTextAsync_ReadData(int outOrChars, char[] chars, int pos, int rcount, int rpos, int orChars, char c)
diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/Xmlcustomformatter.cs b/src/System.Private.Xml/src/System/Xml/Serialization/Xmlcustomformatter.cs
index d13835b485..15a19486e8 100644
--- a/src/System.Private.Xml/src/System/Xml/Serialization/Xmlcustomformatter.cs
+++ b/src/System.Private.Xml/src/System/Xml/Serialization/Xmlcustomformatter.cs
@@ -77,7 +77,7 @@ namespace System.Xml.Serialization
return FromXmlNmTokens((string)value);
}
}
- throw new Exception(SR.Format(SR.XmlUnsupportedDefaultType, type.FullName));
+ throw new XmlException(SR.Format(SR.XmlUnsupportedDefaultType, type.FullName));
}
internal static string FromDate(DateTime value)
@@ -243,7 +243,7 @@ namespace System.Xml.Serialization
{
return ToXmlNmTokens(value);
}
- throw new Exception(SR.Format(SR.XmlUnsupportedDefaultValue, formatter));
+ throw new XmlException(SR.Format(SR.XmlUnsupportedDefaultValue, formatter));
// Debug.WriteLineIf(CompModSwitches.XmlSerialization.TraceVerbose, "XmlSerialization::Unhandled default value " + value + " formatter " + formatter);
// return DBNull.Value;
}
diff --git a/src/System.Private.Xml/src/System/Xml/Xsl/Xslt/XPathPatternBuilder.cs b/src/System.Private.Xml/src/System/Xml/Xsl/Xslt/XPathPatternBuilder.cs
index e72d268b38..8c1fdc941e 100644
--- a/src/System.Private.Xml/src/System/Xml/Xsl/Xslt/XPathPatternBuilder.cs
+++ b/src/System.Private.Xml/src/System/Xml/Xsl/Xslt/XPathPatternBuilder.cs
@@ -321,14 +321,15 @@ namespace System.Xml.Xsl.Xslt
}
public QilNode String(string value) { return _f.String(value); } // As argument of id() or key() function
- public QilNode Number(double value) { return UnexpectedToken("Literal number"); }
- public QilNode Variable(string prefix, string name) { return UnexpectedToken("Variable"); }
-
- private QilNode UnexpectedToken(string tokenName)
+ public QilNode Number(double value)
+ {
+ //Internal Error: Literal number is not allowed in XSLT pattern outside of predicate.
+ throw new XmlException(SR.Xml_InternalError);
+ }
+ public QilNode Variable(string prefix, string name)
{
- string prompt = string.Format(CultureInfo.InvariantCulture, "Internal Error: {0} is not allowed in XSLT pattern outside of predicate.", tokenName);
- Debug.Assert(false, prompt);
- throw new Exception(prompt);
+ //Internal Error: Variable is not allowed in XSLT pattern outside of predicate.
+ throw new XmlException(SR.Xml_InternalError);
}
// -------------------------------------- Priority / Parent ---------------------------------------
diff --git a/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs b/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs
index dc004d5b83..1cf0d23b3c 100644
--- a/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs
+++ b/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs
@@ -1936,6 +1936,20 @@ public static partial class XmlSerializerTests
Assert.False(xmp.CheckSpecified);
}
+ [Fact]
+ public static void XmlSchemaExporter_ExportMembersMapping_NotSupportedDefaultValue()
+ {
+ XmlReflectionImporter importer = new XmlReflectionImporter("http://www.contoso.com/");
+ XmlReflectionMember[] members = new XmlReflectionMember[1];
+ XmlReflectionMember member = members[0] = new XmlReflectionMember();
+ member.MemberType = typeof(TypeWithQNameArrayAsXmlAttributeInvalidDefaultValue);
+ XmlMembersMapping mappings = importer.ImportMembersMapping("root", "", members, true);
+ XmlMemberMapping xmp = mappings[0];
+ XmlSchemas schema = new XmlSchemas();
+ XmlSchemaExporter exporter = new XmlSchemaExporter(schema);
+ AssertExtensions.Throws<XmlException,Exception>(() => exporter.ExportMembersMapping(mappings));
+ }
+
[Fact]
public static void XmlSerializerVersionAttributeTest()
{