The following issues were found
android/guava-tests/test/com/google/common/html/HtmlEscapersTest.java
28 issues
Line: 30
@GwtCompatible
public class HtmlEscapersTest extends TestCase {
public void testHtmlEscaper() throws Exception {
assertEquals("xxx", htmlEscaper().escape("xxx"));
assertEquals(""test"", htmlEscaper().escape("\"test\""));
assertEquals("'test'", htmlEscaper().escape("\'test'"));
assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
assertEquals("test << 1", htmlEscaper().escape("test << 1"));
Reported by PMD.
Line: 30
@GwtCompatible
public class HtmlEscapersTest extends TestCase {
public void testHtmlEscaper() throws Exception {
assertEquals("xxx", htmlEscaper().escape("xxx"));
assertEquals(""test"", htmlEscaper().escape("\"test\""));
assertEquals("'test'", htmlEscaper().escape("\'test'"));
assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
assertEquals("test << 1", htmlEscaper().escape("test << 1"));
Reported by PMD.
Line: 31
public class HtmlEscapersTest extends TestCase {
public void testHtmlEscaper() throws Exception {
assertEquals("xxx", htmlEscaper().escape("xxx"));
assertEquals(""test"", htmlEscaper().escape("\"test\""));
assertEquals("'test'", htmlEscaper().escape("\'test'"));
assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
assertEquals("test << 1", htmlEscaper().escape("test << 1"));
assertEquals("test >> 1", htmlEscaper().escape("test >> 1"));
Reported by PMD.
Line: 31
public class HtmlEscapersTest extends TestCase {
public void testHtmlEscaper() throws Exception {
assertEquals("xxx", htmlEscaper().escape("xxx"));
assertEquals(""test"", htmlEscaper().escape("\"test\""));
assertEquals("'test'", htmlEscaper().escape("\'test'"));
assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
assertEquals("test << 1", htmlEscaper().escape("test << 1"));
assertEquals("test >> 1", htmlEscaper().escape("test >> 1"));
Reported by PMD.
Line: 32
public void testHtmlEscaper() throws Exception {
assertEquals("xxx", htmlEscaper().escape("xxx"));
assertEquals(""test"", htmlEscaper().escape("\"test\""));
assertEquals("'test'", htmlEscaper().escape("\'test'"));
assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
assertEquals("test << 1", htmlEscaper().escape("test << 1"));
assertEquals("test >> 1", htmlEscaper().escape("test >> 1"));
assertEquals("<tab>", htmlEscaper().escape("<tab>"));
Reported by PMD.
Line: 32
public void testHtmlEscaper() throws Exception {
assertEquals("xxx", htmlEscaper().escape("xxx"));
assertEquals(""test"", htmlEscaper().escape("\"test\""));
assertEquals("'test'", htmlEscaper().escape("\'test'"));
assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
assertEquals("test << 1", htmlEscaper().escape("test << 1"));
assertEquals("test >> 1", htmlEscaper().escape("test >> 1"));
assertEquals("<tab>", htmlEscaper().escape("<tab>"));
Reported by PMD.
Line: 33
public void testHtmlEscaper() throws Exception {
assertEquals("xxx", htmlEscaper().escape("xxx"));
assertEquals(""test"", htmlEscaper().escape("\"test\""));
assertEquals("'test'", htmlEscaper().escape("\'test'"));
assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
assertEquals("test << 1", htmlEscaper().escape("test << 1"));
assertEquals("test >> 1", htmlEscaper().escape("test >> 1"));
assertEquals("<tab>", htmlEscaper().escape("<tab>"));
Reported by PMD.
Line: 33
public void testHtmlEscaper() throws Exception {
assertEquals("xxx", htmlEscaper().escape("xxx"));
assertEquals(""test"", htmlEscaper().escape("\"test\""));
assertEquals("'test'", htmlEscaper().escape("\'test'"));
assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
assertEquals("test << 1", htmlEscaper().escape("test << 1"));
assertEquals("test >> 1", htmlEscaper().escape("test >> 1"));
assertEquals("<tab>", htmlEscaper().escape("<tab>"));
Reported by PMD.
Line: 34
assertEquals("xxx", htmlEscaper().escape("xxx"));
assertEquals(""test"", htmlEscaper().escape("\"test\""));
assertEquals("'test'", htmlEscaper().escape("\'test'"));
assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
assertEquals("test << 1", htmlEscaper().escape("test << 1"));
assertEquals("test >> 1", htmlEscaper().escape("test >> 1"));
assertEquals("<tab>", htmlEscaper().escape("<tab>"));
// Test simple escape of '&'.
Reported by PMD.
Line: 34
assertEquals("xxx", htmlEscaper().escape("xxx"));
assertEquals(""test"", htmlEscaper().escape("\"test\""));
assertEquals("'test'", htmlEscaper().escape("\'test'"));
assertEquals("test & test & test", htmlEscaper().escape("test & test & test"));
assertEquals("test << 1", htmlEscaper().escape("test << 1"));
assertEquals("test >> 1", htmlEscaper().escape("test >> 1"));
assertEquals("<tab>", htmlEscaper().escape("<tab>"));
// Test simple escape of '&'.
Reported by PMD.
android/guava-tests/test/com/google/common/cache/CacheLoaderTest.java
28 issues
Line: 39
public class CacheLoaderTest extends TestCase {
private static class QueuingExecutor implements Executor {
private final Deque<Runnable> tasks = Queues.newArrayDeque();
@Override
public void execute(Runnable task) {
tasks.add(task);
}
Reported by PMD.
Line: 47
}
private void runNext() {
tasks.removeFirst().run();
}
}
public void testAsyncReload() throws Exception {
final AtomicInteger loadCount = new AtomicInteger();
Reported by PMD.
Line: 51
}
}
public void testAsyncReload() throws Exception {
final AtomicInteger loadCount = new AtomicInteger();
final AtomicInteger reloadCount = new AtomicInteger();
final AtomicInteger loadAllCount = new AtomicInteger();
CacheLoader<Object, Object> baseLoader =
Reported by PMD.
Line: 51
}
}
public void testAsyncReload() throws Exception {
final AtomicInteger loadCount = new AtomicInteger();
final AtomicInteger reloadCount = new AtomicInteger();
final AtomicInteger loadAllCount = new AtomicInteger();
CacheLoader<Object, Object> baseLoader =
Reported by PMD.
Line: 77
}
};
assertEquals(0, loadCount.get());
assertEquals(0, reloadCount.get());
assertEquals(0, loadAllCount.get());
baseLoader.load(new Object());
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Reported by PMD.
Line: 78
};
assertEquals(0, loadCount.get());
assertEquals(0, reloadCount.get());
assertEquals(0, loadAllCount.get());
baseLoader.load(new Object());
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = baseLoader.reload(new Object(), new Object());
Reported by PMD.
Line: 79
assertEquals(0, loadCount.get());
assertEquals(0, reloadCount.get());
assertEquals(0, loadAllCount.get());
baseLoader.load(new Object());
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = baseLoader.reload(new Object(), new Object());
baseLoader.loadAll(ImmutableList.of(new Object()));
Reported by PMD.
Line: 85
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError = baseLoader.reload(new Object(), new Object());
baseLoader.loadAll(ImmutableList.of(new Object()));
assertEquals(1, loadCount.get());
assertEquals(1, reloadCount.get());
assertEquals(1, loadAllCount.get());
QueuingExecutor executor = new QueuingExecutor();
CacheLoader<Object, Object> asyncReloader = CacheLoader.asyncReloading(baseLoader, executor);
Reported by PMD.
Line: 86
Future<?> possiblyIgnoredError = baseLoader.reload(new Object(), new Object());
baseLoader.loadAll(ImmutableList.of(new Object()));
assertEquals(1, loadCount.get());
assertEquals(1, reloadCount.get());
assertEquals(1, loadAllCount.get());
QueuingExecutor executor = new QueuingExecutor();
CacheLoader<Object, Object> asyncReloader = CacheLoader.asyncReloading(baseLoader, executor);
Reported by PMD.
Line: 87
baseLoader.loadAll(ImmutableList.of(new Object()));
assertEquals(1, loadCount.get());
assertEquals(1, reloadCount.get());
assertEquals(1, loadAllCount.get());
QueuingExecutor executor = new QueuingExecutor();
CacheLoader<Object, Object> asyncReloader = CacheLoader.asyncReloading(baseLoader, executor);
asyncReloader.load(new Object());
Reported by PMD.
android/guava-tests/test/com/google/common/util/concurrent/AggregateFutureStateFallbackAtomicHelperTest.java
28 issues
Line: 48
* methods in these degenerate classloaders.
*/
public class AggregateFutureStateFallbackAtomicHelperTest extends TestCase {
/**
* This classloader disallows AtomicReferenceFieldUpdater and AtomicIntegerFieldUpdate which will
* prevent us from selecting our {@code SafeAtomicHelper} strategy.
*
Reported by PMD.
Line: 69
// corresponding method on FuturesTest in the correct classloader.
TestSuite suite = new TestSuite(AggregateFutureStateFallbackAtomicHelperTest.class.getName());
for (Method method : FuturesTest.class.getDeclaredMethods()) {
if (Modifier.isPublic(method.getModifiers()) && method.getName().startsWith("test")) {
suite.addTest(
TestSuite.createTest(
AggregateFutureStateFallbackAtomicHelperTest.class, method.getName()));
}
}
Reported by PMD.
Line: 81
@Override
public void runTest() throws Exception {
// First ensure that our classloaders are initializing the correct helper versions
checkHelperVersion(getClass().getClassLoader(), "SafeAtomicHelper");
checkHelperVersion(NO_ATOMIC_FIELD_UPDATER, "SynchronizedAtomicHelper");
// Run the corresponding FuturesTest test method in a new classloader that disallows
// certain core jdk classes.
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Reported by PMD.
Line: 81
@Override
public void runTest() throws Exception {
// First ensure that our classloaders are initializing the correct helper versions
checkHelperVersion(getClass().getClassLoader(), "SafeAtomicHelper");
checkHelperVersion(NO_ATOMIC_FIELD_UPDATER, "SynchronizedAtomicHelper");
// Run the corresponding FuturesTest test method in a new classloader that disallows
// certain core jdk classes.
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Reported by PMD.
Line: 86
// Run the corresponding FuturesTest test method in a new classloader that disallows
// certain core jdk classes.
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(NO_ATOMIC_FIELD_UPDATER);
try {
runTestMethod(NO_ATOMIC_FIELD_UPDATER);
// TODO(lukes): assert that the logs are full of errors
} finally {
Reported by PMD.
Line: 87
// Run the corresponding FuturesTest test method in a new classloader that disallows
// certain core jdk classes.
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(NO_ATOMIC_FIELD_UPDATER);
try {
runTestMethod(NO_ATOMIC_FIELD_UPDATER);
// TODO(lukes): assert that the logs are full of errors
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
Reported by PMD.
Line: 92
runTestMethod(NO_ATOMIC_FIELD_UPDATER);
// TODO(lukes): assert that the logs are full of errors
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
private void runTestMethod(ClassLoader classLoader) throws Exception {
Class<?> test = classLoader.loadClass(FuturesTest.class.getName());
Reported by PMD.
Line: 96
}
}
private void runTestMethod(ClassLoader classLoader) throws Exception {
Class<?> test = classLoader.loadClass(FuturesTest.class.getName());
Object testInstance = test.getDeclaredConstructor().newInstance();
test.getMethod("setUp").invoke(testInstance);
test.getMethod(getName()).invoke(testInstance);
test.getMethod("tearDown").invoke(testInstance);
Reported by PMD.
Line: 98
private void runTestMethod(ClassLoader classLoader) throws Exception {
Class<?> test = classLoader.loadClass(FuturesTest.class.getName());
Object testInstance = test.getDeclaredConstructor().newInstance();
test.getMethod("setUp").invoke(testInstance);
test.getMethod(getName()).invoke(testInstance);
test.getMethod("tearDown").invoke(testInstance);
}
Reported by PMD.
Line: 98
private void runTestMethod(ClassLoader classLoader) throws Exception {
Class<?> test = classLoader.loadClass(FuturesTest.class.getName());
Object testInstance = test.getDeclaredConstructor().newInstance();
test.getMethod("setUp").invoke(testInstance);
test.getMethod(getName()).invoke(testInstance);
test.getMethod("tearDown").invoke(testInstance);
}
Reported by PMD.
android/guava/src/com/google/common/primitives/Longs.java
28 issues
Line: 159
continue outer;
}
}
return i;
}
return -1;
}
/**
Reported by PMD.
Line: 274
* use a shared {@link java.nio.ByteBuffer} instance, or use {@link
* com.google.common.io.ByteStreams#newDataOutput()} to get a growable buffer.
*/
public static byte[] toByteArray(long value) {
// Note that this code needs to stay compatible with GWT, which has known
// bugs when narrowing byte casts of long values occur.
byte[] result = new byte[8];
for (int i = 7; i >= 0; i--) {
result[i] = (byte) (value & 0xffL);
Reported by PMD.
Line: 47
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class Longs {
private Longs() {}
/**
* The number of bytes required to represent a primitive {@code long} value.
*
Reported by PMD.
Line: 47
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class Longs {
private Longs() {}
/**
* The number of bytes required to represent a primitive {@code long} value.
*
Reported by PMD.
Line: 47
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class Longs {
private Longs() {}
/**
* The number of bytes required to represent a primitive {@code long} value.
*
Reported by PMD.
Line: 47
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class Longs {
private Longs() {}
/**
* The number of bytes required to represent a primitive {@code long} value.
*
Reported by PMD.
Line: 327
static final class AsciiDigits {
private AsciiDigits() {}
private static final byte[] asciiDigits;
static {
byte[] result = new byte[128];
Arrays.fill(result, (byte) -1);
for (int i = 0; i < 10; i++) {
Reported by PMD.
Line: 392
*/
@Beta
@CheckForNull
public static Long tryParse(String string, int radix) {
if (checkNotNull(string).isEmpty()) {
return null;
}
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
throw new IllegalArgumentException(
Reported by PMD.
Line: 392
*/
@Beta
@CheckForNull
public static Long tryParse(String string, int radix) {
if (checkNotNull(string).isEmpty()) {
return null;
}
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
throw new IllegalArgumentException(
Reported by PMD.
Line: 392
*/
@Beta
@CheckForNull
public static Long tryParse(String string, int radix) {
if (checkNotNull(string).isEmpty()) {
return null;
}
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
throw new IllegalArgumentException(
Reported by PMD.
android/guava/src/com/google/common/util/concurrent/AbstractCatchingFuture.java
28 issues
Line: 37
@GwtCompatible
@ElementTypesAreNonnullByDefault
@SuppressWarnings("nullness") // TODO(b/147136275): Remove once our checker understands & and |.
abstract class AbstractCatchingFuture<
V extends @Nullable Object, X extends Throwable, F, T extends @Nullable Object>
extends FluentFuture.TrustedFuture<V> implements Runnable {
static <V extends @Nullable Object, X extends Throwable> ListenableFuture<V> create(
ListenableFuture<? extends V> input,
Class<X> exceptionType,
Reported by PMD.
Line: 37
@GwtCompatible
@ElementTypesAreNonnullByDefault
@SuppressWarnings("nullness") // TODO(b/147136275): Remove once our checker understands & and |.
abstract class AbstractCatchingFuture<
V extends @Nullable Object, X extends Throwable, F, T extends @Nullable Object>
extends FluentFuture.TrustedFuture<V> implements Runnable {
static <V extends @Nullable Object, X extends Throwable> ListenableFuture<V> create(
ListenableFuture<? extends V> input,
Class<X> exceptionType,
Reported by PMD.
Line: 64
* In certain circumstances, this field might theoretically not be visible to an afterDone() call
* triggered by cancel(). For details, see the comments on the fields of TimeoutFuture.
*/
@CheckForNull ListenableFuture<? extends V> inputFuture;
@CheckForNull Class<X> exceptionType;
@CheckForNull F fallback;
AbstractCatchingFuture(
ListenableFuture<? extends V> inputFuture, Class<X> exceptionType, F fallback) {
Reported by PMD.
Line: 65
* triggered by cancel(). For details, see the comments on the fields of TimeoutFuture.
*/
@CheckForNull ListenableFuture<? extends V> inputFuture;
@CheckForNull Class<X> exceptionType;
@CheckForNull F fallback;
AbstractCatchingFuture(
ListenableFuture<? extends V> inputFuture, Class<X> exceptionType, F fallback) {
this.inputFuture = checkNotNull(inputFuture);
Reported by PMD.
Line: 66
*/
@CheckForNull ListenableFuture<? extends V> inputFuture;
@CheckForNull Class<X> exceptionType;
@CheckForNull F fallback;
AbstractCatchingFuture(
ListenableFuture<? extends V> inputFuture, Class<X> exceptionType, F fallback) {
this.inputFuture = checkNotNull(inputFuture);
this.exceptionType = checkNotNull(exceptionType);
Reported by PMD.
Line: 76
}
@Override
public final void run() {
ListenableFuture<? extends V> localInputFuture = inputFuture;
Class<X> localExceptionType = exceptionType;
F localFallback = fallback;
if (localInputFuture == null | localExceptionType == null | localFallback == null
// This check, unlike all the others, is a volatile read
Reported by PMD.
Line: 76
}
@Override
public final void run() {
ListenableFuture<? extends V> localInputFuture = inputFuture;
Class<X> localExceptionType = exceptionType;
F localFallback = fallback;
if (localInputFuture == null | localExceptionType == null | localFallback == null
// This check, unlike all the others, is a volatile read
Reported by PMD.
Line: 76
}
@Override
public final void run() {
ListenableFuture<? extends V> localInputFuture = inputFuture;
Class<X> localExceptionType = exceptionType;
F localFallback = fallback;
if (localInputFuture == null | localExceptionType == null | localFallback == null
// This check, unlike all the others, is a volatile read
Reported by PMD.
Line: 76
}
@Override
public final void run() {
ListenableFuture<? extends V> localInputFuture = inputFuture;
Class<X> localExceptionType = exceptionType;
F localFallback = fallback;
if (localInputFuture == null | localExceptionType == null | localFallback == null
// This check, unlike all the others, is a volatile read
Reported by PMD.
Line: 85
|| isCancelled()) {
return;
}
inputFuture = null;
// For an explanation of the cases here, see the comments on AbstractTransformFuture.run.
V sourceResult = null;
Throwable throwable = null;
try {
Reported by PMD.
android/guava/src/com/google/common/collect/GeneralRange.java
28 issues
Line: 41
*/
@GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
final class GeneralRange<T extends @Nullable Object> implements Serializable {
/** Converts a Range to a GeneralRange. */
static <T extends Comparable> GeneralRange<T> from(Range<T> range) {
T lowerEndpoint = range.hasLowerBound() ? range.lowerEndpoint() : null;
BoundType lowerBoundType = range.hasLowerBound() ? range.lowerBoundType() : OPEN;
Reported by PMD.
Line: 41
*/
@GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
final class GeneralRange<T extends @Nullable Object> implements Serializable {
/** Converts a Range to a GeneralRange. */
static <T extends Comparable> GeneralRange<T> from(Range<T> range) {
T lowerEndpoint = range.hasLowerBound() ? range.lowerEndpoint() : null;
BoundType lowerBoundType = range.hasLowerBound() ? range.lowerBoundType() : OPEN;
Reported by PMD.
Line: 95
return new GeneralRange<T>(comparator, true, lower, lowerType, true, upper, upperType);
}
private final Comparator<? super T> comparator;
private final boolean hasLowerBound;
@CheckForNull private final T lowerEndpoint;
private final BoundType lowerBoundType;
private final boolean hasUpperBound;
@CheckForNull private final T upperEndpoint;
Reported by PMD.
Line: 95
return new GeneralRange<T>(comparator, true, lower, lowerType, true, upper, upperType);
}
private final Comparator<? super T> comparator;
private final boolean hasLowerBound;
@CheckForNull private final T lowerEndpoint;
private final BoundType lowerBoundType;
private final boolean hasUpperBound;
@CheckForNull private final T upperEndpoint;
Reported by PMD.
Line: 96
}
private final Comparator<? super T> comparator;
private final boolean hasLowerBound;
@CheckForNull private final T lowerEndpoint;
private final BoundType lowerBoundType;
private final boolean hasUpperBound;
@CheckForNull private final T upperEndpoint;
private final BoundType upperBoundType;
Reported by PMD.
Line: 96
}
private final Comparator<? super T> comparator;
private final boolean hasLowerBound;
@CheckForNull private final T lowerEndpoint;
private final BoundType lowerBoundType;
private final boolean hasUpperBound;
@CheckForNull private final T upperEndpoint;
private final BoundType upperBoundType;
Reported by PMD.
Line: 99
private final boolean hasLowerBound;
@CheckForNull private final T lowerEndpoint;
private final BoundType lowerBoundType;
private final boolean hasUpperBound;
@CheckForNull private final T upperEndpoint;
private final BoundType upperBoundType;
private GeneralRange(
Comparator<? super T> comparator,
Reported by PMD.
Line: 99
private final boolean hasLowerBound;
@CheckForNull private final T lowerEndpoint;
private final BoundType lowerBoundType;
private final boolean hasUpperBound;
@CheckForNull private final T upperEndpoint;
private final BoundType upperBoundType;
private GeneralRange(
Comparator<? super T> comparator,
Reported by PMD.
Line: 192
* Returns the intersection of the two ranges, or an empty range if their intersection is empty.
*/
@SuppressWarnings("nullness") // TODO(cpovirk): Add casts as needed. Will be noisy and annoying...
GeneralRange<T> intersect(GeneralRange<T> other) {
checkNotNull(other);
checkArgument(comparator.equals(other.comparator));
boolean hasLowBound = this.hasLowerBound;
T lowEnd = getLowerEndpoint();
Reported by PMD.
Line: 192
* Returns the intersection of the two ranges, or an empty range if their intersection is empty.
*/
@SuppressWarnings("nullness") // TODO(cpovirk): Add casts as needed. Will be noisy and annoying...
GeneralRange<T> intersect(GeneralRange<T> other) {
checkNotNull(other);
checkArgument(comparator.equals(other.comparator));
boolean hasLowBound = this.hasLowerBound;
T lowEnd = getLowerEndpoint();
Reported by PMD.
android/guava/src/com/google/common/io/ByteStreams.java
28 issues
Line: 171
* a total combined length of {@code totalLen} bytes) followed by all bytes remaining in the given
* input stream.
*/
private static byte[] toByteArrayInternal(InputStream in, Queue<byte[]> bufs, int totalLen)
throws IOException {
// Starting with an 8k buffer, double the size of each successive buffer. Buffers are retained
// in a deque so that there's no copying between buffers while reading and so all of the bytes
// in each new allocated buffer are available for reading from the stream.
for (int bufSize = BUFFER_SIZE;
Reported by PMD.
Line: 729
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (left == 0) {
return -1;
}
len = (int) Math.min(len, left);
Reported by PMD.
Line: 756
}
@Override
public long skip(long n) throws IOException {
n = Math.min(n, left);
long skipped = in.skip(n);
left -= skipped;
return skipped;
}
Reported by PMD.
Line: 15
* the License.
*/
package com.google.common.io;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndex;
import static com.google.common.base.Preconditions.checkPositionIndexes;
Reported by PMD.
Line: 56
*/
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class ByteStreams {
private static final int BUFFER_SIZE = 8192;
/** Creates a new byte array for buffering reads or writes. */
static byte[] createBuffer() {
Reported by PMD.
Line: 56
*/
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class ByteStreams {
private static final int BUFFER_SIZE = 8192;
/** Creates a new byte array for buffering reads or writes. */
static byte[] createBuffer() {
Reported by PMD.
Line: 137
checkNotNull(to);
if (from instanceof FileChannel) {
FileChannel sourceChannel = (FileChannel) from;
long oldPosition = sourceChannel.position();
long position = oldPosition;
long copied;
do {
copied = sourceChannel.transferTo(position, ZERO_COPY_CHUNK_SIZE, to);
position += copied;
Reported by PMD.
Line: 141
long position = oldPosition;
long copied;
do {
copied = sourceChannel.transferTo(position, ZERO_COPY_CHUNK_SIZE, to);
position += copied;
sourceChannel.position(position);
} while (copied > 0 || position < sourceChannel.size());
return position - oldPosition;
}
Reported by PMD.
Line: 143
do {
copied = sourceChannel.transferTo(position, ZERO_COPY_CHUNK_SIZE, to);
position += copied;
sourceChannel.position(position);
} while (copied > 0 || position < sourceChannel.size());
return position - oldPosition;
}
ByteBuffer buf = ByteBuffer.wrap(createBuffer());
Reported by PMD.
Line: 144
copied = sourceChannel.transferTo(position, ZERO_COPY_CHUNK_SIZE, to);
position += copied;
sourceChannel.position(position);
} while (copied > 0 || position < sourceChannel.size());
return position - oldPosition;
}
ByteBuffer buf = ByteBuffer.wrap(createBuffer());
long total = 0;
Reported by PMD.
android/guava/src/com/google/common/collect/ImmutableSortedMultiset.java
28 issues
Line: 53
*/
@GwtIncompatible // hasn't been tested yet
@ElementTypesAreNonnullByDefault
public abstract class ImmutableSortedMultiset<E> extends ImmutableSortedMultisetFauxverideShim<E>
implements SortedMultiset<E> {
// TODO(lowasser): GWT compatibility
/**
* Returns the empty immutable sorted multiset.
Reported by PMD.
Line: 54
@GwtIncompatible // hasn't been tested yet
@ElementTypesAreNonnullByDefault
public abstract class ImmutableSortedMultiset<E> extends ImmutableSortedMultisetFauxverideShim<E>
implements SortedMultiset<E> {
// TODO(lowasser): GWT compatibility
/**
* Returns the empty immutable sorted multiset.
*
Reported by PMD.
Line: 62
*
* <p><b>Performance note:</b> the instance returned is a singleton.
*/
@SuppressWarnings("unchecked")
public static <E> ImmutableSortedMultiset<E> of() {
return (ImmutableSortedMultiset) RegularImmutableSortedMultiset.NATURAL_EMPTY_MULTISET;
}
/** Returns an immutable sorted multiset containing a single element. */
Reported by PMD.
Line: 217
if (elements instanceof ImmutableSortedMultiset) {
@SuppressWarnings("unchecked") // immutable collections are always safe for covariant casts
ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
if (comparator.equals(multiset.comparator())) {
if (multiset.isPartialView()) {
return copyOfSortedEntries(comparator, multiset.entrySet().asList());
} else {
return multiset;
}
Reported by PMD.
Line: 218
@SuppressWarnings("unchecked") // immutable collections are always safe for covariant casts
ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
if (comparator.equals(multiset.comparator())) {
if (multiset.isPartialView()) {
return copyOfSortedEntries(comparator, multiset.entrySet().asList());
} else {
return multiset;
}
}
Reported by PMD.
Line: 219
ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
if (comparator.equals(multiset.comparator())) {
if (multiset.isPartialView()) {
return copyOfSortedEntries(comparator, multiset.entrySet().asList());
} else {
return multiset;
}
}
}
Reported by PMD.
Line: 219
ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
if (comparator.equals(multiset.comparator())) {
if (multiset.isPartialView()) {
return copyOfSortedEntries(comparator, multiset.entrySet().asList());
} else {
return multiset;
}
}
}
Reported by PMD.
Line: 269
@SuppressWarnings("unchecked")
static <E> ImmutableSortedMultiset<E> emptyMultiset(Comparator<? super E> comparator) {
if (Ordering.natural().equals(comparator)) {
return (ImmutableSortedMultiset<E>) RegularImmutableSortedMultiset.NATURAL_EMPTY_MULTISET;
} else {
return new RegularImmutableSortedMultiset<E>(comparator);
}
}
Reported by PMD.
Line: 280
@Override
public final Comparator<? super E> comparator() {
return elementSet().comparator();
}
@Override
public abstract ImmutableSortedSet<E> elementSet();
Reported by PMD.
Line: 286
@Override
public abstract ImmutableSortedSet<E> elementSet();
@LazyInit @CheckForNull transient ImmutableSortedMultiset<E> descendingMultiset;
@Override
public ImmutableSortedMultiset<E> descendingMultiset() {
ImmutableSortedMultiset<E> result = descendingMultiset;
if (result == null) {
Reported by PMD.
android/guava/src/com/google/common/collect/SparseImmutableTable.java
28 issues
Line: 29
@GwtCompatible
@Immutable(containerOf = {"R", "C", "V"})
@ElementTypesAreNonnullByDefault
final class SparseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V> {
static final ImmutableTable<Object, Object, Object> EMPTY =
new SparseImmutableTable<>(
ImmutableList.<Cell<Object, Object, Object>>of(), ImmutableSet.of(), ImmutableSet.of());
private final ImmutableMap<R, ImmutableMap<C, V>> rowMap;
Reported by PMD.
Line: 34
new SparseImmutableTable<>(
ImmutableList.<Cell<Object, Object, Object>>of(), ImmutableSet.of(), ImmutableSet.of());
private final ImmutableMap<R, ImmutableMap<C, V>> rowMap;
private final ImmutableMap<C, ImmutableMap<R, V>> columnMap;
// For each cell in iteration order, the index of that cell's row key in the row key list.
@SuppressWarnings("Immutable") // We don't modify this after construction.
private final int[] cellRowIndices;
Reported by PMD.
Line: 34
new SparseImmutableTable<>(
ImmutableList.<Cell<Object, Object, Object>>of(), ImmutableSet.of(), ImmutableSet.of());
private final ImmutableMap<R, ImmutableMap<C, V>> rowMap;
private final ImmutableMap<C, ImmutableMap<R, V>> columnMap;
// For each cell in iteration order, the index of that cell's row key in the row key list.
@SuppressWarnings("Immutable") // We don't modify this after construction.
private final int[] cellRowIndices;
Reported by PMD.
Line: 35
ImmutableList.<Cell<Object, Object, Object>>of(), ImmutableSet.of(), ImmutableSet.of());
private final ImmutableMap<R, ImmutableMap<C, V>> rowMap;
private final ImmutableMap<C, ImmutableMap<R, V>> columnMap;
// For each cell in iteration order, the index of that cell's row key in the row key list.
@SuppressWarnings("Immutable") // We don't modify this after construction.
private final int[] cellRowIndices;
Reported by PMD.
Line: 35
ImmutableList.<Cell<Object, Object, Object>>of(), ImmutableSet.of(), ImmutableSet.of());
private final ImmutableMap<R, ImmutableMap<C, V>> rowMap;
private final ImmutableMap<C, ImmutableMap<R, V>> columnMap;
// For each cell in iteration order, the index of that cell's row key in the row key list.
@SuppressWarnings("Immutable") // We don't modify this after construction.
private final int[] cellRowIndices;
Reported by PMD.
Line: 39
// For each cell in iteration order, the index of that cell's row key in the row key list.
@SuppressWarnings("Immutable") // We don't modify this after construction.
private final int[] cellRowIndices;
// For each cell in iteration order, the index of that cell's column key in the list of column
// keys present in that row.
@SuppressWarnings("Immutable") // We don't modify this after construction.
private final int[] cellColumnInRowIndices;
Reported by PMD.
Line: 44
// For each cell in iteration order, the index of that cell's column key in the list of column
// keys present in that row.
@SuppressWarnings("Immutable") // We don't modify this after construction.
private final int[] cellColumnInRowIndices;
SparseImmutableTable(
ImmutableList<Cell<R, C, V>> cellList,
ImmutableSet<R> rowSpace,
ImmutableSet<C> columnSpace) {
Reported by PMD.
Line: 53
Map<R, Integer> rowIndex = Maps.indexMap(rowSpace);
Map<R, Map<C, V>> rows = Maps.newLinkedHashMap();
for (R row : rowSpace) {
rows.put(row, new LinkedHashMap<C, V>());
}
Map<C, Map<R, V>> columns = Maps.newLinkedHashMap();
for (C col : columnSpace) {
columns.put(col, new LinkedHashMap<R, V>());
}
Reported by PMD.
Line: 57
}
Map<C, Map<R, V>> columns = Maps.newLinkedHashMap();
for (C col : columnSpace) {
columns.put(col, new LinkedHashMap<R, V>());
}
int[] cellRowIndices = new int[cellList.size()];
int[] cellColumnInRowIndices = new int[cellList.size()];
for (int i = 0; i < cellList.size(); i++) {
Cell<R, C, V> cell = cellList.get(i);
Reported by PMD.
Line: 117
@Override
Cell<R, C, V> getCell(int index) {
int rowIndex = cellRowIndices[index];
Entry<R, ImmutableMap<C, V>> rowEntry = rowMap.entrySet().asList().get(rowIndex);
ImmutableMap<C, V> row = rowEntry.getValue();
int columnIndex = cellColumnInRowIndices[index];
Entry<C, V> colEntry = row.entrySet().asList().get(columnIndex);
return cellOf(rowEntry.getKey(), colEntry.getKey(), colEntry.getValue());
}
Reported by PMD.
android/guava/src/com/google/common/base/Throwables.java
28 issues
Line: 243
@Deprecated
public static RuntimeException propagate(Throwable throwable) {
throwIfUnchecked(throwable);
throw new RuntimeException(throwable);
}
/**
* Returns the innermost cause of {@code throwable}. The first throwable in a chain provides
* context from when the error or exception was initially detected. Example usage:
Reported by PMD.
Line: 444
try {
return method.invoke(receiver, params);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw propagate(e.getCause());
}
}
Reported by PMD.
Line: 256
*
* @throws IllegalArgumentException if there is a loop in the causal chain
*/
public static Throwable getRootCause(Throwable throwable) {
// Keep a second pointer that slowly walks the causal chain. If the fast pointer ever catches
// the slower pointer, then there's a loop.
Throwable slowPointer = throwable;
boolean advanceSlowPointer = false;
Reported by PMD.
Line: 294
* @throws IllegalArgumentException if there is a loop in the causal chain
*/
@Beta // TODO(kevinb): decide best return type
public static List<Throwable> getCausalChain(Throwable throwable) {
checkNotNull(throwable);
List<Throwable> causes = new ArrayList<>(4);
causes.add(throwable);
// Keep a second pointer that slowly walks the causal chain. If the fast pointer ever catches
Reported by PMD.
Line: 50
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Throwables {
private Throwables() {}
/**
* Throws {@code throwable} if it is an instance of {@code declaredType}. Example usage:
*
Reported by PMD.
Line: 50
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Throwables {
private Throwables() {}
/**
* Throws {@code throwable} if it is an instance of {@code declaredType}. Example usage:
*
Reported by PMD.
Line: 263
boolean advanceSlowPointer = false;
Throwable cause;
while ((cause = throwable.getCause()) != null) {
throwable = cause;
if (throwable == slowPointer) {
throw new IllegalArgumentException("Loop in causal chain detected.", throwable);
}
Reported by PMD.
Line: 266
while ((cause = throwable.getCause()) != null) {
throwable = cause;
if (throwable == slowPointer) {
throw new IllegalArgumentException("Loop in causal chain detected.", throwable);
}
if (advanceSlowPointer) {
slowPointer = slowPointer.getCause();
}
Reported by PMD.
Line: 305
boolean advanceSlowPointer = false;
Throwable cause;
while ((cause = throwable.getCause()) != null) {
throwable = cause;
causes.add(throwable);
if (throwable == slowPointer) {
throw new IllegalArgumentException("Loop in causal chain detected.", throwable);
Reported by PMD.
Line: 309
throwable = cause;
causes.add(throwable);
if (throwable == slowPointer) {
throw new IllegalArgumentException("Loop in causal chain detected.", throwable);
}
if (advanceSlowPointer) {
slowPointer = slowPointer.getCause();
}
Reported by PMD.