From commits-return-6320-archive-asf-public=cust-asf.ponee.io@lucenenet.apache.org Tue Jul 9 21:29:23 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 4AC4318067E for ; Tue, 9 Jul 2019 23:29:21 +0200 (CEST) Received: (qmail 98679 invoked by uid 500); 9 Jul 2019 21:29:19 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 98055 invoked by uid 99); 9 Jul 2019 21:29:18 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Jul 2019 21:29:18 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 1CE5B87ADC; Tue, 9 Jul 2019 21:29:18 +0000 (UTC) Date: Tue, 09 Jul 2019 21:29:44 +0000 To: "commits@lucenenet.apache.org" Subject: [lucenenet] 28/29: Added missing guard clauses for HashMap and LinkedHashMap constructors MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: nightowl888@apache.org In-Reply-To: <156270775695.22198.7361892772101007504@gitbox.apache.org> References: <156270775695.22198.7361892772101007504@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: lucenenet X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: 66c27e106bf18e16024cdfbcc41aa0415a0611e2 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20190709212918.1CE5B87ADC@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git commit 66c27e106bf18e16024cdfbcc41aa0415a0611e2 Author: Shad Storhaug AuthorDate: Wed Jul 10 00:33:41 2019 +0700 Added missing guard clauses for HashMap and LinkedHashMap constructors --- src/Lucene.Net/Support/HashMap.cs | 11 +++++++++-- src/Lucene.Net/Support/LinkedHashMap.cs | 26 ++++++++++++++------------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Lucene.Net/Support/HashMap.cs b/src/Lucene.Net/Support/HashMap.cs index f099404..db8723e 100644 --- a/src/Lucene.Net/Support/HashMap.cs +++ b/src/Lucene.Net/Support/HashMap.cs @@ -107,6 +107,9 @@ namespace Lucene.Net.Support public HashMap(IEnumerable> other) : this(0) { + if (other == null) + throw new ArgumentNullException(nameof(other)); + foreach (var kvp in other) { Add(kvp.Key, kvp.Value); @@ -115,8 +118,12 @@ namespace Lucene.Net.Support internal HashMap(IDictionary wrappedDict, IEqualityComparer comparer) { - // LUCENENET TODO: Is this a bug? Shouldn't we be using the passed in comparer if non-null? - _comparer = /* comparer ?? */ EqualityComparer.Default; + if (wrappedDict == null) + throw new ArgumentNullException(nameof(wrappedDict)); + if (comparer == null) + throw new ArgumentNullException(nameof(comparer)); + + _comparer = comparer; _dict = wrappedDict; _hasNullValue = false; diff --git a/src/Lucene.Net/Support/LinkedHashMap.cs b/src/Lucene.Net/Support/LinkedHashMap.cs index e3d9c94..6019f6e 100644 --- a/src/Lucene.Net/Support/LinkedHashMap.cs +++ b/src/Lucene.Net/Support/LinkedHashMap.cs @@ -69,25 +69,27 @@ namespace Lucene.Net.Support #region Constructors public LinkedHashMap() + : this(0, EqualityComparer.Default) { - dict = new HashMap>>(); - list = new LinkedList>(); } public LinkedHashMap(IEqualityComparer comparer) + : this(0, comparer) { - dict = new HashMap>>(comparer); - list = new LinkedList>(); } public LinkedHashMap(int capacity) + : this(capacity, EqualityComparer.Default) { - dict = new HashMap>>(capacity); - list = new LinkedList>(); } public LinkedHashMap(int capacity, IEqualityComparer comparer) { + if (capacity < 0) + throw new ArgumentOutOfRangeException($"{nameof(capacity)} must be 0 or greater."); + if (comparer == null) + throw new ArgumentNullException(nameof(comparer)); + dict = new HashMap>>(capacity, comparer); list = new LinkedList>(); } @@ -95,9 +97,8 @@ namespace Lucene.Net.Support public LinkedHashMap(IEnumerable> source) { if (source == null) - { - throw new ArgumentNullException("source"); - } + throw new ArgumentNullException(nameof(source)); + var countable = source as ICollection; if (countable != null) { @@ -117,9 +118,10 @@ namespace Lucene.Net.Support public LinkedHashMap(IEnumerable> source, IEqualityComparer comparer) { if (source == null) - { - throw new ArgumentNullException("source"); - } + throw new ArgumentNullException(nameof(source)); + if (comparer == null) + throw new ArgumentNullException(nameof(comparer)); + var countable = source as ICollection; if (countable != null) {