The following issues were found
android/guava/src/com/google/common/collect/MultimapBuilder.java
26 issues
Line: 138
* safely cast to a {@link java.util.SortedSet}, and the {@link Multimap#asMap()} can safely be
* cast to a {@link java.util.SortedMap}.
*/
@SuppressWarnings("rawtypes")
public static MultimapBuilderWithKeys<Comparable> treeKeys() {
return treeKeys(Ordering.natural());
}
/**
Reported by PMD.
Line: 186
};
}
private static final class ArrayListSupplier<V extends @Nullable Object>
implements Supplier<List<V>>, Serializable {
private final int expectedValuesPerKey;
ArrayListSupplier(int expectedValuesPerKey) {
this.expectedValuesPerKey = checkNonnegative(expectedValuesPerKey, "expectedValuesPerKey");
Reported by PMD.
Line: 188
private static final class ArrayListSupplier<V extends @Nullable Object>
implements Supplier<List<V>>, Serializable {
private final int expectedValuesPerKey;
ArrayListSupplier(int expectedValuesPerKey) {
this.expectedValuesPerKey = checkNonnegative(expectedValuesPerKey, "expectedValuesPerKey");
}
Reported by PMD.
Line: 191
private final int expectedValuesPerKey;
ArrayListSupplier(int expectedValuesPerKey) {
this.expectedValuesPerKey = checkNonnegative(expectedValuesPerKey, "expectedValuesPerKey");
}
@Override
public List<V> get() {
return new ArrayList<V>(expectedValuesPerKey);
Reported by PMD.
Line: 216
}
}
private static final class HashSetSupplier<V extends @Nullable Object>
implements Supplier<Set<V>>, Serializable {
private final int expectedValuesPerKey;
HashSetSupplier(int expectedValuesPerKey) {
this.expectedValuesPerKey = checkNonnegative(expectedValuesPerKey, "expectedValuesPerKey");
Reported by PMD.
Line: 218
private static final class HashSetSupplier<V extends @Nullable Object>
implements Supplier<Set<V>>, Serializable {
private final int expectedValuesPerKey;
HashSetSupplier(int expectedValuesPerKey) {
this.expectedValuesPerKey = checkNonnegative(expectedValuesPerKey, "expectedValuesPerKey");
}
Reported by PMD.
Line: 230
}
}
private static final class LinkedHashSetSupplier<V extends @Nullable Object>
implements Supplier<Set<V>>, Serializable {
private final int expectedValuesPerKey;
LinkedHashSetSupplier(int expectedValuesPerKey) {
this.expectedValuesPerKey = checkNonnegative(expectedValuesPerKey, "expectedValuesPerKey");
Reported by PMD.
Line: 232
private static final class LinkedHashSetSupplier<V extends @Nullable Object>
implements Supplier<Set<V>>, Serializable {
private final int expectedValuesPerKey;
LinkedHashSetSupplier(int expectedValuesPerKey) {
this.expectedValuesPerKey = checkNonnegative(expectedValuesPerKey, "expectedValuesPerKey");
}
Reported by PMD.
Line: 244
}
}
private static final class TreeSetSupplier<V extends @Nullable Object>
implements Supplier<SortedSet<V>>, Serializable {
private final Comparator<? super V> comparator;
TreeSetSupplier(Comparator<? super V> comparator) {
this.comparator = checkNotNull(comparator);
Reported by PMD.
Line: 246
private static final class TreeSetSupplier<V extends @Nullable Object>
implements Supplier<SortedSet<V>>, Serializable {
private final Comparator<? super V> comparator;
TreeSetSupplier(Comparator<? super V> comparator) {
this.comparator = checkNotNull(comparator);
}
Reported by PMD.
android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
26 issues
Line: 97
}
@Override
public boolean containsAll(Collection<?> targets) {
// TODO(jlevy): For optimal performance, use a binary search when
// targets.size() < size() / log(size())
// TODO(kevinb): see if we can share code with OrderedIterator after it
// graduates from labs.
if (targets instanceof Multiset) {
Reported by PMD.
Line: 43
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings({"serial", "rawtypes"})
@ElementTypesAreNonnullByDefault
final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
static final RegularImmutableSortedSet<Comparable> NATURAL_EMPTY_SET =
new RegularImmutableSortedSet<>(ImmutableList.<Comparable>of(), Ordering.natural());
@VisibleForTesting final transient ImmutableList<E> elements;
Reported by PMD.
Line: 43
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings({"serial", "rawtypes"})
@ElementTypesAreNonnullByDefault
final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
static final RegularImmutableSortedSet<Comparable> NATURAL_EMPTY_SET =
new RegularImmutableSortedSet<>(ImmutableList.<Comparable>of(), Ordering.natural());
@VisibleForTesting final transient ImmutableList<E> elements;
Reported by PMD.
Line: 43
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings({"serial", "rawtypes"})
@ElementTypesAreNonnullByDefault
final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
static final RegularImmutableSortedSet<Comparable> NATURAL_EMPTY_SET =
new RegularImmutableSortedSet<>(ImmutableList.<Comparable>of(), Ordering.natural());
@VisibleForTesting final transient ImmutableList<E> elements;
Reported by PMD.
Line: 79
@GwtIncompatible // NavigableSet
@Override
public UnmodifiableIterator<E> descendingIterator() {
return elements.reverse().iterator();
}
@Override
public int size() {
return elements.size();
Reported by PMD.
Line: 97
}
@Override
public boolean containsAll(Collection<?> targets) {
// TODO(jlevy): For optimal performance, use a binary search when
// targets.size() < size() / log(size())
// TODO(kevinb): see if we can share code with OrderedIterator after it
// graduates from labs.
if (targets instanceof Multiset) {
Reported by PMD.
Line: 97
}
@Override
public boolean containsAll(Collection<?> targets) {
// TODO(jlevy): For optimal performance, use a binary search when
// targets.size() < size() / log(size())
// TODO(kevinb): see if we can share code with OrderedIterator after it
// graduates from labs.
if (targets instanceof Multiset) {
Reported by PMD.
Line: 97
}
@Override
public boolean containsAll(Collection<?> targets) {
// TODO(jlevy): For optimal performance, use a binary search when
// targets.size() < size() / log(size())
// TODO(kevinb): see if we can share code with OrderedIterator after it
// graduates from labs.
if (targets instanceof Multiset) {
Reported by PMD.
Line: 105
if (targets instanceof Multiset) {
targets = ((Multiset<?>) targets).elementSet();
}
if (!SortedIterables.hasSameComparator(comparator(), targets) || (targets.size() <= 1)) {
return super.containsAll(targets);
}
/*
* If targets is a sorted set with the same comparator, containsAll can run
Reported by PMD.
Line: 115
*/
Iterator<E> thisIterator = iterator();
Iterator<?> thatIterator = targets.iterator();
// known nonempty since we checked targets.size() > 1
if (!thisIterator.hasNext()) {
return false;
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/TestsForSetsInJavaUtil.java
26 issues
Line: 53
* @author Kevin Bourrillion
*/
@GwtIncompatible
public class TestsForSetsInJavaUtil {
public static Test suite() {
return new TestsForSetsInJavaUtil().allTests();
}
public Test allTests() {
Reported by PMD.
Line: 54
*/
@GwtIncompatible
public class TestsForSetsInJavaUtil {
public static Test suite() {
return new TestsForSetsInJavaUtil().allTests();
}
public Test allTests() {
TestSuite suite = new TestSuite("java.util Sets");
Reported by PMD.
Line: 162
return Collections.emptySet();
}
public Test testsForCheckedNavigableSet() {
return SortedSetTestSuiteBuilder.using(
new TestStringSortedSetGenerator() {
@Override
public NavigableSet<String> create(String[] elements) {
NavigableSet<String> innerSet = new TreeSet<>();
Reported by PMD.
Line: 184
.createTestSuite();
}
public Test testsForEmptySet() {
return SetTestSuiteBuilder.using(
new TestStringSetGenerator() {
@Override
public Set<String> create(String[] elements) {
return Collections.emptySet();
Reported by PMD.
Line: 198
.createTestSuite();
}
public Test testsForEmptyNavigableSet() {
return SetTestSuiteBuilder.using(
new TestStringSortedSetGenerator() {
@Override
public NavigableSet<String> create(String[] elements) {
return Collections.emptyNavigableSet();
Reported by PMD.
Line: 212
.createTestSuite();
}
public Test testsForEmptySortedSet() {
return SetTestSuiteBuilder.using(
new TestStringSortedSetGenerator() {
@Override
public SortedSet<String> create(String[] elements) {
return Collections.emptySortedSet();
Reported by PMD.
Line: 226
.createTestSuite();
}
public Test testsForSingletonSet() {
return SetTestSuiteBuilder.using(
new TestStringSetGenerator() {
@Override
public Set<String> create(String[] elements) {
return Collections.singleton(elements[0]);
Reported by PMD.
Line: 243
.createTestSuite();
}
public Test testsForHashSet() {
return SetTestSuiteBuilder.using(
new TestStringSetGenerator() {
@Override
public Set<String> create(String[] elements) {
return new HashSet<>(MinimalCollection.of(elements));
Reported by PMD.
Line: 262
.createTestSuite();
}
public Test testsForLinkedHashSet() {
return SetTestSuiteBuilder.using(
new TestStringSetGenerator() {
@Override
public Set<String> create(String[] elements) {
return new LinkedHashSet<>(MinimalCollection.of(elements));
Reported by PMD.
Line: 282
.createTestSuite();
}
public Test testsForEnumSet() {
return SetTestSuiteBuilder.using(
new TestEnumSetGenerator() {
@Override
public Set<AnEnum> create(AnEnum[] elements) {
return (elements.length == 0)
Reported by PMD.
android/guava/src/com/google/common/collect/ForwardingSortedMultiset.java
26 issues
Line: 51
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public abstract class ForwardingSortedMultiset<E extends @Nullable Object>
extends ForwardingMultiset<E> implements SortedMultiset<E> {
/** Constructor for use by subclasses. */
protected ForwardingSortedMultiset() {}
@Override
protected abstract SortedMultiset<E> delegate();
Reported by PMD.
Line: 60
@Override
public NavigableSet<E> elementSet() {
return delegate().elementSet();
}
/**
* A sensible implementation of {@link SortedMultiset#elementSet} in terms of the following
* methods: {@link SortedMultiset#clear}, {@link SortedMultiset#comparator}, {@link
Reported by PMD.
Line: 85
@Override
public Comparator<? super E> comparator() {
return delegate().comparator();
}
@Override
public SortedMultiset<E> descendingMultiset() {
return delegate().descendingMultiset();
Reported by PMD.
Line: 90
@Override
public SortedMultiset<E> descendingMultiset() {
return delegate().descendingMultiset();
}
/**
* A skeleton implementation of a descending multiset view. Normally, {@link
* #descendingMultiset()} will not reflect any changes you make to the behavior of methods such as
Reported by PMD.
Line: 118
@Override
@CheckForNull
public Entry<E> firstEntry() {
return delegate().firstEntry();
}
/**
* A sensible definition of {@link #firstEntry()} in terms of {@code entrySet().iterator()}.
*
Reported by PMD.
Line: 129
*/
@CheckForNull
protected Entry<E> standardFirstEntry() {
Iterator<Entry<E>> entryIterator = entrySet().iterator();
if (!entryIterator.hasNext()) {
return null;
}
Entry<E> entry = entryIterator.next();
return Multisets.immutableEntry(entry.getElement(), entry.getCount());
Reported by PMD.
Line: 134
return null;
}
Entry<E> entry = entryIterator.next();
return Multisets.immutableEntry(entry.getElement(), entry.getCount());
}
@Override
@CheckForNull
public Entry<E> lastEntry() {
Reported by PMD.
Line: 134
return null;
}
Entry<E> entry = entryIterator.next();
return Multisets.immutableEntry(entry.getElement(), entry.getCount());
}
@Override
@CheckForNull
public Entry<E> lastEntry() {
Reported by PMD.
Line: 140
@Override
@CheckForNull
public Entry<E> lastEntry() {
return delegate().lastEntry();
}
/**
* A sensible definition of {@link #lastEntry()} in terms of {@code
* descendingMultiset().entrySet().iterator()}.
Reported by PMD.
Line: 152
*/
@CheckForNull
protected Entry<E> standardLastEntry() {
Iterator<Entry<E>> entryIterator = descendingMultiset().entrySet().iterator();
if (!entryIterator.hasNext()) {
return null;
}
Entry<E> entry = entryIterator.next();
return Multisets.immutableEntry(entry.getElement(), entry.getCount());
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java
26 issues
Line: 229
try {
requirements = FeatureUtil.getTesterRequirements(method);
} catch (ConflictingRequirementsException e) {
throw new RuntimeException(e);
}
if (!features.containsAll(requirements.getPresentFeatures())) {
if (logger.isLoggable(FINER)) {
Set<Feature<?>> missingFeatures = Helpers.copyToSet(requirements.getPresentFeatures());
missingFeatures.removeAll(features);
Reported by PMD.
Line: 176
public TestSuite createTestSuite() {
checkCanCreate();
logger.fine(" Testing: " + name);
logger.fine("Features: " + formatFeatureSet(features));
FeatureUtil.addImpliedFeatures(features);
logger.fine("Expanded: " + formatFeatureSet(features));
Reported by PMD.
Line: 177
checkCanCreate();
logger.fine(" Testing: " + name);
logger.fine("Features: " + formatFeatureSet(features));
FeatureUtil.addImpliedFeatures(features);
logger.fine("Expanded: " + formatFeatureSet(features));
Reported by PMD.
Line: 181
FeatureUtil.addImpliedFeatures(features);
logger.fine("Expanded: " + formatFeatureSet(features));
// Class parameters must be raw.
List<Class<? extends AbstractTester>> testers = getTesters();
TestSuite suite = new TestSuite(name);
Reported by PMD.
Line: 55
* @author George van den Driessche
*/
@GwtIncompatible
public abstract class FeatureSpecificTestSuiteBuilder<
B extends FeatureSpecificTestSuiteBuilder<B, G>, G> {
@SuppressWarnings("unchecked")
protected B self() {
return (B) this;
}
Reported by PMD.
Line: 56
*/
@GwtIncompatible
public abstract class FeatureSpecificTestSuiteBuilder<
B extends FeatureSpecificTestSuiteBuilder<B, G>, G> {
@SuppressWarnings("unchecked")
protected B self() {
return (B) this;
}
Reported by PMD.
Line: 64
// Test Data
private G subjectGenerator;
// Gets run before every test.
private Runnable setUp;
// Gets run at the conclusion of every test.
private Runnable tearDown;
Reported by PMD.
Line: 66
private G subjectGenerator;
// Gets run before every test.
private Runnable setUp;
// Gets run at the conclusion of every test.
private Runnable tearDown;
protected B usingGenerator(G subjectGenerator) {
this.subjectGenerator = subjectGenerator;
Reported by PMD.
Line: 68
// Gets run before every test.
private Runnable setUp;
// Gets run at the conclusion of every test.
private Runnable tearDown;
protected B usingGenerator(G subjectGenerator) {
this.subjectGenerator = subjectGenerator;
return self();
}
Reported by PMD.
Line: 122
// Name
private String name;
/** Configures this builder produce a TestSuite with the given name. */
public B named(String name) {
if (name.contains("(")) {
throw new IllegalArgumentException(
Reported by PMD.
android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureFallbackAtomicHelperTest.java
26 issues
Line: 47
* test methods in these degenerate classloaders.
*/
public class AbstractFutureFallbackAtomicHelperTest extends TestCase {
// stash these in static fields to avoid loading them over and over again (speeds up test
// execution significantly)
/**
Reported by PMD.
Line: 74
// corresponding method on AbstractFutureTest in the correct classloader.
TestSuite suite = new TestSuite(AbstractFutureFallbackAtomicHelperTest.class.getName());
for (Method method : AbstractFutureTest.class.getDeclaredMethods()) {
if (Modifier.isPublic(method.getModifiers()) && method.getName().startsWith("test")) {
suite.addTest(
TestSuite.createTest(AbstractFutureFallbackAtomicHelperTest.class, method.getName()));
}
}
return suite;
Reported by PMD.
Line: 85
@Override
public void runTest() throws Exception {
// First ensure that our classloaders are initializing the correct helper versions
checkHelperVersion(getClass().getClassLoader(), "UnsafeAtomicHelper");
checkHelperVersion(NO_UNSAFE, "SafeAtomicHelper");
checkHelperVersion(NO_ATOMIC_REFERENCE_FIELD_UPDATER, "SynchronizedHelper");
// Run the corresponding AbstractFutureTest test method in a new classloader that disallows
// certain core jdk classes.
Reported by PMD.
Line: 85
@Override
public void runTest() throws Exception {
// First ensure that our classloaders are initializing the correct helper versions
checkHelperVersion(getClass().getClassLoader(), "UnsafeAtomicHelper");
checkHelperVersion(NO_UNSAFE, "SafeAtomicHelper");
checkHelperVersion(NO_ATOMIC_REFERENCE_FIELD_UPDATER, "SynchronizedHelper");
// Run the corresponding AbstractFutureTest test method in a new classloader that disallows
// certain core jdk classes.
Reported by PMD.
Line: 91
// Run the corresponding AbstractFutureTest test method in a new classloader that disallows
// certain core jdk classes.
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(NO_UNSAFE);
try {
runTestMethod(NO_UNSAFE);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
Reported by PMD.
Line: 92
// Run the corresponding AbstractFutureTest test method in a new classloader that disallows
// certain core jdk classes.
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(NO_UNSAFE);
try {
runTestMethod(NO_UNSAFE);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
Reported by PMD.
Line: 96
try {
runTestMethod(NO_UNSAFE);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
Thread.currentThread().setContextClassLoader(NO_ATOMIC_REFERENCE_FIELD_UPDATER);
try {
runTestMethod(NO_ATOMIC_REFERENCE_FIELD_UPDATER);
Reported by PMD.
Line: 99
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
Thread.currentThread().setContextClassLoader(NO_ATOMIC_REFERENCE_FIELD_UPDATER);
try {
runTestMethod(NO_ATOMIC_REFERENCE_FIELD_UPDATER);
// TODO(lukes): assert that the logs are full of errors
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
Reported by PMD.
Line: 104
runTestMethod(NO_ATOMIC_REFERENCE_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(AbstractFutureTest.class.getName());
Reported by PMD.
Line: 108
}
}
private void runTestMethod(ClassLoader classLoader) throws Exception {
Class<?> test = classLoader.loadClass(AbstractFutureTest.class.getName());
test.getMethod(getName()).invoke(test.getDeclaredConstructor().newInstance());
}
private void checkHelperVersion(ClassLoader classLoader, String expectedHelperClassName)
Reported by PMD.
guava-tests/test/com/google/common/collect/ConcurrentHashMultisetBasherTest.java
26 issues
Line: 45
public class ConcurrentHashMultisetBasherTest extends TestCase {
public void testAddAndRemove_ConcurrentHashMap() throws Exception {
testAddAndRemove(new ConcurrentHashMap<String, AtomicInteger>());
}
public void testAddAndRemove_ConcurrentSkipListMap() throws Exception {
testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());
Reported by PMD.
Line: 45
public class ConcurrentHashMultisetBasherTest extends TestCase {
public void testAddAndRemove_ConcurrentHashMap() throws Exception {
testAddAndRemove(new ConcurrentHashMap<String, AtomicInteger>());
}
public void testAddAndRemove_ConcurrentSkipListMap() throws Exception {
testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());
Reported by PMD.
Line: 49
testAddAndRemove(new ConcurrentHashMap<String, AtomicInteger>());
}
public void testAddAndRemove_ConcurrentSkipListMap() throws Exception {
testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());
}
public void testAddAndRemove_MapMakerMap() throws Exception {
MapMaker mapMaker = new MapMaker();
Reported by PMD.
Line: 49
testAddAndRemove(new ConcurrentHashMap<String, AtomicInteger>());
}
public void testAddAndRemove_ConcurrentSkipListMap() throws Exception {
testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());
}
public void testAddAndRemove_MapMakerMap() throws Exception {
MapMaker mapMaker = new MapMaker();
Reported by PMD.
Line: 53
testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());
}
public void testAddAndRemove_MapMakerMap() throws Exception {
MapMaker mapMaker = new MapMaker();
// force MapMaker to use its own MapMakerInternalMap
mapMaker.useCustomMap = true;
testAddAndRemove(mapMaker.<String, AtomicInteger>makeMap());
}
Reported by PMD.
Line: 53
testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());
}
public void testAddAndRemove_MapMakerMap() throws Exception {
MapMaker mapMaker = new MapMaker();
// force MapMaker to use its own MapMakerInternalMap
mapMaker.useCustomMap = true;
testAddAndRemove(mapMaker.<String, AtomicInteger>makeMap());
}
Reported by PMD.
Line: 60
testAddAndRemove(mapMaker.<String, AtomicInteger>makeMap());
}
private void testAddAndRemove(ConcurrentMap<String, AtomicInteger> map)
throws ExecutionException, InterruptedException {
final ConcurrentHashMultiset<String> multiset = new ConcurrentHashMultiset<>(map);
int nThreads = 20;
int tasksPerThread = 10;
Reported by PMD.
Line: 72
try {
List<Future<int[]>> futures = Lists.newArrayListWithExpectedSize(nTasks);
for (int i = 0; i < nTasks; i++) {
futures.add(pool.submit(new MutateTask(multiset, keys)));
}
int[] deltas = new int[3];
for (Future<int[]> future : futures) {
int[] taskDeltas = future.get();
Reported by PMD.
Line: 99
// Since we have access to the backing map, verify that there are no zeroes in the map
for (AtomicInteger value : map.values()) {
assertTrue("map should not contain a zero", value.get() != 0);
}
}
private static class MutateTask implements Callable<int[]> {
private final ConcurrentHashMultiset<String> multiset;
Reported by PMD.
Line: 104
}
private static class MutateTask implements Callable<int[]> {
private final ConcurrentHashMultiset<String> multiset;
private final ImmutableList<String> keys;
private final Random random = new Random();
private MutateTask(ConcurrentHashMultiset<String> multiset, ImmutableList<String> keys) {
this.multiset = multiset;
Reported by PMD.
guava-tests/test/com/google/common/escape/ArrayBasedUnicodeEscaperTest.java
26 issues
Line: 36
'&', "<and>");
private static final char[] NO_CHARS = new char[0];
public void testReplacements() throws IOException {
// In reality this is not a very sensible escaper to have (if you are only
// escaping elements from a map you would use a ArrayBasedCharEscaper).
UnicodeEscaper escaper =
new ArrayBasedUnicodeEscaper(
SIMPLE_REPLACEMENTS, Character.MIN_VALUE, Character.MAX_CODE_POINT, null) {
Reported by PMD.
Line: 36
'&', "<and>");
private static final char[] NO_CHARS = new char[0];
public void testReplacements() throws IOException {
// In reality this is not a very sensible escaper to have (if you are only
// escaping elements from a map you would use a ArrayBasedCharEscaper).
UnicodeEscaper escaper =
new ArrayBasedUnicodeEscaper(
SIMPLE_REPLACEMENTS, Character.MIN_VALUE, Character.MAX_CODE_POINT, null) {
Reported by PMD.
Line: 48
}
};
EscaperAsserts.assertBasic(escaper);
assertEquals("<tab>Fish <and> Chips<newline>", escaper.escape("\tFish & Chips\n"));
// Verify that everything else is left unescaped.
String safeChars = "\0\u0100\uD800\uDC00\uFFFF";
assertEquals(safeChars, escaper.escape(safeChars));
Reported by PMD.
Line: 52
// Verify that everything else is left unescaped.
String safeChars = "\0\u0100\uD800\uDC00\uFFFF";
assertEquals(safeChars, escaper.escape(safeChars));
// Ensure that Unicode escapers behave correctly wrt badly formed input.
String badUnicode = "\uDC00\uD800";
try {
escaper.escape(badUnicode);
Reported by PMD.
Line: 58
String badUnicode = "\uDC00\uD800";
try {
escaper.escape(badUnicode);
fail("should fail for bad Unicode");
} catch (IllegalArgumentException e) {
// Pass
}
}
Reported by PMD.
Line: 59
try {
escaper.escape(badUnicode);
fail("should fail for bad Unicode");
} catch (IllegalArgumentException e) {
// Pass
}
}
public void testSafeRange() throws IOException {
Reported by PMD.
Line: 64
}
}
public void testSafeRange() throws IOException {
// Basic escaping of unsafe chars (wrap them in {,}'s)
UnicodeEscaper wrappingEscaper =
new ArrayBasedUnicodeEscaper(NO_REPLACEMENTS, 'A', 'Z', null) {
@Override
protected char[] escapeUnsafe(int c) {
Reported by PMD.
Line: 75
};
EscaperAsserts.assertBasic(wrappingEscaper);
// '[' and '@' lie either side of [A-Z].
assertEquals("{[}FOO{@}BAR{]}", wrappingEscaper.escape("[FOO@BAR]"));
}
public void testDeleteUnsafeChars() throws IOException {
UnicodeEscaper deletingEscaper =
new ArrayBasedUnicodeEscaper(NO_REPLACEMENTS, ' ', '~', null) {
Reported by PMD.
Line: 78
assertEquals("{[}FOO{@}BAR{]}", wrappingEscaper.escape("[FOO@BAR]"));
}
public void testDeleteUnsafeChars() throws IOException {
UnicodeEscaper deletingEscaper =
new ArrayBasedUnicodeEscaper(NO_REPLACEMENTS, ' ', '~', null) {
@Override
protected char[] escapeUnsafe(int c) {
return NO_CHARS;
Reported by PMD.
Line: 87
}
};
EscaperAsserts.assertBasic(deletingEscaper);
assertEquals(
"Everything outside the printable ASCII range is deleted.",
deletingEscaper.escape(
"\tEverything\0 outside the\uD800\uDC00 "
+ "printable ASCII \uFFFFrange is \u007Fdeleted.\n"));
}
Reported by PMD.
guava-tests/test/com/google/common/eventbus/DispatcherTest.java
26 issues
Line: 37
public class DispatcherTest extends TestCase {
private final EventBus bus = new EventBus();
private final IntegerSubscriber i1 = new IntegerSubscriber("i1");
private final IntegerSubscriber i2 = new IntegerSubscriber("i2");
private final IntegerSubscriber i3 = new IntegerSubscriber("i3");
private final ImmutableList<Subscriber> integerSubscribers =
Reported by PMD.
Line: 39
private final EventBus bus = new EventBus();
private final IntegerSubscriber i1 = new IntegerSubscriber("i1");
private final IntegerSubscriber i2 = new IntegerSubscriber("i2");
private final IntegerSubscriber i3 = new IntegerSubscriber("i3");
private final ImmutableList<Subscriber> integerSubscribers =
ImmutableList.of(
subscriber(bus, i1, "handleInteger", Integer.class),
Reported by PMD.
Line: 40
private final EventBus bus = new EventBus();
private final IntegerSubscriber i1 = new IntegerSubscriber("i1");
private final IntegerSubscriber i2 = new IntegerSubscriber("i2");
private final IntegerSubscriber i3 = new IntegerSubscriber("i3");
private final ImmutableList<Subscriber> integerSubscribers =
ImmutableList.of(
subscriber(bus, i1, "handleInteger", Integer.class),
subscriber(bus, i2, "handleInteger", Integer.class),
Reported by PMD.
Line: 41
private final IntegerSubscriber i1 = new IntegerSubscriber("i1");
private final IntegerSubscriber i2 = new IntegerSubscriber("i2");
private final IntegerSubscriber i3 = new IntegerSubscriber("i3");
private final ImmutableList<Subscriber> integerSubscribers =
ImmutableList.of(
subscriber(bus, i1, "handleInteger", Integer.class),
subscriber(bus, i2, "handleInteger", Integer.class),
subscriber(bus, i3, "handleInteger", Integer.class));
Reported by PMD.
Line: 42
private final IntegerSubscriber i1 = new IntegerSubscriber("i1");
private final IntegerSubscriber i2 = new IntegerSubscriber("i2");
private final IntegerSubscriber i3 = new IntegerSubscriber("i3");
private final ImmutableList<Subscriber> integerSubscribers =
ImmutableList.of(
subscriber(bus, i1, "handleInteger", Integer.class),
subscriber(bus, i2, "handleInteger", Integer.class),
subscriber(bus, i3, "handleInteger", Integer.class));
Reported by PMD.
Line: 48
subscriber(bus, i2, "handleInteger", Integer.class),
subscriber(bus, i3, "handleInteger", Integer.class));
private final StringSubscriber s1 = new StringSubscriber("s1");
private final StringSubscriber s2 = new StringSubscriber("s2");
private final ImmutableList<Subscriber> stringSubscribers =
ImmutableList.of(
subscriber(bus, s1, "handleString", String.class),
subscriber(bus, s2, "handleString", String.class));
Reported by PMD.
Line: 49
subscriber(bus, i3, "handleInteger", Integer.class));
private final StringSubscriber s1 = new StringSubscriber("s1");
private final StringSubscriber s2 = new StringSubscriber("s2");
private final ImmutableList<Subscriber> stringSubscribers =
ImmutableList.of(
subscriber(bus, s1, "handleString", String.class),
subscriber(bus, s2, "handleString", String.class));
Reported by PMD.
Line: 50
private final StringSubscriber s1 = new StringSubscriber("s1");
private final StringSubscriber s2 = new StringSubscriber("s2");
private final ImmutableList<Subscriber> stringSubscribers =
ImmutableList.of(
subscriber(bus, s1, "handleString", String.class),
subscriber(bus, s2, "handleString", String.class));
private final ConcurrentLinkedQueue<Object> dispatchedSubscribers =
Reported by PMD.
Line: 55
subscriber(bus, s1, "handleString", String.class),
subscriber(bus, s2, "handleString", String.class));
private final ConcurrentLinkedQueue<Object> dispatchedSubscribers =
Queues.newConcurrentLinkedQueue();
private Dispatcher dispatcher;
public void testPerThreadQueuedDispatcher() {
Reported by PMD.
Line: 58
private final ConcurrentLinkedQueue<Object> dispatchedSubscribers =
Queues.newConcurrentLinkedQueue();
private Dispatcher dispatcher;
public void testPerThreadQueuedDispatcher() {
dispatcher = Dispatcher.perThreadDispatchQueue();
dispatcher.dispatch(1, integerSubscribers.iterator());
Reported by PMD.
guava-tests/test/com/google/common/eventbus/SubscriberTest.java
26 issues
Line: 36
private static final Object FIXTURE_ARGUMENT = new Object();
private EventBus bus;
private boolean methodCalled;
private Object methodArgument;
@Override
protected void setUp() throws Exception {
Reported by PMD.
Line: 37
private static final Object FIXTURE_ARGUMENT = new Object();
private EventBus bus;
private boolean methodCalled;
private Object methodArgument;
@Override
protected void setUp() throws Exception {
bus = new EventBus();
Reported by PMD.
Line: 38
private EventBus bus;
private boolean methodCalled;
private Object methodArgument;
@Override
protected void setUp() throws Exception {
bus = new EventBus();
methodCalled = false;
Reported by PMD.
Line: 40
private boolean methodCalled;
private Object methodArgument;
@Override
protected void setUp() throws Exception {
bus = new EventBus();
methodCalled = false;
methodArgument = null;
}
Reported by PMD.
Line: 44
protected void setUp() throws Exception {
bus = new EventBus();
methodCalled = false;
methodArgument = null;
}
public void testCreate() {
Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod"));
assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class);
Reported by PMD.
Line: 47
methodArgument = null;
}
public void testCreate() {
Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod"));
assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class);
// a thread-safe method should not create a synchronized subscriber
Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod"));
Reported by PMD.
Line: 47
methodArgument = null;
}
public void testCreate() {
Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod"));
assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class);
// a thread-safe method should not create a synchronized subscriber
Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod"));
Reported by PMD.
Line: 49
public void testCreate() {
Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod"));
assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class);
// a thread-safe method should not create a synchronized subscriber
Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod"));
assertThat(s2).isNotInstanceOf(Subscriber.SynchronizedSubscriber.class);
}
Reported by PMD.
Line: 53
// a thread-safe method should not create a synchronized subscriber
Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod"));
assertThat(s2).isNotInstanceOf(Subscriber.SynchronizedSubscriber.class);
}
public void testInvokeSubscriberMethod_basicMethodCall() throws Throwable {
Method method = getTestSubscriberMethod("recordingMethod");
Subscriber subscriber = Subscriber.create(bus, this, method);
Reported by PMD.
Line: 56
assertThat(s2).isNotInstanceOf(Subscriber.SynchronizedSubscriber.class);
}
public void testInvokeSubscriberMethod_basicMethodCall() throws Throwable {
Method method = getTestSubscriberMethod("recordingMethod");
Subscriber subscriber = Subscriber.create(bus, this, method);
subscriber.invokeSubscriberMethod(FIXTURE_ARGUMENT);
Reported by PMD.