The following issues were found
guava/src/com/google/common/net/HostSpecifier.java
6 issues
Line: 49
@ElementTypesAreNonnullByDefault
public final class HostSpecifier {
private final String canonicalForm;
private HostSpecifier(String canonicalForm) {
this.canonicalForm = canonicalForm;
}
Reported by PMD.
Line: 75
// Verify that no port was specified, and strip optional brackets from
// IPv6 literals.
final HostAndPort parsedHost = HostAndPort.fromString(specifier);
Preconditions.checkArgument(!parsedHost.hasPort());
final String host = parsedHost.getHost();
// Try to interpret the specifier as an IP address. Note we build
// the address rather than using the .is* methods because we want to
// use InetAddresses.toUriString to convert the result to a string in
Reported by PMD.
Line: 76
// IPv6 literals.
final HostAndPort parsedHost = HostAndPort.fromString(specifier);
Preconditions.checkArgument(!parsedHost.hasPort());
final String host = parsedHost.getHost();
// Try to interpret the specifier as an IP address. Note we build
// the address rather than using the .is* methods because we want to
// use InetAddresses.toUriString to convert the result to a string in
// canonical form.
Reported by PMD.
Line: 85
InetAddress addr = null;
try {
addr = InetAddresses.forString(host);
} catch (IllegalArgumentException e) {
// It is not an IPv4 or IPv6 literal
}
if (addr != null) {
return new HostSpecifier(InetAddresses.toUriString(addr));
Reported by PMD.
Line: 98
// TODO(user): different versions of this for different factories?
final InternetDomainName domain = InternetDomainName.from(host);
if (domain.hasPublicSuffix()) {
return new HostSpecifier(domain.toString());
}
throw new IllegalArgumentException(
"Domain name does not have a recognized public suffix: " + host);
Reported by PMD.
Line: 82
// the address rather than using the .is* methods because we want to
// use InetAddresses.toUriString to convert the result to a string in
// canonical form.
InetAddress addr = null;
try {
addr = InetAddresses.forString(host);
} catch (IllegalArgumentException e) {
// It is not an IPv4 or IPv6 literal
}
Reported by PMD.
guava/src/com/google/common/collect/MoreCollectors.java
5 issues
Line: 75
ToOptionalState::combine,
state -> {
Object result = state.getElement();
return (result == NULL_PLACEHOLDER) ? null : result;
},
Collector.Characteristics.UNORDERED);
/**
* A collector that takes a stream containing exactly one element and returns that element. The
Reported by PMD.
Line: 96
private static final class ToOptionalState {
static final int MAX_EXTRAS = 4;
@Nullable Object element;
List<Object> extras;
ToOptionalState() {
element = null;
extras = emptyList();
Reported by PMD.
Line: 97
static final int MAX_EXTRAS = 4;
@Nullable Object element;
List<Object> extras;
ToOptionalState() {
element = null;
extras = emptyList();
}
Reported by PMD.
Line: 100
List<Object> extras;
ToOptionalState() {
element = null;
extras = emptyList();
}
IllegalArgumentException multiples(boolean overflow) {
StringBuilder sb =
Reported by PMD.
Line: 145
extras.add(other.element);
extras.addAll(other.extras);
if (extras.size() > MAX_EXTRAS) {
extras.subList(MAX_EXTRAS, extras.size()).clear();
throw multiples(true);
}
return this;
}
}
Reported by PMD.
guava/src/com/google/common/io/LineBuffer.java
5 issues
Line: 36
@ElementTypesAreNonnullByDefault
abstract class LineBuffer {
/** Holds partial line contents. */
private StringBuilder line = new StringBuilder();
/** Whether a line ending with a CR is pending processing. */
private boolean sawReturn;
/**
* Process additional characters from the stream. When a line separator is found the contents of
Reported by PMD.
Line: 36
@ElementTypesAreNonnullByDefault
abstract class LineBuffer {
/** Holds partial line contents. */
private StringBuilder line = new StringBuilder();
/** Whether a line ending with a CR is pending processing. */
private boolean sawReturn;
/**
* Process additional characters from the stream. When a line separator is found the contents of
Reported by PMD.
Line: 38
/** Holds partial line contents. */
private StringBuilder line = new StringBuilder();
/** Whether a line ending with a CR is pending processing. */
private boolean sawReturn;
/**
* Process additional characters from the stream. When a line separator is found the contents of
* the line and the line separator itself are passed to the abstract {@link #handleLine} method.
*
Reported by PMD.
Line: 54
int pos = off;
if (sawReturn && len > 0) {
// Last call to add ended with a CR; we can handle the line now.
if (finishLine(cbuf[pos] == '\n')) {
pos++;
}
}
int start = pos;
Reported by PMD.
Line: 66
line.append(cbuf, start, pos - start);
sawReturn = true;
if (pos + 1 < end) {
if (finishLine(cbuf[pos + 1] == '\n')) {
pos++;
}
}
start = pos + 1;
break;
Reported by PMD.
guava/src/com/google/common/collect/TableCollectors.java
5 issues
Line: 140
}
private static final class ImmutableTableCollectorState<R, C, V> {
final List<MutableCell<R, C, V>> insertionOrder = new ArrayList<>();
final Table<R, C, MutableCell<R, C, V>> table = HashBasedTable.create();
void put(R row, C column, V value, BinaryOperator<V> merger) {
MutableCell<R, C, V> oldCell = table.get(row, column);
if (oldCell == null) {
Reported by PMD.
Line: 141
private static final class ImmutableTableCollectorState<R, C, V> {
final List<MutableCell<R, C, V>> insertionOrder = new ArrayList<>();
final Table<R, C, MutableCell<R, C, V>> table = HashBasedTable.create();
void put(R row, C column, V value, BinaryOperator<V> merger) {
MutableCell<R, C, V> oldCell = table.get(row, column);
if (oldCell == null) {
MutableCell<R, C, V> cell = new MutableCell<>(row, column, value);
Reported by PMD.
Line: 168
}
private static final class MutableCell<R, C, V> extends AbstractCell<R, C, V> {
private final R row;
private final C column;
private V value;
MutableCell(R row, C column, V value) {
this.row = checkNotNull(row, "row");
Reported by PMD.
Line: 169
private static final class MutableCell<R, C, V> extends AbstractCell<R, C, V> {
private final R row;
private final C column;
private V value;
MutableCell(R row, C column, V value) {
this.row = checkNotNull(row, "row");
this.column = checkNotNull(column, "column");
Reported by PMD.
Line: 170
private static final class MutableCell<R, C, V> extends AbstractCell<R, C, V> {
private final R row;
private final C column;
private V value;
MutableCell(R row, C column, V value) {
this.row = checkNotNull(row, "row");
this.column = checkNotNull(column, "column");
this.value = checkNotNull(value, "value");
Reported by PMD.
guava/src/com/google/common/io/MultiInputStream.java
5 issues
Line: 36
@ElementTypesAreNonnullByDefault
final class MultiInputStream extends InputStream {
private Iterator<? extends ByteSource> it;
@CheckForNull private InputStream in;
/**
* Creates a new instance.
*
Reported by PMD.
Line: 36
@ElementTypesAreNonnullByDefault
final class MultiInputStream extends InputStream {
private Iterator<? extends ByteSource> it;
@CheckForNull private InputStream in;
/**
* Creates a new instance.
*
Reported by PMD.
Line: 37
final class MultiInputStream extends InputStream {
private Iterator<? extends ByteSource> it;
@CheckForNull private InputStream in;
/**
* Creates a new instance.
*
* @param it an iterator of I/O suppliers that will provide each substream
Reported by PMD.
Line: 55
try {
in.close();
} finally {
in = null;
}
}
}
/** Closes the current input stream and opens the next one, if any. */
Reported by PMD.
Line: 64
private void advance() throws IOException {
close();
if (it.hasNext()) {
in = it.next().openStream();
}
}
@Override
public int available() throws IOException {
Reported by PMD.
guava/src/com/google/common/graph/UndirectedGraphConnections.java
5 issues
Line: 42
* @param <V> Value parameter type
*/
@ElementTypesAreNonnullByDefault
final class UndirectedGraphConnections<N, V> implements GraphConnections<N, V> {
private final Map<N, V> adjacentNodeValues;
private UndirectedGraphConnections(Map<N, V> adjacentNodeValues) {
this.adjacentNodeValues = checkNotNull(adjacentNodeValues);
}
Reported by PMD.
Line: 43
*/
@ElementTypesAreNonnullByDefault
final class UndirectedGraphConnections<N, V> implements GraphConnections<N, V> {
private final Map<N, V> adjacentNodeValues;
private UndirectedGraphConnections(Map<N, V> adjacentNodeValues) {
this.adjacentNodeValues = checkNotNull(adjacentNodeValues);
}
Reported by PMD.
Line: 84
@Override
public Iterator<EndpointPair<N>> incidentEdgeIterator(final N thisNode) {
return Iterators.transform(
adjacentNodeValues.keySet().iterator(),
new Function<N, EndpointPair<N>>() {
@Override
public EndpointPair<N> apply(N incidentNode) {
return EndpointPair.unordered(thisNode, incidentNode);
}
Reported by PMD.
Line: 102
@Override
public void removePredecessor(N node) {
@SuppressWarnings("unused")
V unused = removeSuccessor(node);
}
@Override
@CheckForNull
public V removeSuccessor(N node) {
Reported by PMD.
Line: 114
@Override
public void addPredecessor(N node, V value) {
@SuppressWarnings("unused")
V unused = addSuccessor(node, value);
}
@Override
@CheckForNull
public V addSuccessor(N node, V value) {
Reported by PMD.
guava/src/com/google/common/reflect/ImmutableTypeToInstanceMap.java
5 issues
Line: 32
* @since 13.0
*/
@Beta
public final class ImmutableTypeToInstanceMap<B> extends ForwardingMap<TypeToken<? extends B>, B>
implements TypeToInstanceMap<B> {
/** Returns an empty type to instance map. */
public static <B> ImmutableTypeToInstanceMap<B> of() {
return new ImmutableTypeToInstanceMap<B>(ImmutableMap.<TypeToken<? extends B>, B>of());
Reported by PMD.
Line: 63
*/
@Beta
public static final class Builder<B> {
private final ImmutableMap.Builder<TypeToken<? extends B>, B> mapBuilder =
ImmutableMap.builder();
private Builder() {}
/**
Reported by PMD.
Line: 98
}
}
private final ImmutableMap<TypeToken<? extends B>, B> delegate;
private ImmutableTypeToInstanceMap(ImmutableMap<TypeToken<? extends B>, B> delegate) {
this.delegate = delegate;
}
Reported by PMD.
Line: 98
}
}
private final ImmutableMap<TypeToken<? extends B>, B> delegate;
private ImmutableTypeToInstanceMap(ImmutableMap<TypeToken<? extends B>, B> delegate) {
this.delegate = delegate;
}
Reported by PMD.
Line: 123
@CanIgnoreReturnValue
@Deprecated
@Override
@DoNotCall("Always throws UnsupportedOperationException")
public <T extends B> T putInstance(TypeToken<T> type, T value) {
throw new UnsupportedOperationException();
}
/**
Reported by PMD.
guava/src/com/google/common/collect/CompactLinkedHashSet.java
5 issues
Line: 55
*/
@GwtIncompatible // not worth using in GWT for now
@ElementTypesAreNonnullByDefault
class CompactLinkedHashSet<E extends @Nullable Object> extends CompactHashSet<E> {
/** Creates an empty {@code CompactLinkedHashSet} instance. */
public static <E extends @Nullable Object> CompactLinkedHashSet<E> create() {
return new CompactLinkedHashSet<>();
}
Reported by PMD.
Line: 55
*/
@GwtIncompatible // not worth using in GWT for now
@ElementTypesAreNonnullByDefault
class CompactLinkedHashSet<E extends @Nullable Object> extends CompactHashSet<E> {
/** Creates an empty {@code CompactLinkedHashSet} instance. */
public static <E extends @Nullable Object> CompactLinkedHashSet<E> create() {
return new CompactLinkedHashSet<>();
}
Reported by PMD.
Line: 72
public static <E extends @Nullable Object> CompactLinkedHashSet<E> create(
Collection<? extends E> collection) {
CompactLinkedHashSet<E> set = createWithExpectedSize(collection.size());
set.addAll(collection);
return set;
}
/**
* Creates a {@code CompactLinkedHashSet} instance containing the given elements in unspecified
Reported by PMD.
Line: 155
@CanIgnoreReturnValue
Set<E> convertToHashFloodingResistantImplementation() {
Set<E> result = super.convertToHashFloodingResistantImplementation();
this.predecessor = null;
this.successor = null;
return result;
}
/*
Reported by PMD.
Line: 156
Set<E> convertToHashFloodingResistantImplementation() {
Set<E> result = super.convertToHashFloodingResistantImplementation();
this.predecessor = null;
this.successor = null;
return result;
}
/*
* For discussion of the safety of the following methods for operating on predecessors and
Reported by PMD.
guava/src/com/google/common/collect/Platform.java
5 issues
Line: 154
"https://stackoverflow.com/q/5189914/28465",
"https://groups.google.com/d/msg/guava-announce/zHZTFg7YF3o/rQNnwdHeEwAJ"));
}
logger.log(
java.util.logging.Level.WARNING,
"Later in 2020, we will remove GWT-RPC support for Guava types. You are seeing this"
+ " warning because you are sending a Guava type over GWT-RPC, which will break. You"
+ " can identify which type by looking at the class name in the attached stack trace.",
new Throwable());
Reported by PMD.
Line: 34
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class Platform {
private static final java.util.logging.Logger logger =
java.util.logging.Logger.getLogger(Platform.class.getName());
/** Returns the platform preferred implementation of a map based on a hash table. */
static <K extends @Nullable Object, V extends @Nullable Object>
Reported by PMD.
Line: 101
* ObjectArrays, which is the main caller of this method.)
*/
static <T extends @Nullable Object> T[] newArray(T[] reference, int length) {
Class<?> type = reference.getClass().getComponentType();
// the cast is safe because
// result.getClass() == reference.getClass().getComponentType()
@SuppressWarnings("unchecked")
T[] result = (T[]) Array.newInstance(type, length);
Reported by PMD.
Line: 146
if (!Boolean.parseBoolean(System.getProperty(propertyName, "false"))) {
throw new UnsupportedOperationException(
com.google.common.base.Strings.lenientFormat(
"We are removing GWT-RPC support for Guava types. You can temporarily reenable"
+ " support by setting the system property %s to true. For more about system"
+ " properties, see %s. For more about Guava's GWT-RPC support, see %s.",
propertyName,
"https://stackoverflow.com/q/5189914/28465",
Reported by PMD.
Line: 120
* - https://github.com/jspecify/jdk/commit/71d826792b8c7ef95d492c50a274deab938f2552
*/
@SuppressWarnings("nullness")
static <T extends @Nullable Object> T[] copy(Object[] source, int from, int to, T[] arrayOfType) {
return Arrays.copyOfRange(source, from, to, (Class<? extends T[]>) arrayOfType.getClass());
}
/**
* Configures the given map maker to use weak keys, if possible; does nothing otherwise (i.e., in
Reported by PMD.
guava/src/com/google/common/io/MultiReader.java
5 issues
Line: 40
MultiReader(Iterator<? extends CharSource> readers) throws IOException {
this.it = readers;
advance();
}
/** Closes the current reader and opens the next one, if any. */
private void advance() throws IOException {
close();
Reported by PMD.
Line: 35
@GwtIncompatible
@ElementTypesAreNonnullByDefault
class MultiReader extends Reader {
private final Iterator<? extends CharSource> it;
@CheckForNull private Reader current;
MultiReader(Iterator<? extends CharSource> readers) throws IOException {
this.it = readers;
advance();
Reported by PMD.
Line: 36
@ElementTypesAreNonnullByDefault
class MultiReader extends Reader {
private final Iterator<? extends CharSource> it;
@CheckForNull private Reader current;
MultiReader(Iterator<? extends CharSource> readers) throws IOException {
this.it = readers;
advance();
}
Reported by PMD.
Line: 47
private void advance() throws IOException {
close();
if (it.hasNext()) {
current = it.next().openStream();
}
}
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
Reported by PMD.
Line: 91
try {
current.close();
} finally {
current = null;
}
}
}
}
Reported by PMD.