From 7a93c3e6f12ad30743bcb23647b5eed2a7c97905 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Fri, 21 Aug 2015 19:42:38 +0000 Subject: [PATCH] LUCENE-6752: Add Math#random() to forbiddenapis git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1697050 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 5 +++++ .../test/org/apache/lucene/index/TestTermVectorsReader.java | 4 +++- .../org/apache/lucene/index/BaseCompoundFormatTestCase.java | 4 +++- .../java/org/apache/lucene/store/BaseDirectoryTestCase.java | 4 +--- lucene/tools/forbiddenApis/tests.txt | 3 ++- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 71d68a79672..ca867429f35 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -104,6 +104,11 @@ Build detect javadoc-style license headers. Use Groovy to implement the checks instead of plain Ant. (Uwe Schindler) +Tests + +* LUCENE-6752: Add Math#random() to forbiddenapis. (Uwe Schindler, + Mikhail Khludnev, Andrei Beliakov) + Changes in Backwards Compatibility Policy * LUCENE-6742: The Lovins & Finnish implementation of SnowballFilter diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java b/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java index 3d6729af829..8495010fad4 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java @@ -19,6 +19,7 @@ package org.apache.lucene.index; import java.io.IOException; import java.util.Arrays; +import java.util.Random; import org.apache.lucene.analysis.*; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; @@ -73,12 +74,13 @@ public class TestTermVectorsReader extends LuceneTestCase { Arrays.sort(testTerms); int tokenUpto = 0; + Random rnd = random(); for (int i = 0; i < testTerms.length; i++) { positions[i] = new int[TERM_FREQ]; // first position must be 0 for (int j = 0; j < TERM_FREQ; j++) { // positions are always sorted in increasing order - positions[i][j] = (int) (j * 10 + Math.random() * 10); + positions[i][j] = (int) (j * 10 + rnd.nextDouble() * 10); TestToken token = tokens[tokenUpto++] = new TestToken(); token.text = testTerms[i]; token.pos = positions[i][j]; diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java index 34d14dc4680..9122e993dab 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Random; import org.apache.lucene.codecs.Codec; import org.apache.lucene.document.Document; @@ -654,8 +655,9 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest /** Creates a file of the specified size with random data. */ protected static void createRandomFile(Directory dir, String name, int size) throws IOException { IndexOutput os = dir.createOutput(name, newIOContext(random())); + Random rnd = random(); for (int i=0; i() @ Use RandomizedRunner's random instead +java.util.Random#() @ Use RandomizedRunner's random() instead +java.lang.Math#random() @ Use RandomizedRunner's random().nextDouble() instead # TODO: fix tests that do this! #java.lang.System#currentTimeMillis() @ Don't depend on wall clock times