[freenet-cvs] r18554 - trunk/freenet/src/org/spaceroots/mantissa/random

nextgens at freenetproject.org nextgens at freenetproject.org
Mon Mar 17 02:17:00 UTC 2008


Author: nextgens
Date: 2008-03-17 02:17:00 +0000 (Mon, 17 Mar 2008)
New Revision: 18554

Modified:
   trunk/freenet/src/org/spaceroots/mantissa/random/MersenneTwister.java
Log:
MersenTwister: fix a NPE (race condition: http://de.pastebin.ca/raw/945252) and resolve #2169

Modified: trunk/freenet/src/org/spaceroots/mantissa/random/MersenneTwister.java
===================================================================
--- trunk/freenet/src/org/spaceroots/mantissa/random/MersenneTwister.java	2008-03-16 12:16:07 UTC (rev 18553)
+++ trunk/freenet/src/org/spaceroots/mantissa/random/MersenneTwister.java	2008-03-17 02:17:00 UTC (rev 18554)
@@ -124,6 +124,12 @@
 	 * @param seed the initial seed (32 bits integer)
 	 */
 	public synchronized void setSeed(int seed) {
+		if (mt == null) {
+			// this is probably a spurious call from base class constructor,
+			// we do nothing and wait for the setSeed in our own
+			// constructors after array allocation
+			return;
+		}
 		// we use a long masked by 0xffffffffL as a poor man unsigned int
 		long longMT = seed;
 		mt[0]= (int) longMT;
@@ -139,6 +145,12 @@
 	 * Seed from byte[].
 	 */
 	public synchronized void setSeed(byte[] seed) {
+		if (mt == null) {
+			// this is probably a spurious call from base class constructor,
+			// we do nothing and wait for the setSeed in our own
+			// constructors after array allocation
+			return;
+		}
 		int[] seeds = new int[seed.length/4];
 		for(int i=0;i<seeds.length;i+=4) {
 			seeds[i] = Fields.bytesToInt(seed, i);




More information about the cvs mailing list