Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-1990

suspicious instantiation of java Random instances

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 3.5.0
    • 3.6.0, 3.5.5
    • None

    Description

      It's not clear to me why we are doing this, but it looks very suspicious. Why aren't we just calling "new Random()" in these cases? (even for the tests I don't really see it - typically that would just be for repeatability)

      ag "new Random[ \t]*\(" .
      src/java/main/org/apache/zookeeper/ClientCnxn.java
      817:        private Random r = new Random(System.nanoTime());        
      
      src/java/main/org/apache/zookeeper/client/StaticHostProvider.java
      75:       sourceOfRandomness = new Random(System.currentTimeMillis() ^ this.hashCode());
      98:        sourceOfRandomness = new Random(randomnessSeed);
      
      src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java
      420:                rand = new Random(java.lang.Thread.currentThread().getId()
      
      src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
      64:    private final Random r = new Random(System.nanoTime());
      
      src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
      537:        Random r = new Random(id ^ superSecret);
      554:        Random r = new Random(sessionId ^ superSecret);
      
      src/java/test/org/apache/zookeeper/server/quorum/WatchLeakTest.java
      271:        Random r = new Random(SESSION_ID ^ superSecret);
      
      src/java/test/org/apache/zookeeper/server/quorum/CommitProcessorTest.java
      151:            Random rand = new Random(Thread.currentThread().getId());
      258:            Random rand = new Random(Thread.currentThread().getId());
      288:        Random rand = new Random(Thread.currentThread().getId());
      
      src/java/test/org/apache/zookeeper/test/StaticHostProviderTest.java
      40:    private Random r = new Random(1);
      
      

      Attachments

        Issue Links

          Activity

            People

              nkalmar Norbert Kalmár
              phunt Patrick D. Hunt
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m