Skip to content

Apache Lucene open-source search software

SOLR-7493: Initialize random correctly

Shalin Shekhar Mangarc49d7b654e34
diff --git a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
index e374d8e5bad..35f89dd2ddc 100644
--- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
+++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
@@ -117,10 +117,16 @@ import org.slf4j.LoggerFactory;
public class HttpSolrCall {
protected static Logger log = LoggerFactory.getLogger(HttpSolrCall.class);
- protected static Random random;
+ static final Random random;
static {
+ // We try to make things reproducible in the context of our tests by initializing the random instance
+ // based on the current seed
String seed = System.getProperty("tests.seed");
- random = new Random(seed != null ? Long.parseLong(seed) : System.currentTimeMillis());
+ if (seed == null) {
+ random = new Random();
+ } else {
+ random = new Random(seed.hashCode());
+ }
}
protected final SolrDispatchFilter solrDispatchFilter;