--- jsr166/src/test/tck/ThreadLocalRandomTest.java 2016/12/10 12:39:15 1.24 +++ jsr166/src/test/tck/ThreadLocalRandomTest.java 2017/10/13 02:34:59 1.27 @@ -57,6 +57,9 @@ public class ThreadLocalRandomTest exten * possible values. */ public void testNext() throws ReflectiveOperationException { + // Inhibit "An illegal reflective access operation has occurred" + if (!testImplementationDetails) return; + ThreadLocalRandom rnd = ThreadLocalRandom.current(); final java.lang.reflect.Method m; try { @@ -382,4 +385,38 @@ public class ThreadLocalRandomTest exten fail("all threads generate the same pseudo-random sequence"); } + /** + * Repeated calls to nextBytes produce at least values of different signs for every byte + */ + public void testNextBytes() { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + int n = rnd.nextInt(1, 20); + byte[] bytes = new byte[n]; + outer: + for (int i = 0; i < n; i++) { + for (int tries = NCALLS; tries-->0; ) { + byte before = bytes[i]; + rnd.nextBytes(bytes); + byte after = bytes[i]; + if (after * before < 0) + continue outer; + } + fail("not enough variation in random bytes"); + } + } + + /** + * Filling an empty array with random bytes succeeds without effect. + */ + public void testNextBytes_emptyArray() { + ThreadLocalRandom.current().nextBytes(new byte[0]); + } + + public void testNextBytes_nullArray() { + try { + ThreadLocalRandom.current().nextBytes(null); + shouldThrow(); + } catch (NullPointerException success) {} + } + }