IGNITE-4185 .NET: Fix NullReferenceException in IgniteOutputCacheProvider when igniteConfiguration is missing
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d775ad12 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d775ad12 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d775ad12 Branch: refs/heads/master Commit: d775ad12a8eedce5d3bd80c296de76b9ca2d49b7 Parents: 986e276 Author: Pavel Tupitsyn <[email protected]> Authored: Tue Nov 8 19:13:48 2016 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Wed Nov 9 19:53:44 2016 +0300 ---------------------------------------------------------------------- .../Apache.Ignite.AspNet.Tests/App.config | 1 + .../IgniteSessionStateStoreProviderTest.cs | 21 +++++++++++++++++--- .../Apache.Ignite.AspNet/Impl/ConfigUtil.cs | 5 +++++ 3 files changed, 24 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/d775ad12/modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/App.config ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/App.config b/modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/App.config index 86ee3d4..7d2c1d0 100644 --- a/modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/App.config +++ b/modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/App.config @@ -22,6 +22,7 @@ <section name="igniteConfiguration" type="Apache.Ignite.Core.IgniteConfigurationSection, Apache.Ignite.Core" /> <section name="igniteConfiguration2" type="Apache.Ignite.Core.IgniteConfigurationSection, Apache.Ignite.Core" /> <section name="igniteConfiguration3" type="Apache.Ignite.Core.IgniteConfigurationSection, Apache.Ignite.Core" /> + <section name="igniteConfigurationInvalid" type="Apache.Ignite.Core.IgniteConfigurationSection, Apache.Ignite.Core" /> </configSections> <runtime> http://git-wip-us.apache.org/repos/asf/ignite/blob/d775ad12/modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/IgniteSessionStateStoreProviderTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/IgniteSessionStateStoreProviderTest.cs b/modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/IgniteSessionStateStoreProviderTest.cs index 2c73359..9c3b07c 100644 --- a/modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/IgniteSessionStateStoreProviderTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/IgniteSessionStateStoreProviderTest.cs @@ -19,6 +19,7 @@ namespace Apache.Ignite.AspNet.Tests { using System; using System.Collections.Specialized; + using System.Configuration; using System.Linq; using System.Reflection; using System.Threading; @@ -116,14 +117,28 @@ namespace Apache.Ignite.AspNet.Tests Assert.Throws<InvalidOperationException>(() => stateProvider.GetItem(HttpContext, Id, out locked, out lockAge, out lockId, out actions)); - // Invalid section. - Assert.Throws<IgniteException>(() => + // Missing section. + var ex = Assert.Throws<IgniteException>(() => stateProvider.Initialize("testName", new NameValueCollection { - {SectionNameAttr, "invalidSection"}, + {SectionNameAttr, "missingSection"}, {CacheNameAttr, CacheName} })); + Assert.IsInstanceOf<ConfigurationErrorsException>(ex.InnerException); + + // Invalid section with missing content. + stateProvider = new IgniteSessionStateStoreProvider(); + + ex = Assert.Throws<IgniteException>(() => + stateProvider.Initialize("testName", new NameValueCollection + { + {SectionNameAttr, "igniteConfigurationInvalid"}, + {CacheNameAttr, CacheName} + })); + + Assert.IsInstanceOf<ConfigurationErrorsException>(ex.InnerException); + // Valid grid. stateProvider = GetProvider(); http://git-wip-us.apache.org/repos/asf/ignite/blob/d775ad12/modules/platforms/dotnet/Apache.Ignite.AspNet/Impl/ConfigUtil.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.AspNet/Impl/ConfigUtil.cs b/modules/platforms/dotnet/Apache.Ignite.AspNet/Impl/ConfigUtil.cs index a162d81..fc93c7e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.AspNet/Impl/ConfigUtil.cs +++ b/modules/platforms/dotnet/Apache.Ignite.AspNet/Impl/ConfigUtil.cs @@ -86,6 +86,11 @@ namespace Apache.Ignite.AspNet.Impl "Could not find {0} with name '{1}'", typeof(IgniteConfigurationSection).Name, sectionName)); config = section.IgniteConfiguration; + + if (config == null) + throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, + "{0} with name '{1}' is defined in <configSections>, but not present in configuration", + typeof(IgniteConfigurationSection).Name, sectionName)); } else config = new IgniteConfiguration {GridName = gridName};
