The following issues were found
guava-testlib/test/com/google/common/util/concurrent/testing/TestingExecutorsTest.java
46 issues
Line: 108
new Runnable() {
@Override
public void run() {
throw new RuntimeException("Oh no!");
}
};
Future<?> future = TestingExecutors.sameThreadScheduledExecutor().submit(runnable);
try {
Reported by PMD.
Line: 36
* @author Eric Chang
*/
public class TestingExecutorsTest extends TestCase {
private volatile boolean taskDone;
public void testNoOpScheduledExecutor() throws InterruptedException {
taskDone = false;
Runnable task =
new Runnable() {
Reported by PMD.
Line: 38
public class TestingExecutorsTest extends TestCase {
private volatile boolean taskDone;
public void testNoOpScheduledExecutor() throws InterruptedException {
taskDone = false;
Runnable task =
new Runnable() {
@Override
public void run() {
Reported by PMD.
Line: 38
public class TestingExecutorsTest extends TestCase {
private volatile boolean taskDone;
public void testNoOpScheduledExecutor() throws InterruptedException {
taskDone = false;
Runnable task =
new Runnable() {
@Override
public void run() {
Reported by PMD.
Line: 48
}
};
ScheduledFuture<?> future =
TestingExecutors.noOpScheduledExecutor().schedule(task, 10, TimeUnit.MILLISECONDS);
Thread.sleep(20);
assertFalse(taskDone);
assertFalse(future.isDone());
}
Reported by PMD.
Line: 50
ScheduledFuture<?> future =
TestingExecutors.noOpScheduledExecutor().schedule(task, 10, TimeUnit.MILLISECONDS);
Thread.sleep(20);
assertFalse(taskDone);
assertFalse(future.isDone());
}
public void testNoOpScheduledExecutorShutdown() {
ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
Reported by PMD.
Line: 51
TestingExecutors.noOpScheduledExecutor().schedule(task, 10, TimeUnit.MILLISECONDS);
Thread.sleep(20);
assertFalse(taskDone);
assertFalse(future.isDone());
}
public void testNoOpScheduledExecutorShutdown() {
ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
assertFalse(executor.isShutdown());
Reported by PMD.
Line: 51
TestingExecutors.noOpScheduledExecutor().schedule(task, 10, TimeUnit.MILLISECONDS);
Thread.sleep(20);
assertFalse(taskDone);
assertFalse(future.isDone());
}
public void testNoOpScheduledExecutorShutdown() {
ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
assertFalse(executor.isShutdown());
Reported by PMD.
Line: 54
assertFalse(future.isDone());
}
public void testNoOpScheduledExecutorShutdown() {
ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
assertFalse(executor.isShutdown());
assertFalse(executor.isTerminated());
executor.shutdown();
assertTrue(executor.isShutdown());
Reported by PMD.
Line: 54
assertFalse(future.isDone());
}
public void testNoOpScheduledExecutorShutdown() {
ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
assertFalse(executor.isShutdown());
assertFalse(executor.isTerminated());
executor.shutdown();
assertTrue(executor.isShutdown());
Reported by PMD.
guava-testlib/test/com/google/common/testing/anotherpackage/ForwardingWrapperTesterTest.java
46 issues
Line: 17
* limitations under the License.
*/
package com.google.common.testing.anotherpackage;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.base.Equivalence;
import com.google.common.base.Function;
Reported by PMD.
Line: 44
*
* @author Ben Yu
*/
public class ForwardingWrapperTesterTest extends TestCase {
private final ForwardingWrapperTester tester = new ForwardingWrapperTester();
public void testGoodForwarder() {
tester.testForwarding(
Reported by PMD.
Line: 46
*/
public class ForwardingWrapperTesterTest extends TestCase {
private final ForwardingWrapperTester tester = new ForwardingWrapperTester();
public void testGoodForwarder() {
tester.testForwarding(
Arithmetic.class,
new Function<Arithmetic, Arithmetic>() {
Reported by PMD.
Line: 48
private final ForwardingWrapperTester tester = new ForwardingWrapperTester();
public void testGoodForwarder() {
tester.testForwarding(
Arithmetic.class,
new Function<Arithmetic, Arithmetic>() {
@Override
public Arithmetic apply(Arithmetic arithmetic) {
Reported by PMD.
Line: 48
private final ForwardingWrapperTester tester = new ForwardingWrapperTester();
public void testGoodForwarder() {
tester.testForwarding(
Arithmetic.class,
new Function<Arithmetic, Arithmetic>() {
@Override
public Arithmetic apply(Arithmetic arithmetic) {
Reported by PMD.
Line: 67
});
}
public void testVoidMethodForwarding() {
tester.testForwarding(
Runnable.class,
new Function<Runnable, Runnable>() {
@Override
public Runnable apply(final Runnable runnable) {
Reported by PMD.
Line: 67
});
}
public void testVoidMethodForwarding() {
tester.testForwarding(
Runnable.class,
new Function<Runnable, Runnable>() {
@Override
public Runnable apply(final Runnable runnable) {
Reported by PMD.
Line: 78
});
}
public void testToStringForwarding() {
tester.testForwarding(
Runnable.class,
new Function<Runnable, Runnable>() {
@Override
public Runnable apply(final Runnable runnable) {
Reported by PMD.
Line: 78
});
}
public void testToStringForwarding() {
tester.testForwarding(
Runnable.class,
new Function<Runnable, Runnable>() {
@Override
public Runnable apply(final Runnable runnable) {
Reported by PMD.
Line: 94
});
}
public void testFailsToForwardToString() {
assertFailure(
Runnable.class,
new Function<Runnable, Runnable>() {
@Override
public Runnable apply(final Runnable runnable) {
Reported by PMD.
guava/src/com/google/common/primitives/Shorts.java
46 issues
Line: 63
*
* @since 10.0
*/
public static final short MAX_POWER_OF_TWO = 1 << (Short.SIZE - 2);
/**
* Returns a hash code for {@code value}; equal to the result of invoking {@code ((Short)
* value).hashCode()}.
*
Reported by PMD.
Line: 74
* @param value a primitive {@code short} value
* @return a hash code for the value
*/
public static int hashCode(short value) {
return value;
}
/**
* Returns the {@code short} value that is equal to {@code value}, if possible.
Reported by PMD.
Line: 86
* @throws IllegalArgumentException if {@code value} is greater than {@link Short#MAX_VALUE} or
* less than {@link Short#MIN_VALUE}
*/
public static short checkedCast(long value) {
short result = (short) value;
checkArgument(result == value, "Out of range: %s", value);
return result;
}
Reported by PMD.
Line: 87
* less than {@link Short#MIN_VALUE}
*/
public static short checkedCast(long value) {
short result = (short) value;
checkArgument(result == value, "Out of range: %s", value);
return result;
}
/**
Reported by PMD.
Line: 99
* @return the same value cast to {@code short} if it is in the range of the {@code short} type,
* {@link Short#MAX_VALUE} if it is too large, or {@link Short#MIN_VALUE} if it is too small
*/
public static short saturatedCast(long value) {
if (value > Short.MAX_VALUE) {
return Short.MAX_VALUE;
}
if (value < Short.MIN_VALUE) {
return Short.MIN_VALUE;
Reported by PMD.
Line: 121
* @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is
* greater than {@code b}; or zero if they are equal
*/
public static int compare(short a, short b) {
return a - b; // safe due to restricted range
}
/**
* Returns {@code true} if {@code target} is present as an element anywhere in {@code array}.
Reported by PMD.
Line: 121
* @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is
* greater than {@code b}; or zero if they are equal
*/
public static int compare(short a, short b) {
return a - b; // safe due to restricted range
}
/**
* Returns {@code true} if {@code target} is present as an element anywhere in {@code array}.
Reported by PMD.
Line: 132
* @param target a primitive {@code short} value
* @return {@code true} if {@code array[i] == target} for some value of {@code i}
*/
public static boolean contains(short[] array, short target) {
for (short value : array) {
if (value == target) {
return true;
}
}
Reported by PMD.
Line: 133
* @return {@code true} if {@code array[i] == target} for some value of {@code i}
*/
public static boolean contains(short[] array, short target) {
for (short value : array) {
if (value == target) {
return true;
}
}
return false;
Reported by PMD.
Line: 149
* @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no
* such index exists.
*/
public static int indexOf(short[] array, short target) {
return indexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int indexOf(short[] array, short target, int start, int end) {
Reported by PMD.
guava-tests/test/com/google/common/escape/EscapersTest.java
46 issues
Line: 28
/** @author David Beaumont */
@GwtCompatible
public class EscapersTest extends TestCase {
public void testNullEscaper() throws IOException {
Escaper escaper = Escapers.nullEscaper();
EscaperAsserts.assertBasic(escaper);
String s = "\0\n\t\\az09~\uD800\uDC00\uFFFF";
assertEquals("null escaper should have no effect", s, escaper.escape(s));
}
Reported by PMD.
Line: 32
Escaper escaper = Escapers.nullEscaper();
EscaperAsserts.assertBasic(escaper);
String s = "\0\n\t\\az09~\uD800\uDC00\uFFFF";
assertEquals("null escaper should have no effect", s, escaper.escape(s));
}
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
Reported by PMD.
Line: 35
assertEquals("null escaper should have no effect", s, escaper.escape(s));
}
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
Reported by PMD.
Line: 37
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Reported by PMD.
Line: 37
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Reported by PMD.
Line: 38
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
Reported by PMD.
Line: 38
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
Reported by PMD.
Line: 41
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
}
Reported by PMD.
Line: 43
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
}
public void testBuilderRetainsState() {
// Setting a safe range and unsafe replacement works as expected.
Reported by PMD.
Line: 43
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
}
public void testBuilderRetainsState() {
// Setting a safe range and unsafe replacement works as expected.
Reported by PMD.
android/guava-tests/test/com/google/common/cache/NullCacheTest.java
46 issues
Line: 35
* @author mike nonemacher
*/
public class NullCacheTest extends TestCase {
QueuingRemovalListener<Object, Object> listener;
@Override
protected void setUp() {
listener = queuingRemovalListener();
}
Reported by PMD.
Line: 37
public class NullCacheTest extends TestCase {
QueuingRemovalListener<Object, Object> listener;
@Override
protected void setUp() {
listener = queuingRemovalListener();
}
public void testGet() {
Reported by PMD.
Line: 42
listener = queuingRemovalListener();
}
public void testGet() {
Object computed = new Object();
LoadingCache<Object, Object> cache =
CacheBuilder.newBuilder()
.maximumSize(0)
.removalListener(listener)
Reported by PMD.
Line: 42
listener = queuingRemovalListener();
}
public void testGet() {
Object computed = new Object();
LoadingCache<Object, Object> cache =
CacheBuilder.newBuilder()
.maximumSize(0)
.removalListener(listener)
Reported by PMD.
Line: 51
.build(constantLoader(computed));
Object key = new Object();
assertSame(computed, cache.getUnchecked(key));
RemovalNotification<Object, Object> notification = listener.remove();
assertSame(key, notification.getKey());
assertSame(computed, notification.getValue());
assertSame(RemovalCause.SIZE, notification.getCause());
assertTrue(listener.isEmpty());
Reported by PMD.
Line: 51
.build(constantLoader(computed));
Object key = new Object();
assertSame(computed, cache.getUnchecked(key));
RemovalNotification<Object, Object> notification = listener.remove();
assertSame(key, notification.getKey());
assertSame(computed, notification.getValue());
assertSame(RemovalCause.SIZE, notification.getCause());
assertTrue(listener.isEmpty());
Reported by PMD.
Line: 53
Object key = new Object();
assertSame(computed, cache.getUnchecked(key));
RemovalNotification<Object, Object> notification = listener.remove();
assertSame(key, notification.getKey());
assertSame(computed, notification.getValue());
assertSame(RemovalCause.SIZE, notification.getCause());
assertTrue(listener.isEmpty());
checkEmpty(cache);
}
Reported by PMD.
Line: 53
Object key = new Object();
assertSame(computed, cache.getUnchecked(key));
RemovalNotification<Object, Object> notification = listener.remove();
assertSame(key, notification.getKey());
assertSame(computed, notification.getValue());
assertSame(RemovalCause.SIZE, notification.getCause());
assertTrue(listener.isEmpty());
checkEmpty(cache);
}
Reported by PMD.
Line: 54
assertSame(computed, cache.getUnchecked(key));
RemovalNotification<Object, Object> notification = listener.remove();
assertSame(key, notification.getKey());
assertSame(computed, notification.getValue());
assertSame(RemovalCause.SIZE, notification.getCause());
assertTrue(listener.isEmpty());
checkEmpty(cache);
}
Reported by PMD.
Line: 54
assertSame(computed, cache.getUnchecked(key));
RemovalNotification<Object, Object> notification = listener.remove();
assertSame(key, notification.getKey());
assertSame(computed, notification.getValue());
assertSame(RemovalCause.SIZE, notification.getCause());
assertTrue(listener.isEmpty());
checkEmpty(cache);
}
Reported by PMD.
guava-tests/test/com/google/common/graph/GraphMutationTest.java
46 issues
Line: 40
private static final int NODE_POOL_SIZE = 1000; // must be >> NUM_NODES
@Test
public void directedGraph() {
testGraphMutation(GraphBuilder.directed());
}
@Test
public void undirectedGraph() {
Reported by PMD.
Line: 45
}
@Test
public void undirectedGraph() {
testGraphMutation(GraphBuilder.undirected());
}
private static void testGraphMutation(GraphBuilder<? super Integer> graphBuilder) {
Random gen = new Random(42); // Fixed seed so test results are deterministic.
Reported by PMD.
Line: 49
testGraphMutation(GraphBuilder.undirected());
}
private static void testGraphMutation(GraphBuilder<? super Integer> graphBuilder) {
Random gen = new Random(42); // Fixed seed so test results are deterministic.
for (int trial = 0; trial < NUM_TRIALS; ++trial) {
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
Reported by PMD.
Line: 53
Random gen = new Random(42); // Fixed seed so test results are deterministic.
for (int trial = 0; trial < NUM_TRIALS; ++trial) {
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
assertThat(graph.nodes()).isEmpty();
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
Reported by PMD.
Line: 55
for (int trial = 0; trial < NUM_TRIALS; ++trial) {
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
assertThat(graph.nodes()).isEmpty();
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
Reported by PMD.
Line: 55
for (int trial = 0; trial < NUM_TRIALS; ++trial) {
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
assertThat(graph.nodes()).isEmpty();
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
Reported by PMD.
Line: 56
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
assertThat(graph.nodes()).isEmpty();
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
}
Reported by PMD.
Line: 56
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
assertThat(graph.nodes()).isEmpty();
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
}
Reported by PMD.
Line: 59
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
}
ArrayList<Integer> nodeList = new ArrayList<>(graph.nodes());
while (graph.edges().size() < NUM_EDGES) {
graph.putEdge(getRandomElement(nodeList, gen), getRandomElement(nodeList, gen));
Reported by PMD.
Line: 59
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
}
ArrayList<Integer> nodeList = new ArrayList<>(graph.nodes());
while (graph.edges().size() < NUM_EDGES) {
graph.putEdge(getRandomElement(nodeList, gen), getRandomElement(nodeList, gen));
Reported by PMD.
android/guava-tests/test/com/google/common/graph/GraphMutationTest.java
46 issues
Line: 40
private static final int NODE_POOL_SIZE = 1000; // must be >> NUM_NODES
@Test
public void directedGraph() {
testGraphMutation(GraphBuilder.directed());
}
@Test
public void undirectedGraph() {
Reported by PMD.
Line: 45
}
@Test
public void undirectedGraph() {
testGraphMutation(GraphBuilder.undirected());
}
private static void testGraphMutation(GraphBuilder<? super Integer> graphBuilder) {
Random gen = new Random(42); // Fixed seed so test results are deterministic.
Reported by PMD.
Line: 49
testGraphMutation(GraphBuilder.undirected());
}
private static void testGraphMutation(GraphBuilder<? super Integer> graphBuilder) {
Random gen = new Random(42); // Fixed seed so test results are deterministic.
for (int trial = 0; trial < NUM_TRIALS; ++trial) {
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
Reported by PMD.
Line: 53
Random gen = new Random(42); // Fixed seed so test results are deterministic.
for (int trial = 0; trial < NUM_TRIALS; ++trial) {
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
assertThat(graph.nodes()).isEmpty();
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
Reported by PMD.
Line: 55
for (int trial = 0; trial < NUM_TRIALS; ++trial) {
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
assertThat(graph.nodes()).isEmpty();
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
Reported by PMD.
Line: 55
for (int trial = 0; trial < NUM_TRIALS; ++trial) {
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
assertThat(graph.nodes()).isEmpty();
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
Reported by PMD.
Line: 56
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
assertThat(graph.nodes()).isEmpty();
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
}
Reported by PMD.
Line: 56
MutableGraph<Integer> graph = graphBuilder.allowsSelfLoops(true).build();
assertThat(graph.nodes()).isEmpty();
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
}
Reported by PMD.
Line: 59
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
}
ArrayList<Integer> nodeList = new ArrayList<>(graph.nodes());
while (graph.edges().size() < NUM_EDGES) {
graph.putEdge(getRandomElement(nodeList, gen), getRandomElement(nodeList, gen));
Reported by PMD.
Line: 59
assertThat(graph.edges()).isEmpty();
AbstractGraphTest.validateGraph(graph);
while (graph.nodes().size() < NUM_NODES) {
graph.addNode(gen.nextInt(NODE_POOL_SIZE));
}
ArrayList<Integer> nodeList = new ArrayList<>(graph.nodes());
while (graph.edges().size() < NUM_EDGES) {
graph.putEdge(getRandomElement(nodeList, gen), getRandomElement(nodeList, gen));
Reported by PMD.
android/guava-tests/test/com/google/common/escape/EscapersTest.java
46 issues
Line: 28
/** @author David Beaumont */
@GwtCompatible
public class EscapersTest extends TestCase {
public void testNullEscaper() throws IOException {
Escaper escaper = Escapers.nullEscaper();
EscaperAsserts.assertBasic(escaper);
String s = "\0\n\t\\az09~\uD800\uDC00\uFFFF";
assertEquals("null escaper should have no effect", s, escaper.escape(s));
}
Reported by PMD.
Line: 32
Escaper escaper = Escapers.nullEscaper();
EscaperAsserts.assertBasic(escaper);
String s = "\0\n\t\\az09~\uD800\uDC00\uFFFF";
assertEquals("null escaper should have no effect", s, escaper.escape(s));
}
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
Reported by PMD.
Line: 35
assertEquals("null escaper should have no effect", s, escaper.escape(s));
}
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
Reported by PMD.
Line: 37
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Reported by PMD.
Line: 37
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Reported by PMD.
Line: 38
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
Reported by PMD.
Line: 38
public void testBuilderInitialStateNoReplacement() {
// Unsafe characters aren't modified by default (unsafeReplacement == null).
Escaper escaper = Escapers.builder().setSafeRange('a', 'z').build();
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
Reported by PMD.
Line: 41
assertEquals("The Quick Brown Fox", escaper.escape("The Quick Brown Fox"));
}
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
}
Reported by PMD.
Line: 43
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
}
public void testBuilderRetainsState() {
// Setting a safe range and unsafe replacement works as expected.
Reported by PMD.
Line: 43
public void testBuilderInitialStateNoneUnsafe() {
// No characters are unsafe by default (safeMin == 0, safeMax == 0xFFFF).
Escaper escaper = Escapers.builder().setUnsafeReplacement("X").build();
assertEquals("\0\uFFFF", escaper.escape("\0\uFFFF"));
}
public void testBuilderRetainsState() {
// Setting a safe range and unsafe replacement works as expected.
Reported by PMD.
android/guava/src/com/google/common/primitives/Shorts.java
46 issues
Line: 63
*
* @since 10.0
*/
public static final short MAX_POWER_OF_TWO = 1 << (Short.SIZE - 2);
/**
* Returns a hash code for {@code value}; equal to the result of invoking {@code ((Short)
* value).hashCode()}.
*
Reported by PMD.
Line: 74
* @param value a primitive {@code short} value
* @return a hash code for the value
*/
public static int hashCode(short value) {
return value;
}
/**
* Returns the {@code short} value that is equal to {@code value}, if possible.
Reported by PMD.
Line: 86
* @throws IllegalArgumentException if {@code value} is greater than {@link Short#MAX_VALUE} or
* less than {@link Short#MIN_VALUE}
*/
public static short checkedCast(long value) {
short result = (short) value;
checkArgument(result == value, "Out of range: %s", value);
return result;
}
Reported by PMD.
Line: 87
* less than {@link Short#MIN_VALUE}
*/
public static short checkedCast(long value) {
short result = (short) value;
checkArgument(result == value, "Out of range: %s", value);
return result;
}
/**
Reported by PMD.
Line: 99
* @return the same value cast to {@code short} if it is in the range of the {@code short} type,
* {@link Short#MAX_VALUE} if it is too large, or {@link Short#MIN_VALUE} if it is too small
*/
public static short saturatedCast(long value) {
if (value > Short.MAX_VALUE) {
return Short.MAX_VALUE;
}
if (value < Short.MIN_VALUE) {
return Short.MIN_VALUE;
Reported by PMD.
Line: 121
* @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is
* greater than {@code b}; or zero if they are equal
*/
public static int compare(short a, short b) {
return a - b; // safe due to restricted range
}
/**
* Returns {@code true} if {@code target} is present as an element anywhere in {@code array}.
Reported by PMD.
Line: 121
* @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is
* greater than {@code b}; or zero if they are equal
*/
public static int compare(short a, short b) {
return a - b; // safe due to restricted range
}
/**
* Returns {@code true} if {@code target} is present as an element anywhere in {@code array}.
Reported by PMD.
Line: 132
* @param target a primitive {@code short} value
* @return {@code true} if {@code array[i] == target} for some value of {@code i}
*/
public static boolean contains(short[] array, short target) {
for (short value : array) {
if (value == target) {
return true;
}
}
Reported by PMD.
Line: 133
* @return {@code true} if {@code array[i] == target} for some value of {@code i}
*/
public static boolean contains(short[] array, short target) {
for (short value : array) {
if (value == target) {
return true;
}
}
return false;
Reported by PMD.
Line: 149
* @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no
* such index exists.
*/
public static int indexOf(short[] array, short target) {
return indexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int indexOf(short[] array, short target, int start, int end) {
Reported by PMD.
guava-tests/test/com/google/common/collect/MultimapsCollectionTest.java
46 issues
Line: 403
};
}
abstract static class TransformedListMultimapGenerator
extends TransformedMultimapGenerator<ListMultimap<String, String>>
implements TestListMultimapGenerator<String, String> {}
private static Test transformSuite() {
TestSuite suite = new TestSuite("Multimaps.transform*");
Reported by PMD.
Line: 621
ListMultimapTestSuiteBuilder.using(
new FilteredListMultimapGenerator() {
@Override
ListMultimap<String, Integer> filter(ListMultimap<String, Integer> multimap) {
multimap.put("foo", 17);
multimap.put("bar", 32);
multimap.put("foo", 16);
multimap =
Multimaps.filterKeys(multimap, Predicates.not(Predicates.equalTo("foo")));
Reported by PMD.
Line: 684
SetMultimapTestSuiteBuilder.using(
new FilteredSetMultimapGenerator() {
@Override
SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) {
ImmutableSetMultimap<String, Integer> badEntries =
ImmutableSetMultimap.of("foo", 314, "one", 159, "two", 265, "bar", 358);
multimap.putAll(badEntries);
multimap =
Multimaps.filterKeys(
Reported by PMD.
Line: 707
SetMultimapTestSuiteBuilder.using(
new FilteredSetMultimapGenerator() {
@Override
SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) {
ImmutableSetMultimap<String, Integer> badEntries =
ImmutableSetMultimap.of("foo", 314, "one", 159, "two", 265, "bar", 358);
multimap.putAll(badEntries);
multimap =
Multimaps.filterEntries(
Reported by PMD.
Line: 732
SetMultimapTestSuiteBuilder.using(
new FilteredSetMultimapGenerator() {
@Override
SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) {
ImmutableSetMultimap<String, Integer> badEntries =
ImmutableSetMultimap.of("foo", 314, "bar", 358);
multimap.putAll(badEntries);
multimap =
Multimaps.filterKeys(multimap, Predicates.not(Predicates.equalTo("foo")));
Reported by PMD.
Line: 732
SetMultimapTestSuiteBuilder.using(
new FilteredSetMultimapGenerator() {
@Override
SetMultimap<String, Integer> filter(SetMultimap<String, Integer> multimap) {
ImmutableSetMultimap<String, Integer> badEntries =
ImmutableSetMultimap.of("foo", 314, "bar", 358);
multimap.putAll(badEntries);
multimap =
Multimaps.filterKeys(multimap, Predicates.not(Predicates.equalTo("foo")));
Reported by PMD.
Line: 17
* limitations under the License.
*/
package com.google.common.collect;
import static com.google.common.collect.Maps.newHashMap;
import static com.google.common.collect.testing.Helpers.mapEntry;
import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES;
import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE;
Reported by PMD.
Line: 75
* @author Jared Levy
*/
@GwtIncompatible // suite // TODO(cpovirk): set up collect/gwt/suites version
public class MultimapsCollectionTest extends TestCase {
private static final Feature<?>[] FOR_MAP_FEATURES_ONE = {
CollectionSize.ONE,
ALLOWS_NULL_VALUES,
SUPPORTS_REMOVE,
Reported by PMD.
Line: 96
new Supplier<TreeSet<String>>() {
@Override
public TreeSet<String> get() {
return new TreeSet<>(Ordering.natural().nullsLast());
}
};
static void populateMultimapForGet(Multimap<Integer, String> multimap, String[] elements) {
multimap.put(2, "foo");
Reported by PMD.
Line: 101
};
static void populateMultimapForGet(Multimap<Integer, String> multimap, String[] elements) {
multimap.put(2, "foo");
for (String element : elements) {
multimap.put(3, element);
}
}
Reported by PMD.