This is an automated email from the ASF dual-hosted git repository.
laimis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
The following commit(s) were added to refs/heads/master by this push:
new 4fde199 https://issues.apache.org/jira/browse/LUCENENET-607 (#224)
4fde199 is described below
commit 4fde199bf9937b421f63b073a32b34477b9416c1
Author: hindikaynen <[email protected]>
AuthorDate: Mon Mar 11 20:13:02 2019 +0300
https://issues.apache.org/jira/browse/LUCENENET-607 (#224)
* https://issues.apache.org/jira/browse/LUCENENET-607
GOOD_FAST_HASH_SEED thread safety
* LUCENENET-607 code-review: avoid static ctor
fixes LUCENENET-607
---
src/Lucene.Net/Util/StringHelper.cs | 70 ++++++++++++++++---------------------
1 file changed, 31 insertions(+), 39 deletions(-)
diff --git a/src/Lucene.Net/Util/StringHelper.cs
b/src/Lucene.Net/Util/StringHelper.cs
index 8d30354..fe2f12d 100644
--- a/src/Lucene.Net/Util/StringHelper.cs
+++ b/src/Lucene.Net/Util/StringHelper.cs
@@ -29,6 +29,37 @@ namespace Lucene.Net.Util
public abstract class StringHelper
{
/// <summary>
+ /// Pass this as the seed to <see cref="Murmurhash3_x86_32(byte[],
int, int, int)"/>. </summary>
+
+ //Singleton-esque member. Only created once
+ public static readonly int GOOD_FAST_HASH_SEED = InitializeHashSeed();
+
+ // Poached from Guava: set a different salt/seed
+ // for each JVM instance, to frustrate hash key collision
+ // denial of service attacks, and to catch any places that
+ // somehow rely on hash function/order across JVM
+ // instances:
+ private static int InitializeHashSeed()
+ {
+ string prop = SystemProperties.GetProperty("tests.seed", null);
+
+ if (prop != null)
+ {
+ // So if there is a test failure that relied on hash
+ // order, we remain reproducible based on the test seed:
+ if (prop.Length > 8)
+ {
+ prop = prop.Substring(prop.Length - 8);
+ }
+ return Convert.ToInt32(prop, 16);
+ }
+ else
+ {
+ return DateTime.Now.Millisecond;
+ }
+ }
+
+ /// <summary>
/// Compares two <see cref="BytesRef"/>, element by element, and
returns the
/// number of elements common to both arrays.
/// </summary>
@@ -179,45 +210,6 @@ namespace Lucene.Net.Util
}
/// <summary>
- /// Pass this as the seed to <see cref="Murmurhash3_x86_32(byte[],
int, int, int)"/>. </summary>
-
- // Poached from Guava: set a different salt/seed
- // for each JVM instance, to frustrate hash key collision
- // denial of service attacks, and to catch any places that
- // somehow rely on hash function/order across JVM
- // instances:
-
- //Singleton-esque member. Only created once
- private static int good_fast_hash_seed;
-
- public static int GOOD_FAST_HASH_SEED
- {
- get
- {
- if (good_fast_hash_seed == 0)
- {
- string prop = SystemProperties.GetProperty("tests.seed",
null);
-
- if (prop != null)
- {
- // So if there is a test failure that relied on hash
- // order, we remain reproducible based on the test
seed:
- if (prop.Length > 8)
- {
- prop = prop.Substring(prop.Length - 8);
- }
- good_fast_hash_seed = (int)Convert.ToInt32(prop, 16);
- }
- else
- {
- good_fast_hash_seed = (int)DateTime.Now.Millisecond;
- }
- }
- return good_fast_hash_seed;
- }
- }
-
- /// <summary>
/// Returns the MurmurHash3_x86_32 hash.
/// Original source/tests at <a
href="https://github.com/yonik/java_util/">https://github.com/yonik/java_util/</a>.
/// </summary>