Index: lucene/build.xml =================================================================== --- lucene/build.xml (revision 1360292) +++ lucene/build.xml (working copy) @@ -176,7 +176,7 @@ - + @@ -188,6 +188,15 @@ + + + + + + + + + Index: lucene/tools/forbiddenApis/tests.txt =================================================================== --- lucene/tools/forbiddenApis/tests.txt (revision 0) +++ lucene/tools/forbiddenApis/tests.txt (revision 0) @@ -0,0 +1,7 @@ +# Use RandomizedRunner's random instead +java.util.Random#() + +# Don't depend on wall clock times +# TODO: fix tests that do this! +#java.lang.System#currentTimeMillis() +#java.lang.System#nanoTime() Index: lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java =================================================================== --- lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java (revision 1360292) +++ lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java (working copy) @@ -71,13 +71,13 @@ private final String SEED_EXT = "sd"; public MockRandomPostingsFormat() { - // just for reading, we are gonna setSeed from the .seed file... right? - this(new Random()); + // This ctor should *only* be used at read-time: get NPE if you use it! + this(null); } public MockRandomPostingsFormat(Random random) { super("MockRandom"); - this.seedRandom = new Random(random.nextLong()); + this.seedRandom = random == null ? null : new Random(random.nextLong()); } // Chooses random IntStreamFactory depending on file's extension Index: lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java =================================================================== --- lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java (revision 1360292) +++ lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java (working copy) @@ -79,6 +79,7 @@ import org.apache.lucene.store.IOContext; import org.junit.Assert; +import com.carrotsearch.randomizedtesting.RandomizedContext; import com.carrotsearch.randomizedtesting.generators.RandomInts; import com.carrotsearch.randomizedtesting.generators.RandomPicks; @@ -731,8 +732,12 @@ } String newSuffix = suffix == null ? ".tmp" : suffix; File result; + // just pull one long always: we don't want to rely upon what may or may not + // already exist. otherwise tests might not reproduce, depending on when you last + // ran 'ant clean' + final Random random = new Random(RandomizedContext.current().getRandom().nextLong()); do { - result = genTempFile(prefix, newSuffix, directory); + result = genTempFile(random, prefix, newSuffix, directory); } while (!result.createNewFile()); return result; } @@ -746,12 +751,12 @@ private static class TempFileLocker {}; private static TempFileLocker tempFileLocker = new TempFileLocker(); - private static File genTempFile(String prefix, String suffix, File directory) { + private static File genTempFile(Random random, String prefix, String suffix, File directory) { int identify = 0; synchronized (tempFileLocker) { if (counter == 0) { - int newInt = new Random().nextInt(); + int newInt = random.nextInt(); counter = ((newInt / 65535) & 0xFFFF) + 0x2710; counterBase = counter; }