The following issues were found
guava-tests/test/com/google/common/collect/SynchronizedQueueTest.java
43 issues
Line: 36
TestQueue<String> inner = new TestQueue<>();
Queue<String> outer = Synchronized.queue(inner, null);
inner.mutex = outer;
outer.add("foo"); // necessary because we try to remove elements later on
return outer;
}
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
Reported by PMD.
Line: 36
TestQueue<String> inner = new TestQueue<>();
Queue<String> outer = Synchronized.queue(inner, null);
inner.mutex = outer;
outer.add("foo"); // necessary because we try to remove elements later on
return outer;
}
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
Reported by PMD.
Line: 40
return outer;
}
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
public Object mutex;
@Override
public boolean offer(E o) {
Reported by PMD.
Line: 41
}
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
public Object mutex;
@Override
public boolean offer(E o) {
assertTrue(Thread.holdsLock(mutex));
Reported by PMD.
Line: 42
private static final class TestQueue<E> implements Queue<E> {
private final Queue<E> delegate = Lists.newLinkedList();
public Object mutex;
@Override
public boolean offer(E o) {
assertTrue(Thread.holdsLock(mutex));
return delegate.offer(o);
Reported by PMD.
Line: 46
@Override
public boolean offer(E o) {
assertTrue(Thread.holdsLock(mutex));
return delegate.offer(o);
}
@Override
public E poll() {
Reported by PMD.
Line: 52
@Override
public E poll() {
assertTrue(Thread.holdsLock(mutex));
return delegate.poll();
}
@Override
public E remove() {
Reported by PMD.
Line: 58
@Override
public E remove() {
assertTrue(Thread.holdsLock(mutex));
return delegate.remove();
}
@Override
public boolean remove(Object object) {
Reported by PMD.
Line: 64
@Override
public boolean remove(Object object) {
assertTrue(Thread.holdsLock(mutex));
return delegate.remove(object);
}
@Override
public E peek() {
Reported by PMD.
Line: 70
@Override
public E peek() {
assertTrue(Thread.holdsLock(mutex));
return delegate.peek();
}
@Override
public E element() {
Reported by PMD.
guava-tests/test/com/google/common/collect/MutableClassToInstanceMapTest.java
42 issues
Line: 85
* because we know that newClassMap() is implemented using ConstrainedMap which is itself
* well-tested. A purist would object to this, but what can I say, we're dirty cheaters.
*/
map.put(Integer.class, new Integer(5));
try {
map.put(Double.class, new Long(42));
fail();
} catch (ClassCastException expected) {
}
Reported by PMD.
Line: 87
*/
map.put(Integer.class, new Integer(5));
try {
map.put(Double.class, new Long(42));
fail();
} catch (ClassCastException expected) {
}
// Won't compile: map.put(String.class, "x");
}
Reported by PMD.
Line: 95
}
public void testPutAndGetInstance() {
assertNull(map.putInstance(Integer.class, new Integer(5)));
Integer oldValue = map.putInstance(Integer.class, new Integer(7));
assertEquals(5, (int) oldValue);
Integer newValue = map.getInstance(Integer.class);
Reported by PMD.
Line: 97
public void testPutAndGetInstance() {
assertNull(map.putInstance(Integer.class, new Integer(5)));
Integer oldValue = map.putInstance(Integer.class, new Integer(7));
assertEquals(5, (int) oldValue);
Integer newValue = map.getInstance(Integer.class);
assertEquals(7, (int) newValue);
Reported by PMD.
Line: 108
public void testNull() {
try {
map.put(null, new Integer(1));
fail();
} catch (NullPointerException expected) {
}
map.putInstance(Integer.class, null);
assertNull(map.get(Integer.class));
Reported by PMD.
Line: 37
* @author Kevin Bourrillion
*/
public class MutableClassToInstanceMapTest extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(MutableClassToInstanceMapTest.class);
suite.addTest(
MapTestSuiteBuilder.using(
Reported by PMD.
Line: 52
MutableClassToInstanceMap<Impl> map = MutableClassToInstanceMap.create();
for (Object object : elements) {
Entry<Class, Impl> entry = (Entry<Class, Impl>) object;
map.putInstance(entry.getKey(), entry.getValue());
}
return (Map) map;
}
})
.named("MutableClassToInstanceMap")
Reported by PMD.
Line: 52
MutableClassToInstanceMap<Impl> map = MutableClassToInstanceMap.create();
for (Object object : elements) {
Entry<Class, Impl> entry = (Entry<Class, Impl>) object;
map.putInstance(entry.getKey(), entry.getValue());
}
return (Map) map;
}
})
.named("MutableClassToInstanceMap")
Reported by PMD.
Line: 71
return suite;
}
private ClassToInstanceMap<Number> map;
@Override
protected void setUp() throws Exception {
map = MutableClassToInstanceMap.create();
}
Reported by PMD.
Line: 73
private ClassToInstanceMap<Number> map;
@Override
protected void setUp() throws Exception {
map = MutableClassToInstanceMap.create();
}
public void testConstraint() {
Reported by PMD.
guava-testlib/test/com/google/common/collect/testing/features/FeatureUtilTest.java
42 issues
Line: 106
@ExampleDerivedFeature.Require({ExampleDerivedFeature.DERIVED_FEATURE_2})
private static class ExampleDerivedInterfaceTester extends ExampleBaseInterfaceTester {
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
@ExampleDerivedFeature.Require({
ExampleDerivedFeature.DERIVED_FEATURE_1,
ExampleDerivedFeature.DERIVED_FEATURE_2
})
public void testRequiringTwoExplicitDerivedFeatures() throws Exception {
Reported by PMD.
Line: 111
ExampleDerivedFeature.DERIVED_FEATURE_1,
ExampleDerivedFeature.DERIVED_FEATURE_2
})
public void testRequiringTwoExplicitDerivedFeatures() throws Exception {
doNotActuallyRunThis();
}
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
Reported by PMD.
Line: 116
}
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
@ExampleDerivedFeature.Require({
ExampleDerivedFeature.DERIVED_FEATURE_1,
ExampleDerivedFeature.DERIVED_FEATURE_3
})
public void testRequiringAllThreeDerivedFeatures() {
Reported by PMD.
Line: 121
ExampleDerivedFeature.DERIVED_FEATURE_1,
ExampleDerivedFeature.DERIVED_FEATURE_3
})
public void testRequiringAllThreeDerivedFeatures() {
doNotActuallyRunThis();
}
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
Reported by PMD.
Line: 126
}
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
@ExampleBaseFeature.Require(absent = {ExampleBaseFeature.BASE_FEATURE_1})
public void testRequiringConflictingFeatures() throws Exception {
doNotActuallyRunThis();
}
}
Reported by PMD.
Line: 128
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
@ExampleBaseFeature.Require(absent = {ExampleBaseFeature.BASE_FEATURE_1})
public void testRequiringConflictingFeatures() throws Exception {
doNotActuallyRunThis();
}
}
@ExampleDerivedFeature.Require(absent = {ExampleDerivedFeature.DERIVED_FEATURE_2})
Reported by PMD.
Line: 137
private static class ConflictingRequirementsExampleDerivedInterfaceTester
extends ExampleBaseInterfaceTester {}
public void testTestFeatureEnums() throws Exception {
// Haha! Let's test our own test rig!
FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleBaseFeature.class);
FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
}
Reported by PMD.
Line: 137
private static class ConflictingRequirementsExampleDerivedInterfaceTester
extends ExampleBaseInterfaceTester {}
public void testTestFeatureEnums() throws Exception {
// Haha! Let's test our own test rig!
FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleBaseFeature.class);
FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
}
Reported by PMD.
Line: 143
FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
}
public void testAddImpliedFeatures_returnsSameSetInstance() throws Exception {
Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(ExampleBaseFeature.BASE_FEATURE_1);
assertSame(features, FeatureUtil.addImpliedFeatures(features));
}
public void testAddImpliedFeatures_addsImpliedFeatures() throws Exception {
Reported by PMD.
Line: 145
public void testAddImpliedFeatures_returnsSameSetInstance() throws Exception {
Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(ExampleBaseFeature.BASE_FEATURE_1);
assertSame(features, FeatureUtil.addImpliedFeatures(features));
}
public void testAddImpliedFeatures_addsImpliedFeatures() throws Exception {
Set<Feature<?>> features;
Reported by PMD.
guava-tests/test/com/google/common/io/LittleEndianDataOutputStreamTest.java
42 issues
Line: 35
*/
public class LittleEndianDataOutputStreamTest extends TestCase {
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
Reported by PMD.
Line: 35
*/
public class LittleEndianDataOutputStreamTest extends TestCase {
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
Reported by PMD.
Line: 36
public class LittleEndianDataOutputStreamTest extends TestCase {
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.write(new byte[] {-100, 100});
Reported by PMD.
Line: 36
public class LittleEndianDataOutputStreamTest extends TestCase {
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.write(new byte[] {-100, 100});
Reported by PMD.
Line: 38
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.write(new byte[] {-100, 100});
out.writeBoolean(true);
out.writeBoolean(false);
Reported by PMD.
Line: 38
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.write(new byte[] {-100, 100});
out.writeBoolean(true);
out.writeBoolean(false);
Reported by PMD.
Line: 64
/* Read in various values NORMALLY */
byte[] b = new byte[2];
in.readFully(b);
assertEquals(-100, b[0]);
assertEquals(100, b[1]);
assertEquals(true, in.readBoolean());
assertEquals(false, in.readBoolean());
assertEquals(100, in.readByte());
assertEquals(-100, in.readByte());
Reported by PMD.
Line: 65
byte[] b = new byte[2];
in.readFully(b);
assertEquals(-100, b[0]);
assertEquals(100, b[1]);
assertEquals(true, in.readBoolean());
assertEquals(false, in.readBoolean());
assertEquals(100, in.readByte());
assertEquals(-100, in.readByte());
assertEquals(200, in.readUnsignedByte());
Reported by PMD.
Line: 66
in.readFully(b);
assertEquals(-100, b[0]);
assertEquals(100, b[1]);
assertEquals(true, in.readBoolean());
assertEquals(false, in.readBoolean());
assertEquals(100, in.readByte());
assertEquals(-100, in.readByte());
assertEquals(200, in.readUnsignedByte());
assertEquals('\u6100', in.readChar());
Reported by PMD.
Line: 66
in.readFully(b);
assertEquals(-100, b[0]);
assertEquals(100, b[1]);
assertEquals(true, in.readBoolean());
assertEquals(false, in.readBoolean());
assertEquals(100, in.readByte());
assertEquals(-100, in.readByte());
assertEquals(200, in.readUnsignedByte());
assertEquals('\u6100', in.readChar());
Reported by PMD.
android/guava/src/com/google/common/io/CharSource.java
42 issues
Line: 81
*/
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public abstract class CharSource {
/** Constructor for use by subclasses. */
protected CharSource() {}
/**
Reported by PMD.
Line: 168
@Beta
public long length() throws IOException {
Optional<Long> lengthIfKnown = lengthIfKnown();
if (lengthIfKnown.isPresent()) {
return lengthIfKnown.get();
}
Closer closer = Closer.create();
try {
Reported by PMD.
Line: 174
Closer closer = Closer.create();
try {
Reader reader = closer.register(openStream());
return countBySkipping(reader);
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
Reported by PMD.
Line: 176
try {
Reader reader = closer.register(openStream());
return countBySkipping(reader);
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
Reported by PMD.
Line: 186
private long countBySkipping(Reader reader) throws IOException {
long count = 0;
long read;
while ((read = reader.skip(Long.MAX_VALUE)) != 0) {
count += read;
}
return count;
}
Reported by PMD.
Line: 206
Closer closer = Closer.create();
try {
Reader reader = closer.register(openStream());
return CharStreams.copy(reader, appendable);
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
Reported by PMD.
Line: 208
try {
Reader reader = closer.register(openStream());
return CharStreams.copy(reader, appendable);
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
Reported by PMD.
Line: 228
Closer closer = Closer.create();
try {
Reader reader = closer.register(openStream());
Writer writer = closer.register(sink.openStream());
return CharStreams.copy(reader, writer);
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
Reported by PMD.
Line: 229
Closer closer = Closer.create();
try {
Reader reader = closer.register(openStream());
Writer writer = closer.register(sink.openStream());
return CharStreams.copy(reader, writer);
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
Reported by PMD.
Line: 231
Reader reader = closer.register(openStream());
Writer writer = closer.register(sink.openStream());
return CharStreams.copy(reader, writer);
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
Reported by PMD.
android/guava-testlib/test/com/google/common/collect/testing/features/FeatureUtilTest.java
42 issues
Line: 106
@ExampleDerivedFeature.Require({ExampleDerivedFeature.DERIVED_FEATURE_2})
private static class ExampleDerivedInterfaceTester extends ExampleBaseInterfaceTester {
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
@ExampleDerivedFeature.Require({
ExampleDerivedFeature.DERIVED_FEATURE_1,
ExampleDerivedFeature.DERIVED_FEATURE_2
})
public void testRequiringTwoExplicitDerivedFeatures() throws Exception {
Reported by PMD.
Line: 111
ExampleDerivedFeature.DERIVED_FEATURE_1,
ExampleDerivedFeature.DERIVED_FEATURE_2
})
public void testRequiringTwoExplicitDerivedFeatures() throws Exception {
doNotActuallyRunThis();
}
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
Reported by PMD.
Line: 116
}
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
@ExampleDerivedFeature.Require({
ExampleDerivedFeature.DERIVED_FEATURE_1,
ExampleDerivedFeature.DERIVED_FEATURE_3
})
public void testRequiringAllThreeDerivedFeatures() {
Reported by PMD.
Line: 121
ExampleDerivedFeature.DERIVED_FEATURE_1,
ExampleDerivedFeature.DERIVED_FEATURE_3
})
public void testRequiringAllThreeDerivedFeatures() {
doNotActuallyRunThis();
}
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
Reported by PMD.
Line: 126
}
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
@ExampleBaseFeature.Require(absent = {ExampleBaseFeature.BASE_FEATURE_1})
public void testRequiringConflictingFeatures() throws Exception {
doNotActuallyRunThis();
}
}
Reported by PMD.
Line: 128
// Exists to test that our framework doesn't run it:
@SuppressWarnings("unused")
@ExampleBaseFeature.Require(absent = {ExampleBaseFeature.BASE_FEATURE_1})
public void testRequiringConflictingFeatures() throws Exception {
doNotActuallyRunThis();
}
}
@ExampleDerivedFeature.Require(absent = {ExampleDerivedFeature.DERIVED_FEATURE_2})
Reported by PMD.
Line: 137
private static class ConflictingRequirementsExampleDerivedInterfaceTester
extends ExampleBaseInterfaceTester {}
public void testTestFeatureEnums() throws Exception {
// Haha! Let's test our own test rig!
FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleBaseFeature.class);
FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
}
Reported by PMD.
Line: 137
private static class ConflictingRequirementsExampleDerivedInterfaceTester
extends ExampleBaseInterfaceTester {}
public void testTestFeatureEnums() throws Exception {
// Haha! Let's test our own test rig!
FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleBaseFeature.class);
FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
}
Reported by PMD.
Line: 143
FeatureEnumTest.assertGoodFeatureEnum(FeatureUtilTest.ExampleDerivedFeature.class);
}
public void testAddImpliedFeatures_returnsSameSetInstance() throws Exception {
Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(ExampleBaseFeature.BASE_FEATURE_1);
assertSame(features, FeatureUtil.addImpliedFeatures(features));
}
public void testAddImpliedFeatures_addsImpliedFeatures() throws Exception {
Reported by PMD.
Line: 145
public void testAddImpliedFeatures_returnsSameSetInstance() throws Exception {
Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(ExampleBaseFeature.BASE_FEATURE_1);
assertSame(features, FeatureUtil.addImpliedFeatures(features));
}
public void testAddImpliedFeatures_addsImpliedFeatures() throws Exception {
Set<Feature<?>> features;
Reported by PMD.
android/guava-tests/test/com/google/common/collect/MutableClassToInstanceMapTest.java
42 issues
Line: 85
* because we know that newClassMap() is implemented using ConstrainedMap which is itself
* well-tested. A purist would object to this, but what can I say, we're dirty cheaters.
*/
map.put(Integer.class, new Integer(5));
try {
map.put(Double.class, new Long(42));
fail();
} catch (ClassCastException expected) {
}
Reported by PMD.
Line: 87
*/
map.put(Integer.class, new Integer(5));
try {
map.put(Double.class, new Long(42));
fail();
} catch (ClassCastException expected) {
}
// Won't compile: map.put(String.class, "x");
}
Reported by PMD.
Line: 95
}
public void testPutAndGetInstance() {
assertNull(map.putInstance(Integer.class, new Integer(5)));
Integer oldValue = map.putInstance(Integer.class, new Integer(7));
assertEquals(5, (int) oldValue);
Integer newValue = map.getInstance(Integer.class);
Reported by PMD.
Line: 97
public void testPutAndGetInstance() {
assertNull(map.putInstance(Integer.class, new Integer(5)));
Integer oldValue = map.putInstance(Integer.class, new Integer(7));
assertEquals(5, (int) oldValue);
Integer newValue = map.getInstance(Integer.class);
assertEquals(7, (int) newValue);
Reported by PMD.
Line: 108
public void testNull() {
try {
map.put(null, new Integer(1));
fail();
} catch (NullPointerException expected) {
}
map.putInstance(Integer.class, null);
assertNull(map.get(Integer.class));
Reported by PMD.
Line: 37
* @author Kevin Bourrillion
*/
public class MutableClassToInstanceMapTest extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(MutableClassToInstanceMapTest.class);
suite.addTest(
MapTestSuiteBuilder.using(
Reported by PMD.
Line: 52
MutableClassToInstanceMap<Impl> map = MutableClassToInstanceMap.create();
for (Object object : elements) {
Entry<Class, Impl> entry = (Entry<Class, Impl>) object;
map.putInstance(entry.getKey(), entry.getValue());
}
return (Map) map;
}
})
.named("MutableClassToInstanceMap")
Reported by PMD.
Line: 52
MutableClassToInstanceMap<Impl> map = MutableClassToInstanceMap.create();
for (Object object : elements) {
Entry<Class, Impl> entry = (Entry<Class, Impl>) object;
map.putInstance(entry.getKey(), entry.getValue());
}
return (Map) map;
}
})
.named("MutableClassToInstanceMap")
Reported by PMD.
Line: 71
return suite;
}
private ClassToInstanceMap<Number> map;
@Override
protected void setUp() throws Exception {
map = MutableClassToInstanceMap.create();
}
Reported by PMD.
Line: 73
private ClassToInstanceMap<Number> map;
@Override
protected void setUp() throws Exception {
map = MutableClassToInstanceMap.create();
}
public void testConstraint() {
Reported by PMD.
android/guava-tests/test/com/google/common/io/LittleEndianDataOutputStreamTest.java
42 issues
Line: 35
*/
public class LittleEndianDataOutputStreamTest extends TestCase {
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
Reported by PMD.
Line: 35
*/
public class LittleEndianDataOutputStreamTest extends TestCase {
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
Reported by PMD.
Line: 36
public class LittleEndianDataOutputStreamTest extends TestCase {
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.write(new byte[] {-100, 100});
Reported by PMD.
Line: 36
public class LittleEndianDataOutputStreamTest extends TestCase {
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.write(new byte[] {-100, 100});
Reported by PMD.
Line: 38
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.write(new byte[] {-100, 100});
out.writeBoolean(true);
out.writeBoolean(false);
Reported by PMD.
Line: 38
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(baos);
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.write(new byte[] {-100, 100});
out.writeBoolean(true);
out.writeBoolean(false);
Reported by PMD.
Line: 64
/* Read in various values NORMALLY */
byte[] b = new byte[2];
in.readFully(b);
assertEquals(-100, b[0]);
assertEquals(100, b[1]);
assertEquals(true, in.readBoolean());
assertEquals(false, in.readBoolean());
assertEquals(100, in.readByte());
assertEquals(-100, in.readByte());
Reported by PMD.
Line: 65
byte[] b = new byte[2];
in.readFully(b);
assertEquals(-100, b[0]);
assertEquals(100, b[1]);
assertEquals(true, in.readBoolean());
assertEquals(false, in.readBoolean());
assertEquals(100, in.readByte());
assertEquals(-100, in.readByte());
assertEquals(200, in.readUnsignedByte());
Reported by PMD.
Line: 66
in.readFully(b);
assertEquals(-100, b[0]);
assertEquals(100, b[1]);
assertEquals(true, in.readBoolean());
assertEquals(false, in.readBoolean());
assertEquals(100, in.readByte());
assertEquals(-100, in.readByte());
assertEquals(200, in.readUnsignedByte());
assertEquals('\u6100', in.readChar());
Reported by PMD.
Line: 66
in.readFully(b);
assertEquals(-100, b[0]);
assertEquals(100, b[1]);
assertEquals(true, in.readBoolean());
assertEquals(false, in.readBoolean());
assertEquals(100, in.readByte());
assertEquals(-100, in.readByte());
assertEquals(200, in.readUnsignedByte());
assertEquals('\u6100', in.readChar());
Reported by PMD.
guava/src/com/google/common/util/concurrent/AbstractScheduledService.java
42 issues
Line: 104
*/
@GwtIncompatible
@ElementTypesAreNonnullByDefault
public abstract class AbstractScheduledService implements Service {
private static final Logger logger = Logger.getLogger(AbstractScheduledService.class.getName());
/**
* A scheduler defines the policy for how the {@link AbstractScheduledService} should run its
* task.
Reported by PMD.
Line: 202
}
/* use AbstractService for state management */
private final AbstractService delegate = new ServiceDelegate();
@WeakOuter
private final class ServiceDelegate extends AbstractService {
// A handle to the running task so that we can stop it when a shutdown has been requested.
Reported by PMD.
Line: 209
// A handle to the running task so that we can stop it when a shutdown has been requested.
// These two fields are volatile because their values will be accessed from multiple threads.
@CheckForNull private volatile Cancellable runningTask;
@CheckForNull private volatile ScheduledExecutorService executorService;
// This lock protects the task so we can ensure that none of the template methods (startUp,
// shutDown or runOneIteration) run concurrently with one another.
// TODO(lukes): why don't we use ListenableFuture to sequence things? Then we could drop the
Reported by PMD.
Line: 210
// A handle to the running task so that we can stop it when a shutdown has been requested.
// These two fields are volatile because their values will be accessed from multiple threads.
@CheckForNull private volatile Cancellable runningTask;
@CheckForNull private volatile ScheduledExecutorService executorService;
// This lock protects the task so we can ensure that none of the template methods (startUp,
// shutDown or runOneIteration) run concurrently with one another.
// TODO(lukes): why don't we use ListenableFuture to sequence things? Then we could drop the
// lock.
Reported by PMD.
Line: 216
// shutDown or runOneIteration) run concurrently with one another.
// TODO(lukes): why don't we use ListenableFuture to sequence things? Then we could drop the
// lock.
private final ReentrantLock lock = new ReentrantLock();
@WeakOuter
class Task implements Runnable {
@Override
public void run() {
Reported by PMD.
Line: 228
* requireNonNull is safe because Task isn't run (or at least it doesn't succeed in taking
* the lock) until after it's scheduled and the runningTask field is set.
*/
if (requireNonNull(runningTask).isCancelled()) {
// task may have been cancelled while blocked on the lock.
return;
}
AbstractScheduledService.this.runOneIteration();
} catch (Throwable t) {
Reported by PMD.
Line: 232
// task may have been cancelled while blocked on the lock.
return;
}
AbstractScheduledService.this.runOneIteration();
} catch (Throwable t) {
try {
shutDown();
} catch (Exception ignored) {
logger.log(
Reported by PMD.
Line: 232
// task may have been cancelled while blocked on the lock.
return;
}
AbstractScheduledService.this.runOneIteration();
} catch (Throwable t) {
try {
shutDown();
} catch (Exception ignored) {
logger.log(
Reported by PMD.
Line: 233
return;
}
AbstractScheduledService.this.runOneIteration();
} catch (Throwable t) {
try {
shutDown();
} catch (Exception ignored) {
logger.log(
Level.WARNING,
Reported by PMD.
Line: 236
} catch (Throwable t) {
try {
shutDown();
} catch (Exception ignored) {
logger.log(
Level.WARNING,
"Error while attempting to shut down the service after failure.",
ignored);
}
Reported by PMD.
guava-tests/test/com/google/common/util/concurrent/AtomicLongMapBasherTest.java
41 issues
Line: 35
*/
@GwtIncompatible // threads
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
Reported by PMD.
Line: 36
@GwtIncompatible // threads
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
Reported by PMD.
Line: 38
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
final int deltaRange = 10000;
final String key = "key";
Reported by PMD.
Line: 38
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
final int deltaRange = 10000;
final String key = "key";
Reported by PMD.
Line: 38
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
final int deltaRange = 10000;
final String key = "key";
Reported by PMD.
Line: 38
public class AtomicLongMapBasherTest extends TestCase {
private final Random random = new Random(301);
public void testModify_basher() throws InterruptedException {
int nTasks = 3000;
int nThreads = 100;
final int getsPerTask = 1000;
final int deltaRange = 10000;
final String key = "key";
Reported by PMD.
Line: 53
@SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored
Future<?> possiblyIgnoredError =
threadPool.submit(
new Runnable() {
@Override
public void run() {
int threadSum = 0;
for (int j = 0; j < getsPerTask; j++) {
long delta = random.nextInt(deltaRange);
Reported by PMD.
Line: 55
threadPool.submit(
new Runnable() {
@Override
public void run() {
int threadSum = 0;
for (int j = 0; j < getsPerTask; j++) {
long delta = random.nextInt(deltaRange);
int behavior = random.nextInt(10);
switch (behavior) {
Reported by PMD.
Line: 114
});
}
threadPool.shutdown();
assertTrue(threadPool.awaitTermination(300, TimeUnit.SECONDS));
assertEquals(sum.get(), map.get(key));
}
}
Reported by PMD.
Line: 115
}
threadPool.shutdown();
assertTrue(threadPool.awaitTermination(300, TimeUnit.SECONDS));
assertEquals(sum.get(), map.get(key));
}
}
Reported by PMD.