The following issues were found
guava-testlib/src/com/google/common/collect/testing/google/BiMapEntrySetTester.java
13 issues
Line: 34
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class BiMapEntrySetTester<K, V> extends AbstractBiMapTester<K, V> {
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testSetValue_valueAbsent() {
for (Entry<K, V> entry : getMap().entrySet()) {
if (entry.getKey().equals(k0())) {
assertEquals("entry.setValue() should return the old value", v0(), entry.setValue(v3()));
Reported by PMD.
Line: 37
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testSetValue_valueAbsent() {
for (Entry<K, V> entry : getMap().entrySet()) {
if (entry.getKey().equals(k0())) {
assertEquals("entry.setValue() should return the old value", v0(), entry.setValue(v3()));
}
}
expectReplacement(entry(k0(), v3()));
Reported by PMD.
Line: 38
@CollectionSize.Require(absent = ZERO)
public void testSetValue_valueAbsent() {
for (Entry<K, V> entry : getMap().entrySet()) {
if (entry.getKey().equals(k0())) {
assertEquals("entry.setValue() should return the old value", v0(), entry.setValue(v3()));
}
}
expectReplacement(entry(k0(), v3()));
}
Reported by PMD.
Line: 45
expectReplacement(entry(k0(), v3()));
}
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(SEVERAL)
public void testSetValue_valuePresent() {
for (Entry<K, V> entry : getMap().entrySet()) {
if (entry.getKey().equals(k0())) {
try {
Reported by PMD.
Line: 48
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(SEVERAL)
public void testSetValue_valuePresent() {
for (Entry<K, V> entry : getMap().entrySet()) {
if (entry.getKey().equals(k0())) {
try {
entry.setValue(v1());
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
Reported by PMD.
Line: 49
@CollectionSize.Require(SEVERAL)
public void testSetValue_valuePresent() {
for (Entry<K, V> entry : getMap().entrySet()) {
if (entry.getKey().equals(k0())) {
try {
entry.setValue(v1());
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
Reported by PMD.
Line: 60
expectUnchanged();
}
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testSetValueNullUnsupported() {
for (Entry<K, V> entry : getMap().entrySet()) {
try {
entry.setValue(null);
Reported by PMD.
Line: 63
@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testSetValueNullUnsupported() {
for (Entry<K, V> entry : getMap().entrySet()) {
try {
entry.setValue(null);
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
}
Reported by PMD.
Line: 67
try {
entry.setValue(null);
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
}
expectUnchanged();
}
}
Reported by PMD.
Line: 67
try {
entry.setValue(null);
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
}
expectUnchanged();
}
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/SampleElements.java
13 issues
Line: 33
@GwtCompatible
public class SampleElements<E> implements Iterable<E> {
// TODO: rename e3, e4 => missing1, missing2
private final E e0;
private final E e1;
private final E e2;
private final E e3;
private final E e4;
Reported by PMD.
Line: 33
@GwtCompatible
public class SampleElements<E> implements Iterable<E> {
// TODO: rename e3, e4 => missing1, missing2
private final E e0;
private final E e1;
private final E e2;
private final E e3;
private final E e4;
Reported by PMD.
Line: 34
public class SampleElements<E> implements Iterable<E> {
// TODO: rename e3, e4 => missing1, missing2
private final E e0;
private final E e1;
private final E e2;
private final E e3;
private final E e4;
public SampleElements(E e0, E e1, E e2, E e3, E e4) {
Reported by PMD.
Line: 34
public class SampleElements<E> implements Iterable<E> {
// TODO: rename e3, e4 => missing1, missing2
private final E e0;
private final E e1;
private final E e2;
private final E e3;
private final E e4;
public SampleElements(E e0, E e1, E e2, E e3, E e4) {
Reported by PMD.
Line: 35
// TODO: rename e3, e4 => missing1, missing2
private final E e0;
private final E e1;
private final E e2;
private final E e3;
private final E e4;
public SampleElements(E e0, E e1, E e2, E e3, E e4) {
this.e0 = e0;
Reported by PMD.
Line: 35
// TODO: rename e3, e4 => missing1, missing2
private final E e0;
private final E e1;
private final E e2;
private final E e3;
private final E e4;
public SampleElements(E e0, E e1, E e2, E e3, E e4) {
this.e0 = e0;
Reported by PMD.
Line: 36
private final E e0;
private final E e1;
private final E e2;
private final E e3;
private final E e4;
public SampleElements(E e0, E e1, E e2, E e3, E e4) {
this.e0 = e0;
this.e1 = e1;
Reported by PMD.
Line: 36
private final E e0;
private final E e1;
private final E e2;
private final E e3;
private final E e4;
public SampleElements(E e0, E e1, E e2, E e3, E e4) {
this.e0 = e0;
this.e1 = e1;
Reported by PMD.
Line: 37
private final E e1;
private final E e2;
private final E e3;
private final E e4;
public SampleElements(E e0, E e1, E e2, E e3, E e4) {
this.e0 = e0;
this.e1 = e1;
this.e2 = e2;
Reported by PMD.
Line: 37
private final E e1;
private final E e2;
private final E e3;
private final E e4;
public SampleElements(E e0, E e1, E e2, E e3, E e4) {
this.e0 = e0;
this.e1 = e1;
this.e2 = e2;
Reported by PMD.
android/guava/src/com/google/common/math/LinearTransformation.java
13 issues
Line: 62
*/
public static final class LinearTransformationBuilder {
private final double x1;
private final double y1;
private LinearTransformationBuilder(double x1, double y1) {
this.x1 = x1;
this.y1 = y1;
Reported by PMD.
Line: 63
public static final class LinearTransformationBuilder {
private final double x1;
private final double y1;
private LinearTransformationBuilder(double x1, double y1) {
this.x1 = x1;
this.y1 = y1;
}
Reported by PMD.
Line: 163
private static final class RegularLinearTransformation extends LinearTransformation {
final double slope;
final double yIntercept;
@CheckForNull @LazyInit LinearTransformation inverse;
RegularLinearTransformation(double slope, double yIntercept) {
Reported by PMD.
Line: 163
private static final class RegularLinearTransformation extends LinearTransformation {
final double slope;
final double yIntercept;
@CheckForNull @LazyInit LinearTransformation inverse;
RegularLinearTransformation(double slope, double yIntercept) {
Reported by PMD.
Line: 164
private static final class RegularLinearTransformation extends LinearTransformation {
final double slope;
final double yIntercept;
@CheckForNull @LazyInit LinearTransformation inverse;
RegularLinearTransformation(double slope, double yIntercept) {
this.slope = slope;
Reported by PMD.
Line: 166
final double slope;
final double yIntercept;
@CheckForNull @LazyInit LinearTransformation inverse;
RegularLinearTransformation(double slope, double yIntercept) {
this.slope = slope;
this.yIntercept = yIntercept;
this.inverse = null; // to be lazily initialized
Reported by PMD.
Line: 166
final double slope;
final double yIntercept;
@CheckForNull @LazyInit LinearTransformation inverse;
RegularLinearTransformation(double slope, double yIntercept) {
this.slope = slope;
this.yIntercept = yIntercept;
this.inverse = null; // to be lazily initialized
Reported by PMD.
Line: 171
RegularLinearTransformation(double slope, double yIntercept) {
this.slope = slope;
this.yIntercept = yIntercept;
this.inverse = null; // to be lazily initialized
}
RegularLinearTransformation(double slope, double yIntercept, LinearTransformation inverse) {
this.slope = slope;
this.yIntercept = yIntercept;
Reported by PMD.
Line: 212
}
private LinearTransformation createInverse() {
if (slope != 0.0) {
return new RegularLinearTransformation(1.0 / slope, -1.0 * yIntercept / slope, this);
} else {
return new VerticalLinearTransformation(yIntercept, this);
}
}
Reported by PMD.
Line: 222
private static final class VerticalLinearTransformation extends LinearTransformation {
final double x;
@CheckForNull @LazyInit LinearTransformation inverse;
VerticalLinearTransformation(double x) {
this.x = x;
Reported by PMD.
android/guava/src/com/google/common/io/CharStreams.java
13 issues
Line: 265
* @throws IOException if an I/O error occurs
*/
@Beta
public static void skipFully(Reader reader, long n) throws IOException {
checkNotNull(reader);
while (n > 0) {
long amt = reader.skip(n);
if (amt == 0) {
throw new EOFException();
Reported by PMD.
Line: 50
*/
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public final class CharStreams {
// 2K chars (4K bytes)
private static final int DEFAULT_BUF_SIZE = 0x800;
/** Creates a new {@code CharBuffer} for buffering reads or writes. */
Reported by PMD.
Line: 122
char[] buf = new char[DEFAULT_BUF_SIZE];
int nRead;
long total = 0;
while ((nRead = from.read(buf)) != -1) {
to.append(buf, 0, nRead);
total += nRead;
}
return total;
}
Reported by PMD.
Line: 150
char[] buf = new char[DEFAULT_BUF_SIZE];
int nRead;
long total = 0;
while ((nRead = from.read(buf)) != -1) {
to.write(buf, 0, nRead);
total += nRead;
}
return total;
}
Reported by PMD.
Line: 203
List<String> result = new ArrayList<>();
LineReader lineReader = new LineReader(r);
String line;
while ((line = lineReader.readLine()) != null) {
result.add(line);
}
return result;
}
Reported by PMD.
Line: 228
LineReader lineReader = new LineReader(readable);
String line;
while ((line = lineReader.readLine()) != null) {
if (!processor.processLine(line)) {
break;
}
}
return processor.getResult();
Reported by PMD.
Line: 248
long total = 0;
long read;
CharBuffer buf = createBuffer();
while ((read = readable.read(buf)) != -1) {
total += read;
Java8Compatibility.clear(buf);
}
return total;
}
Reported by PMD.
Line: 286
return NullWriter.INSTANCE;
}
private static final class NullWriter extends Writer {
private static final NullWriter INSTANCE = new NullWriter();
@Override
public void write(int c) {}
Reported by PMD.
Line: 122
char[] buf = new char[DEFAULT_BUF_SIZE];
int nRead;
long total = 0;
while ((nRead = from.read(buf)) != -1) {
to.append(buf, 0, nRead);
total += nRead;
}
return total;
}
Reported by PMD.
Line: 150
char[] buf = new char[DEFAULT_BUF_SIZE];
int nRead;
long total = 0;
while ((nRead = from.read(buf)) != -1) {
to.write(buf, 0, nRead);
total += nRead;
}
return total;
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/TestsForListsInJavaUtil.java
13 issues
Line: 53
* @author Kevin Bourrillion
*/
@GwtIncompatible
public class TestsForListsInJavaUtil {
public static Test suite() {
return new TestsForListsInJavaUtil().allTests();
}
public Test allTests() {
Reported by PMD.
Line: 54
*/
@GwtIncompatible
public class TestsForListsInJavaUtil {
public static Test suite() {
return new TestsForListsInJavaUtil().allTests();
}
public Test allTests() {
TestSuite suite = new TestSuite("java.util Lists");
Reported by PMD.
Line: 124
return Collections.emptySet();
}
public Test testsForEmptyList() {
return ListTestSuiteBuilder.using(
new TestStringListGenerator() {
@Override
public List<String> create(String[] elements) {
return Collections.emptyList();
Reported by PMD.
Line: 138
.createTestSuite();
}
public Test testsForSingletonList() {
return ListTestSuiteBuilder.using(
new TestStringListGenerator() {
@Override
public List<String> create(String[] elements) {
return Collections.singletonList(elements[0]);
Reported by PMD.
Line: 155
.createTestSuite();
}
public Test testsForArraysAsList() {
return ListTestSuiteBuilder.using(
new TestStringListGenerator() {
@Override
public List<String> create(String[] elements) {
return Arrays.asList(elements.clone());
Reported by PMD.
Line: 173
.createTestSuite();
}
public Test testsForArrayList() {
return ListTestSuiteBuilder.using(
new TestStringListGenerator() {
@Override
public List<String> create(String[] elements) {
return new ArrayList<>(MinimalCollection.of(elements));
Reported by PMD.
Line: 192
.createTestSuite();
}
public Test testsForLinkedList() {
return ListTestSuiteBuilder.using(
new TestStringListGenerator() {
@Override
public List<String> create(String[] elements) {
return new LinkedList<>(MinimalCollection.of(elements));
Reported by PMD.
Line: 211
.createTestSuite();
}
public Test testsForCopyOnWriteArrayList() {
return ListTestSuiteBuilder.using(
new TestStringListGenerator() {
@Override
public List<String> create(String[] elements) {
return new CopyOnWriteArrayList<>(MinimalCollection.of(elements));
Reported by PMD.
Line: 233
.createTestSuite();
}
public Test testsForUnmodifiableList() {
return ListTestSuiteBuilder.using(
new TestStringListGenerator() {
@Override
public List<String> create(String[] elements) {
List<String> innerList = new ArrayList<>();
Reported by PMD.
Line: 252
.createTestSuite();
}
public Test testsForCheckedList() {
return ListTestSuiteBuilder.using(
new TestStringListGenerator() {
@Override
public List<String> create(String[] elements) {
List<String> innerList = new ArrayList<>();
Reported by PMD.
android/guava/src/com/google/common/collect/ForwardingList.java
13 issues
Line: 57
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class ForwardingList<E extends @Nullable Object> extends ForwardingCollection<E>
implements List<E> {
// TODO(lowasser): identify places where thread safety is actually lost
/** Constructor for use by subclasses. */
protected ForwardingList() {}
Reported by PMD.
Line: 68
@Override
public void add(int index, @ParametricNullness E element) {
delegate().add(index, element);
}
@CanIgnoreReturnValue
@Override
public boolean addAll(int index, Collection<? extends E> elements) {
Reported by PMD.
Line: 74
@CanIgnoreReturnValue
@Override
public boolean addAll(int index, Collection<? extends E> elements) {
return delegate().addAll(index, elements);
}
@Override
@ParametricNullness
public E get(int index) {
Reported by PMD.
Line: 80
@Override
@ParametricNullness
public E get(int index) {
return delegate().get(index);
}
@Override
public int indexOf(@CheckForNull Object element) {
return delegate().indexOf(element);
Reported by PMD.
Line: 85
@Override
public int indexOf(@CheckForNull Object element) {
return delegate().indexOf(element);
}
@Override
public int lastIndexOf(@CheckForNull Object element) {
return delegate().lastIndexOf(element);
Reported by PMD.
Line: 90
@Override
public int lastIndexOf(@CheckForNull Object element) {
return delegate().lastIndexOf(element);
}
@Override
public ListIterator<E> listIterator() {
return delegate().listIterator();
Reported by PMD.
Line: 95
@Override
public ListIterator<E> listIterator() {
return delegate().listIterator();
}
@Override
public ListIterator<E> listIterator(int index) {
return delegate().listIterator(index);
Reported by PMD.
Line: 100
@Override
public ListIterator<E> listIterator(int index) {
return delegate().listIterator(index);
}
@CanIgnoreReturnValue
@Override
@ParametricNullness
Reported by PMD.
Line: 107
@Override
@ParametricNullness
public E remove(int index) {
return delegate().remove(index);
}
@CanIgnoreReturnValue
@Override
@ParametricNullness
Reported by PMD.
Line: 114
@Override
@ParametricNullness
public E set(int index, @ParametricNullness E element) {
return delegate().set(index, element);
}
@Override
public List<E> subList(int fromIndex, int toIndex) {
return delegate().subList(fromIndex, toIndex);
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/google/MultimapEqualsTester.java
13 issues
Line: 40
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapEqualsTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
public void testEqualsTrue() {
new EqualsTester()
.addEqualityGroup(multimap(), getSubjectGenerator().create(getSampleElements().toArray()))
.testEquals();
}
Reported by PMD.
Line: 42
public class MultimapEqualsTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
public void testEqualsTrue() {
new EqualsTester()
.addEqualityGroup(multimap(), getSubjectGenerator().create(getSampleElements().toArray()))
.testEquals();
}
public void testEqualsFalse() {
List<Entry<K, V>> targetEntries = new ArrayList<>(getSampleElements());
Reported by PMD.
Line: 42
public class MultimapEqualsTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
public void testEqualsTrue() {
new EqualsTester()
.addEqualityGroup(multimap(), getSubjectGenerator().create(getSampleElements().toArray()))
.testEquals();
}
public void testEqualsFalse() {
List<Entry<K, V>> targetEntries = new ArrayList<>(getSampleElements());
Reported by PMD.
Line: 46
.testEquals();
}
public void testEqualsFalse() {
List<Entry<K, V>> targetEntries = new ArrayList<>(getSampleElements());
targetEntries.add(Helpers.mapEntry(k0(), v3()));
new EqualsTester()
.addEqualityGroup(multimap())
.addEqualityGroup(getSubjectGenerator().create(targetEntries.toArray()))
Reported by PMD.
Line: 51
targetEntries.add(Helpers.mapEntry(k0(), v3()));
new EqualsTester()
.addEqualityGroup(multimap())
.addEqualityGroup(getSubjectGenerator().create(targetEntries.toArray()))
.testEquals();
}
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(ALLOWS_NULL_KEYS)
Reported by PMD.
Line: 55
.testEquals();
}
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(ALLOWS_NULL_KEYS)
public void testEqualsMultimapWithNullKey() {
Multimap<K, V> original = multimap();
initMultimapWithNullKey();
Multimap<K, V> withNull = multimap();
Reported by PMD.
Line: 68
.testEquals();
}
@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(ALLOWS_NULL_VALUES)
public void testEqualsMultimapWithNullValue() {
Multimap<K, V> original = multimap();
initMultimapWithNullValue();
Multimap<K, V> withNull = multimap();
Reported by PMD.
Line: 81
.testEquals();
}
@CollectionSize.Require(absent = ZERO)
public void testNotEqualsEmpty() {
new EqualsTester()
.addEqualityGroup(multimap())
.addEqualityGroup(getSubjectGenerator().create())
.testEquals();
Reported by PMD.
Line: 85
public void testNotEqualsEmpty() {
new EqualsTester()
.addEqualityGroup(multimap())
.addEqualityGroup(getSubjectGenerator().create())
.testEquals();
}
public void testHashCodeMatchesAsMap() {
assertEquals(multimap().asMap().hashCode(), multimap().hashCode());
Reported by PMD.
Line: 89
.testEquals();
}
public void testHashCodeMatchesAsMap() {
assertEquals(multimap().asMap().hashCode(), multimap().hashCode());
}
}
Reported by PMD.
android/guava/src/com/google/common/escape/UnicodeEscaper.java
13 issues
Line: 160
* @throws NullPointerException if {@code string} is null
* @throws IllegalArgumentException if invalid surrogate characters are encountered
*/
protected final String escapeSlow(String s, int index) {
int end = s.length();
// Get a destination buffer and setup some loop variables.
char[] dest = Platform.charBufferFromThreadLocal();
int destIndex = 0;
Reported by PMD.
Line: 248
* @return the Unicode code point for the given index or the negated value of the trailing high
* surrogate character at the end of the sequence
*/
protected static int codePointAt(CharSequence seq, int index, int end) {
checkNotNull(seq);
if (index < end) {
char c1 = seq.charAt(index++);
if (c1 < Character.MIN_HIGH_SURROGATE || c1 > Character.MAX_LOW_SURROGATE) {
// Fast path (first test is probably all we need to do)
Reported by PMD.
Line: 56
@Beta
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class UnicodeEscaper extends Escaper {
/** The amount of padding (chars) to use when growing the escape buffer. */
private static final int DEST_PAD = 32;
/** Constructor for use by subclasses. */
protected UnicodeEscaper() {}
Reported by PMD.
Line: 56
@Beta
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class UnicodeEscaper extends Escaper {
/** The amount of padding (chars) to use when growing the escape buffer. */
private static final int DEST_PAD = 32;
/** Constructor for use by subclasses. */
protected UnicodeEscaper() {}
Reported by PMD.
Line: 160
* @throws NullPointerException if {@code string} is null
* @throws IllegalArgumentException if invalid surrogate characters are encountered
*/
protected final String escapeSlow(String s, int index) {
int end = s.length();
// Get a destination buffer and setup some loop variables.
char[] dest = Platform.charBufferFromThreadLocal();
int destIndex = 0;
Reported by PMD.
Line: 160
* @throws NullPointerException if {@code string} is null
* @throws IllegalArgumentException if invalid surrogate characters are encountered
*/
protected final String escapeSlow(String s, int index) {
int end = s.length();
// Get a destination buffer and setup some loop variables.
char[] dest = Platform.charBufferFromThreadLocal();
int destIndex = 0;
Reported by PMD.
Line: 160
* @throws NullPointerException if {@code string} is null
* @throws IllegalArgumentException if invalid surrogate characters are encountered
*/
protected final String escapeSlow(String s, int index) {
int end = s.length();
// Get a destination buffer and setup some loop variables.
char[] dest = Platform.charBufferFromThreadLocal();
int destIndex = 0;
Reported by PMD.
Line: 248
* @return the Unicode code point for the given index or the negated value of the trailing high
* surrogate character at the end of the sequence
*/
protected static int codePointAt(CharSequence seq, int index, int end) {
checkNotNull(seq);
if (index < end) {
char c1 = seq.charAt(index++);
if (c1 < Character.MIN_HIGH_SURROGATE || c1 > Character.MAX_LOW_SURROGATE) {
// Fast path (first test is probably all we need to do)
Reported by PMD.
Line: 164
int end = s.length();
// Get a destination buffer and setup some loop variables.
char[] dest = Platform.charBufferFromThreadLocal();
int destIndex = 0;
int unescapedChunkStart = 0;
while (index < end) {
int cp = codePointAt(s, index, end);
Reported by PMD.
Line: 165
// Get a destination buffer and setup some loop variables.
char[] dest = Platform.charBufferFromThreadLocal();
int destIndex = 0;
int unescapedChunkStart = 0;
while (index < end) {
int cp = codePointAt(s, index, end);
if (cp < 0) {
Reported by PMD.
android/guava-tests/test/com/google/common/util/concurrent/FuturesGetDoneTest.java
13 issues
Line: 31
/** Unit tests for {@link Futures#getDone}. */
@GwtCompatible
public class FuturesGetDoneTest extends TestCase {
public void testSuccessful() throws ExecutionException {
assertThat(getDone(immediateFuture("a"))).isEqualTo("a");
}
public void testSuccessfulNull() throws ExecutionException {
assertThat(getDone(immediateFuture((String) null))).isEqualTo(null);
Reported by PMD.
Line: 32
@GwtCompatible
public class FuturesGetDoneTest extends TestCase {
public void testSuccessful() throws ExecutionException {
assertThat(getDone(immediateFuture("a"))).isEqualTo("a");
}
public void testSuccessfulNull() throws ExecutionException {
assertThat(getDone(immediateFuture((String) null))).isEqualTo(null);
}
Reported by PMD.
Line: 35
assertThat(getDone(immediateFuture("a"))).isEqualTo("a");
}
public void testSuccessfulNull() throws ExecutionException {
assertThat(getDone(immediateFuture((String) null))).isEqualTo(null);
}
public void testFailed() {
Exception failureCause = new Exception();
Reported by PMD.
Line: 39
assertThat(getDone(immediateFuture((String) null))).isEqualTo(null);
}
public void testFailed() {
Exception failureCause = new Exception();
try {
getDone(immediateFailedFuture(failureCause));
fail();
} catch (ExecutionException expected) {
Reported by PMD.
Line: 43
Exception failureCause = new Exception();
try {
getDone(immediateFailedFuture(failureCause));
fail();
} catch (ExecutionException expected) {
assertThat(expected).hasCauseThat().isEqualTo(failureCause);
}
}
Reported by PMD.
Line: 45
getDone(immediateFailedFuture(failureCause));
fail();
} catch (ExecutionException expected) {
assertThat(expected).hasCauseThat().isEqualTo(failureCause);
}
}
public void testCancelled() throws ExecutionException {
try {
Reported by PMD.
Line: 45
getDone(immediateFailedFuture(failureCause));
fail();
} catch (ExecutionException expected) {
assertThat(expected).hasCauseThat().isEqualTo(failureCause);
}
}
public void testCancelled() throws ExecutionException {
try {
Reported by PMD.
Line: 49
}
}
public void testCancelled() throws ExecutionException {
try {
getDone(immediateCancelledFuture());
fail();
} catch (CancellationException expected) {
}
Reported by PMD.
Line: 52
public void testCancelled() throws ExecutionException {
try {
getDone(immediateCancelledFuture());
fail();
} catch (CancellationException expected) {
}
}
public void testPending() throws ExecutionException {
Reported by PMD.
Line: 52
public void testCancelled() throws ExecutionException {
try {
getDone(immediateCancelledFuture());
fail();
} catch (CancellationException expected) {
}
}
public void testPending() throws ExecutionException {
Reported by PMD.
android/guava/src/com/google/common/util/concurrent/TimeoutFuture.java
13 issues
Line: 76
* write-barriers).
*/
@CheckForNull private ListenableFuture<V> delegateRef;
@CheckForNull private ScheduledFuture<?> timer;
private TimeoutFuture(ListenableFuture<V> delegate) {
this.delegateRef = Preconditions.checkNotNull(delegate);
}
Reported by PMD.
Line: 77
*/
@CheckForNull private ListenableFuture<V> delegateRef;
@CheckForNull private ScheduledFuture<?> timer;
private TimeoutFuture(ListenableFuture<V> delegate) {
this.delegateRef = Preconditions.checkNotNull(delegate);
}
Reported by PMD.
Line: 85
/** A runnable that is called when the delegate or the timer completes. */
private static final class Fire<V extends @Nullable Object> implements Runnable {
@CheckForNull TimeoutFuture<V> timeoutFutureRef;
Fire(TimeoutFuture<V> timeoutFuture) {
this.timeoutFutureRef = timeoutFuture;
}
Reported by PMD.
Line: 116
* important for other reasons: run() can still be invoked concurrently in different threads,
* even with the above null checks.)
*/
timeoutFutureRef = null;
if (delegate.isDone()) {
timeoutFuture.setFuture(delegate);
} else {
try {
ScheduledFuture<?> timer = timeoutFuture.timer;
Reported by PMD.
Line: 117
* even with the above null checks.)
*/
timeoutFutureRef = null;
if (delegate.isDone()) {
timeoutFuture.setFuture(delegate);
} else {
try {
ScheduledFuture<?> timer = timeoutFuture.timer;
timeoutFuture.timer = null; // Don't include already elapsed delay in delegate.toString()
Reported by PMD.
Line: 122
} else {
try {
ScheduledFuture<?> timer = timeoutFuture.timer;
timeoutFuture.timer = null; // Don't include already elapsed delay in delegate.toString()
String message = "Timed out";
// This try-finally block ensures that we complete the timeout future, even if attempting
// to produce the message throws (probably StackOverflowError from delegate.toString())
try {
if (timer != null) {
Reported by PMD.
Line: 128
// to produce the message throws (probably StackOverflowError from delegate.toString())
try {
if (timer != null) {
long overDelayMs = Math.abs(timer.getDelay(TimeUnit.MILLISECONDS));
if (overDelayMs > 10) { // Not all timing drift is worth reporting
message += " (timeout delayed by " + overDelayMs + " ms after scheduled time)";
}
}
message += ": " + delegate;
Reported by PMD.
Line: 129
try {
if (timer != null) {
long overDelayMs = Math.abs(timer.getDelay(TimeUnit.MILLISECONDS));
if (overDelayMs > 10) { // Not all timing drift is worth reporting
message += " (timeout delayed by " + overDelayMs + " ms after scheduled time)";
}
}
message += ": " + delegate;
} finally {
Reported by PMD.
Line: 133
message += " (timeout delayed by " + overDelayMs + " ms after scheduled time)";
}
}
message += ": " + delegate;
} finally {
timeoutFuture.setException(new TimeoutFutureException(message));
}
} finally {
delegate.cancel(true);
Reported by PMD.
Line: 144
}
}
private static final class TimeoutFutureException extends TimeoutException {
private TimeoutFutureException(String message) {
super(message);
}
@Override
Reported by PMD.