Skip to content

Commit

Permalink
ARTEMIS-2320 Fix MathAbsoluteRandom errorprone warning
Browse files Browse the repository at this point in the history
Math.abs does not always give a positive result. Please consider other methods for positive random numbers.
  • Loading branch information
jiridanek authored and michaelandrepearce committed Apr 29, 2019
1 parent f7a3630 commit 7820011
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Expand Up @@ -25,10 +25,10 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadLocalRandom;

import org.junit.Test;

Expand Down Expand Up @@ -131,10 +131,10 @@ public void concurrentInsertions() throws Throwable {
final int threadIdx = i;

futures.add(executor.submit(() -> {
Random random = new Random();
final ThreadLocalRandom random = ThreadLocalRandom.current();

for (int j = 0; j < N; j++) {
long key = Math.abs(random.nextLong());
long key = random.nextLong(Long.MAX_VALUE);
// Ensure keys are unique
key -= key % (threadIdx + 1);

Expand Down Expand Up @@ -165,10 +165,10 @@ public void concurrentInsertionsAndReads() throws Throwable {
final int threadIdx = i;

futures.add(executor.submit(() -> {
Random random = new Random();
final ThreadLocalRandom random = ThreadLocalRandom.current();

for (int j = 0; j < N; j++) {
long key = Math.abs(random.nextLong());
long key = random.nextLong(Long.MAX_VALUE);
// Ensure keys are unique
key -= key % (threadIdx + 1);

Expand Down
Expand Up @@ -27,11 +27,11 @@
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadLocalRandom;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -94,10 +94,10 @@ public void concurrentInsertions() throws Throwable {
final int threadIdx = i;

futures.add(executor.submit(() -> {
Random random = new Random();
final ThreadLocalRandom random = ThreadLocalRandom.current();

for (int j = 0; j < N; j++) {
long key = Math.abs(random.nextLong());
long key = random.nextLong(Long.MAX_VALUE);
// Ensure keys are unique
key -= key % (threadIdx + 1);

Expand Down Expand Up @@ -128,10 +128,10 @@ public void concurrentInsertionsAndReads() throws Throwable {
final int threadIdx = i;

futures.add(executor.submit(() -> {
Random random = new Random();
ThreadLocalRandom random = ThreadLocalRandom.current();

for (int j = 0; j < N; j++) {
long key = Math.abs(random.nextLong());
long key = random.nextLong(Long.MAX_VALUE);
// Ensure keys are unique
key -= key % (threadIdx + 1);

Expand Down

0 comments on commit 7820011

Please sign in to comment.