enforce android API level 14 (#8971)

* enforce android API level 14
Add animal-sniffer plugin to check for android compatibility

* Revert "Merge pull request #7855 from belugabehr/ObjectsRequireNonNull"

This reverts commit a3e5587447, reversing
changes made to f79f956b74.
pull/8968/head^2
Elliotte Rusty Harold 3 years ago committed by GitHub
parent 385672597f
commit 5f55fe1d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
  2. 5
      java/core/src/main/java/com/google/protobuf/AllocatedBuffer.java
  3. 6
      java/core/src/main/java/com/google/protobuf/ArrayDecoders.java
  4. 4
      java/core/src/main/java/com/google/protobuf/BinaryWriter.java
  5. 5
      java/core/src/main/java/com/google/protobuf/BooleanArrayList.java
  6. 6
      java/core/src/main/java/com/google/protobuf/ByteString.java
  7. 5
      java/core/src/main/java/com/google/protobuf/CodedInputStream.java
  8. 3
      java/core/src/main/java/com/google/protobuf/CodedInputStreamReader.java
  9. 22
      java/core/src/main/java/com/google/protobuf/CodedOutputStream.java
  10. 4
      java/core/src/main/java/com/google/protobuf/CodedOutputStreamWriter.java
  11. 5
      java/core/src/main/java/com/google/protobuf/Descriptors.java
  12. 5
      java/core/src/main/java/com/google/protobuf/DoubleArrayList.java
  13. 5
      java/core/src/main/java/com/google/protobuf/DynamicMessage.java
  14. 45
      java/core/src/main/java/com/google/protobuf/FieldInfo.java
  15. 5
      java/core/src/main/java/com/google/protobuf/FieldSet.java
  16. 5
      java/core/src/main/java/com/google/protobuf/FloatArrayList.java
  17. 2
      java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
  18. 5
      java/core/src/main/java/com/google/protobuf/IntArrayList.java
  19. 16
      java/core/src/main/java/com/google/protobuf/Internal.java
  20. 20
      java/core/src/main/java/com/google/protobuf/LazyFieldLite.java
  21. 5
      java/core/src/main/java/com/google/protobuf/LongArrayList.java
  22. 4
      java/core/src/main/java/com/google/protobuf/ManifestSchemaFactory.java
  23. 11
      java/core/src/main/java/com/google/protobuf/MapField.java
  24. 11
      java/core/src/main/java/com/google/protobuf/MapFieldLite.java
  25. 9
      java/core/src/main/java/com/google/protobuf/MessageSchema.java
  26. 5
      java/core/src/main/java/com/google/protobuf/NioByteString.java
  27. 13
      java/core/src/main/java/com/google/protobuf/Protobuf.java
  28. 11
      java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java
  29. 11
      java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
  30. 6
      java/core/src/main/java/com/google/protobuf/RopeByteString.java
  31. 6
      java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java
  32. 6
      java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java
  33. 7
      java/core/src/main/java/com/google/protobuf/StructuralMessageInfo.java
  34. 21
      java/pom.xml

@ -30,6 +30,8 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -37,7 +39,6 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
/**
* A partial implementation of the {@link MessageLite} interface which implements as many methods of
@ -401,7 +402,7 @@ public abstract class AbstractMessageLite<
* null.
*/
protected static <T> void addAll(final Iterable<T> values, final List<? super T> list) {
Objects.requireNonNull(values);
checkNotNull(values);
if (values instanceof LazyStringList) {
// For StringOrByteStringLists, check the underlying elements to avoid
// forcing conversions of ByteStrings to Strings.

@ -30,8 +30,9 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.nio.ByteBuffer;
import java.util.Objects;
/**
* A buffer that was allocated by a {@link BufferAllocator}. For every buffer, it is guaranteed that
@ -150,7 +151,7 @@ abstract class AllocatedBuffer {
* returned buffer will have {@link #hasNioBuffer} == {@code true}.
*/
public static AllocatedBuffer wrap(final ByteBuffer buffer) {
Objects.requireNonNull(buffer, "buffer");
checkNotNull(buffer, "buffer");
return new AllocatedBuffer() {

@ -34,7 +34,6 @@ import static com.google.protobuf.MessageSchema.getMutableUnknownFields;
import com.google.protobuf.Internal.ProtobufList;
import java.io.IOException;
import java.util.Objects;
/**
* Helper functions to decode protobuf wire format from a byte array.
@ -65,7 +64,10 @@ final class ArrayDecoders {
}
Registers(ExtensionRegistryLite extensionRegistry) {
this.extensionRegistry = Objects.requireNonNull(extensionRegistry);
if (extensionRegistry == null) {
throw new NullPointerException();
}
this.extensionRegistry = extensionRegistry;
}
}

@ -30,6 +30,7 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import static com.google.protobuf.WireFormat.FIXED32_SIZE;
import static com.google.protobuf.WireFormat.FIXED64_SIZE;
import static com.google.protobuf.WireFormat.MAX_VARINT32_SIZE;
@ -50,7 +51,6 @@ import java.nio.ByteOrder;
import java.util.ArrayDeque;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
/**
@ -146,7 +146,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer {
if (chunkSize <= 0) {
throw new IllegalArgumentException("chunkSize must be > 0");
}
this.alloc = Objects.requireNonNull(alloc, "alloc");
this.alloc = checkNotNull(alloc, "alloc");
this.chunkSize = chunkSize;
}

@ -30,10 +30,11 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Internal.BooleanList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.RandomAccess;
/**
@ -237,7 +238,7 @@ final class BooleanArrayList extends AbstractProtobufList<Boolean>
public boolean addAll(Collection<? extends Boolean> collection) {
ensureIsMutable();
Objects.requireNonNull(collection);
checkNotNull(collection);
// We specialize when adding another BooleanArrayList to avoid boxing elements.
if (!(collection instanceof BooleanArrayList)) {

@ -55,7 +55,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.Objects;
/**
* Immutable sequence of bytes. Provides conversions to and from {@code byte[]}, {@link
@ -1329,7 +1328,10 @@ public abstract class ByteString implements Iterable<Byte>, Serializable {
* @param bytes array to wrap
*/
LiteralByteString(byte[] bytes) {
this.bytes = Objects.requireNonNull(bytes);
if (bytes == null) {
throw new NullPointerException();
}
this.bytes = bytes;
}
@Override

@ -33,6 +33,7 @@ package com.google.protobuf;
import static com.google.protobuf.Internal.EMPTY_BYTE_ARRAY;
import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER;
import static com.google.protobuf.Internal.UTF_8;
import static com.google.protobuf.Internal.checkNotNull;
import static com.google.protobuf.WireFormat.FIXED32_SIZE;
import static com.google.protobuf.WireFormat.FIXED64_SIZE;
import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE;
@ -46,7 +47,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
/**
* Reads and decodes protocol message fields.
@ -2056,7 +2056,8 @@ public abstract class CodedInputStream {
private int currentLimit = Integer.MAX_VALUE;
private StreamDecoder(final InputStream input, int bufferSize) {
this.input = Objects.requireNonNull(input, "input");
checkNotNull(input, "input");
this.input = input;
this.buffer = new byte[bufferSize];
this.bufferSize = 0;
pos = 0;

@ -42,7 +42,6 @@ import static com.google.protobuf.WireFormat.WIRETYPE_VARINT;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/** An adapter between the {@link Reader} interface and {@link CodedInputStream}. */
@ExperimentalApi
@ -64,7 +63,7 @@ final class CodedInputStreamReader implements Reader {
}
private CodedInputStreamReader(CodedInputStream input) {
this.input = Objects.requireNonNull(input, "input");
this.input = Internal.checkNotNull(input, "input");
this.input.wrapper = this;
}

@ -42,7 +42,6 @@ import java.io.OutputStream;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -1155,7 +1154,9 @@ public abstract class CodedOutputStream extends ByteOutput {
private int position;
ArrayEncoder(byte[] buffer, int offset, int length) {
Objects.requireNonNull(buffer, "buffer");
if (buffer == null) {
throw new NullPointerException("buffer");
}
if ((offset | length | (buffer.length - (offset + length))) < 0) {
throw new IllegalArgumentException(
String.format(
@ -2119,11 +2120,14 @@ public abstract class CodedOutputStream extends ByteOutput {
@Override
public void write(byte[] value, int offset, int length) throws IOException {
Objects.requireNonNull(value, "value");
if (offset < 0
if (value == null
|| offset < 0
|| length < 0
|| (value.length - length) < offset
|| (limit - length) < position) {
if (value == null) {
throw new NullPointerException("value");
}
throw new OutOfSpaceException(
String.format("Pos: %d, limit: %d, len: %d", position, limit, length));
}
@ -2392,7 +2396,10 @@ public abstract class CodedOutputStream extends ByteOutput {
ByteOutputEncoder(ByteOutput out, int bufferSize) {
super(bufferSize);
this.out = Objects.requireNonNull(out, "out");
if (out == null) {
throw new NullPointerException("out");
}
this.out = out;
}
@Override
@ -2703,7 +2710,10 @@ public abstract class CodedOutputStream extends ByteOutput {
OutputStreamEncoder(OutputStream out, int bufferSize) {
super(bufferSize);
this.out = Objects.requireNonNull(out, "out");
if (out == null) {
throw new NullPointerException("out");
}
this.out = out;
}
@Override

@ -30,13 +30,13 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import static com.google.protobuf.WireFormat.WIRETYPE_LENGTH_DELIMITED;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/** An adapter between the {@link Writer} interface and {@link CodedOutputStream}. */
@ExperimentalApi
@ -51,7 +51,7 @@ final class CodedOutputStreamWriter implements Writer {
}
private CodedOutputStreamWriter(CodedOutputStream output) {
this.output = Objects.requireNonNull(output, "output");
this.output = checkNotNull(output, "output");
this.output.wrapper = this;
}

@ -30,6 +30,8 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.DescriptorProtos.DescriptorProto;
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto;
import com.google.protobuf.DescriptorProtos.EnumOptions;
@ -55,7 +57,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.logging.Logger;
@ -743,7 +744,7 @@ public final class Descriptors {
/** Determines if the given field name is reserved. */
public boolean isReservedName(final String name) {
Objects.requireNonNull(name);
checkNotNull(name);
for (final String reservedName : proto.getReservedNameList()) {
if (reservedName.equals(name)) {
return true;

@ -30,10 +30,11 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Internal.DoubleList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.RandomAccess;
/**
@ -237,7 +238,7 @@ final class DoubleArrayList extends AbstractProtobufList<Double>
public boolean addAll(Collection<? extends Double> collection) {
ensureIsMutable();
Objects.requireNonNull(collection);
checkNotNull(collection);
// We specialize when adding another DoubleArrayList to avoid boxing elements.
if (!(collection instanceof DoubleArrayList)) {

@ -30,6 +30,8 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
@ -39,7 +41,6 @@ import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* An implementation of {@link Message} that can represent arbitrary types, given a {@link
@ -623,7 +624,7 @@ public final class DynamicMessage extends AbstractMessage {
/** Verifies that the value is EnumValueDescriptor and matches Enum Type. */
private void ensureSingularEnumValueDescriptor(FieldDescriptor field, Object value) {
Objects.requireNonNull(value);
checkNotNull(value);
if (!(value instanceof EnumValueDescriptor)) {
throw new IllegalArgumentException(
"DynamicMessage should use EnumValueDescriptor to set Enum Value.");

@ -30,9 +30,10 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Internal.EnumVerifier;
import java.lang.reflect.Field;
import java.util.Objects;
/** Information for a single field in a protobuf message class. */
@ExperimentalApi
@ -63,8 +64,8 @@ final class FieldInfo implements Comparable<FieldInfo> {
public static FieldInfo forField(
Field field, int fieldNumber, FieldType fieldType, boolean enforceUtf8) {
checkFieldNumber(fieldNumber);
Objects.requireNonNull(field, "field");
Objects.requireNonNull(fieldType, "fieldType");
checkNotNull(field, "field");
checkNotNull(fieldType, "fieldType");
if (fieldType == FieldType.MESSAGE_LIST || fieldType == FieldType.GROUP_LIST) {
throw new IllegalStateException("Shouldn't be called for repeated message fields.");
}
@ -88,8 +89,8 @@ final class FieldInfo implements Comparable<FieldInfo> {
public static FieldInfo forPackedField(
Field field, int fieldNumber, FieldType fieldType, Field cachedSizeField) {
checkFieldNumber(fieldNumber);
Objects.requireNonNull(field, "field");
Objects.requireNonNull(fieldType, "fieldType");
checkNotNull(field, "field");
checkNotNull(fieldType, "fieldType");
if (fieldType == FieldType.MESSAGE_LIST || fieldType == FieldType.GROUP_LIST) {
throw new IllegalStateException("Shouldn't be called for repeated message fields.");
}
@ -113,9 +114,9 @@ final class FieldInfo implements Comparable<FieldInfo> {
public static FieldInfo forRepeatedMessageField(
Field field, int fieldNumber, FieldType fieldType, Class<?> messageClass) {
checkFieldNumber(fieldNumber);
Objects.requireNonNull(field, "field");
Objects.requireNonNull(fieldType, "fieldType");
Objects.requireNonNull(messageClass, "messageClass");
checkNotNull(field, "field");
checkNotNull(fieldType, "fieldType");
checkNotNull(messageClass, "messageClass");
return new FieldInfo(
field,
fieldNumber,
@ -135,7 +136,7 @@ final class FieldInfo implements Comparable<FieldInfo> {
public static FieldInfo forFieldWithEnumVerifier(
Field field, int fieldNumber, FieldType fieldType, EnumVerifier enumVerifier) {
checkFieldNumber(fieldNumber);
Objects.requireNonNull(field, "field");
checkNotNull(field, "field");
return new FieldInfo(
field,
fieldNumber,
@ -159,7 +160,7 @@ final class FieldInfo implements Comparable<FieldInfo> {
EnumVerifier enumVerifier,
Field cachedSizeField) {
checkFieldNumber(fieldNumber);
Objects.requireNonNull(field, "field");
checkNotNull(field, "field");
return new FieldInfo(
field,
fieldNumber,
@ -186,9 +187,9 @@ final class FieldInfo implements Comparable<FieldInfo> {
boolean enforceUtf8,
EnumVerifier enumVerifier) {
checkFieldNumber(fieldNumber);
Objects.requireNonNull(field, "field");
Objects.requireNonNull(fieldType, "fieldType");
Objects.requireNonNull(presenceField, "presenceField");
checkNotNull(field, "field");
checkNotNull(fieldType, "fieldType");
checkNotNull(presenceField, "presenceField");
if (presenceField != null && !isExactlyOneBitSet(presenceMask)) {
throw new IllegalArgumentException(
"presenceMask must have exactly one bit set: " + presenceMask);
@ -229,9 +230,9 @@ final class FieldInfo implements Comparable<FieldInfo> {
boolean enforceUtf8,
EnumVerifier enumVerifier) {
checkFieldNumber(fieldNumber);
Objects.requireNonNull(fieldType, "fieldType");
Objects.requireNonNull(oneof, "oneof");
Objects.requireNonNull(oneofStoredType, "oneofStoredType");
checkNotNull(fieldType, "fieldType");
checkNotNull(oneof, "oneof");
checkNotNull(oneofStoredType, "oneofStoredType");
if (!fieldType.isScalar()) {
throw new IllegalArgumentException(
"Oneof is only supported for scalar fields. Field "
@ -271,9 +272,9 @@ final class FieldInfo implements Comparable<FieldInfo> {
boolean enforceUtf8,
EnumVerifier enumVerifier) {
checkFieldNumber(fieldNumber);
Objects.requireNonNull(field, "field");
Objects.requireNonNull(fieldType, "fieldType");
Objects.requireNonNull(presenceField, "presenceField");
checkNotNull(field, "field");
checkNotNull(fieldType, "fieldType");
checkNotNull(presenceField, "presenceField");
if (presenceField != null && !isExactlyOneBitSet(presenceMask)) {
throw new IllegalArgumentException(
"presenceMask must have exactly one bit set: " + presenceMask);
@ -296,9 +297,9 @@ final class FieldInfo implements Comparable<FieldInfo> {
public static FieldInfo forMapField(
Field field, int fieldNumber, Object mapDefaultEntry, EnumVerifier enumVerifier) {
Objects.requireNonNull(mapDefaultEntry, "mapDefaultEntry");
checkNotNull(mapDefaultEntry, "mapDefaultEntry");
checkFieldNumber(fieldNumber);
Objects.requireNonNull(field, "field");
checkNotNull(field, "field");
return new FieldInfo(
field,
fieldNumber,
@ -488,7 +489,7 @@ final class FieldInfo implements Comparable<FieldInfo> {
/** Specifies proto2 presence information. This should not be called for oneof fields. */
public Builder withPresence(Field presenceField, int presenceMask) {
this.presenceField = Objects.requireNonNull(presenceField, "presenceField");
this.presenceField = checkNotNull(presenceField, "presenceField");
this.presenceMask = presenceMask;
return this;
}

@ -30,6 +30,8 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.LazyField.LazyIterator;
import java.io.IOException;
import java.util.ArrayList;
@ -37,7 +39,6 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* A class which represents an arbitrary set of fields of some message type. This is used to
@ -409,7 +410,7 @@ final class FieldSet<T extends FieldSet.FieldDescriptorLite<T>> {
private static boolean isValidType(final WireFormat.FieldType type, final Object value) {
Objects.requireNonNull(value);
checkNotNull(value);
switch (type.getJavaType()) {
case INT:
return value instanceof Integer;

@ -30,10 +30,11 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Internal.FloatList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.RandomAccess;
/**
@ -236,7 +237,7 @@ final class FloatArrayList extends AbstractProtobufList<Float>
public boolean addAll(Collection<? extends Float> collection) {
ensureIsMutable();
Objects.requireNonNull(collection);
checkNotNull(collection);
// We specialize when adding another FloatArrayList to avoid boxing elements.
if (!(collection instanceof FloatArrayList)) {

@ -30,6 +30,8 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;

@ -30,10 +30,11 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Internal.IntList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.RandomAccess;
/**
@ -236,7 +237,7 @@ final class IntArrayList extends AbstractProtobufList<Integer>
public boolean addAll(Collection<? extends Integer> collection) {
ensureIsMutable();
Objects.requireNonNull(collection);
checkNotNull(collection);
// We specialize when adding another IntArrayList to avoid boxing elements.
if (!(collection instanceof IntArrayList)) {

@ -57,6 +57,22 @@ public final class Internal {
static final Charset UTF_8 = Charset.forName("UTF-8");
static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
/** Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. */
static <T> T checkNotNull(T obj) {
if (obj == null) {
throw new NullPointerException();
}
return obj;
}
/** Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. */
static <T> T checkNotNull(T obj, String message) {
if (obj == null) {
throw new NullPointerException(message);
}
return obj;
}
/**
* Helper called by generated code to construct default values for string fields.
*

@ -31,7 +31,6 @@
package com.google.protobuf;
import java.io.IOException;
import java.util.Objects;
/**
* LazyFieldLite encapsulates the logic of lazily parsing message fields. It stores the message in a
@ -117,8 +116,9 @@ public class LazyFieldLite {
/** Constructs a LazyFieldLite with bytes that will be parsed lazily. */
public LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes) {
this.extensionRegistry = Objects.requireNonNull(extensionRegistry, "found null ExtensionRegistry");
this.delayedBytes = Objects.requireNonNull(bytes, "found null ByteString");
checkArguments(extensionRegistry, bytes);
this.extensionRegistry = extensionRegistry;
this.delayedBytes = bytes;
}
/** Constructs a LazyFieldLite with no contents, and no ability to parse extensions. */
@ -340,8 +340,9 @@ public class LazyFieldLite {
/** Sets this field with bytes to delay-parse. */
public void setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry) {
this.delayedBytes = Objects.requireNonNull(bytes, "found null ByteString");
this.extensionRegistry = Objects.requireNonNull(extensionRegistry, "found null ExtensionRegistry");
checkArguments(extensionRegistry, bytes);
this.delayedBytes = bytes;
this.extensionRegistry = extensionRegistry;
this.value = null;
this.memoizedBytes = null;
}
@ -428,4 +429,13 @@ public class LazyFieldLite {
}
}
}
private static void checkArguments(ExtensionRegistryLite extensionRegistry, ByteString bytes) {
if (extensionRegistry == null) {
throw new NullPointerException("found null ExtensionRegistry");
}
if (bytes == null) {
throw new NullPointerException("found null ByteString");
}
}
}

@ -30,10 +30,11 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Internal.LongList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.RandomAccess;
/**
@ -236,7 +237,7 @@ final class LongArrayList extends AbstractProtobufList<Long>
public boolean addAll(Collection<? extends Long> collection) {
ensureIsMutable();
Objects.requireNonNull(collection);
checkNotNull(collection);
// We specialize when adding another LongArrayList to avoid boxing elements.
if (!(collection instanceof LongArrayList)) {

@ -30,7 +30,7 @@
package com.google.protobuf;
import java.util.Objects;
import static com.google.protobuf.Internal.checkNotNull;
/**
* Dynamically generates a manifest-based (i.e. table-based) schema for a given protobuf message.
@ -45,7 +45,7 @@ final class ManifestSchemaFactory implements SchemaFactory {
}
private ManifestSchemaFactory(MessageInfoFactory messageInfoFactory) {
this.messageInfoFactory = Objects.requireNonNull(messageInfoFactory, "messageInfoFactory");
this.messageInfoFactory = checkNotNull(messageInfoFactory, "messageInfoFactory");
}
@Override

@ -30,6 +30,8 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -37,7 +39,6 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
@ -319,8 +320,8 @@ public class MapField<K, V> implements MutabilityOracle {
@Override
public V put(K key, V value) {
mutabilityOracle.ensureMutable();
Objects.requireNonNull(key);
Objects.requireNonNull(value);
checkNotNull(key);
checkNotNull(value);
return delegate.put(key, value);
}
@ -334,8 +335,8 @@ public class MapField<K, V> implements MutabilityOracle {
public void putAll(Map<? extends K, ? extends V> m) {
mutabilityOracle.ensureMutable();
for (K key : m.keySet()) {
Objects.requireNonNull(key);
Objects.requireNonNull(m.get(key));
checkNotNull(key);
checkNotNull(m.get(key));
}
delegate.putAll(m);
}

@ -30,12 +30,13 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Internal.EnumLite;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
@ -91,9 +92,9 @@ public final class MapFieldLite<K, V> extends LinkedHashMap<K, V> {
@Override
public V put(K key, V value) {
ensureMutable();
Objects.requireNonNull(key);
checkNotNull(key);
Objects.requireNonNull(value);
checkNotNull(value);
return super.put(key, value);
}
@ -116,8 +117,8 @@ public final class MapFieldLite<K, V> extends LinkedHashMap<K, V> {
private static void checkForNullKeysAndValues(Map<?, ?> m) {
for (Object key : m.keySet()) {
Objects.requireNonNull(key);
Objects.requireNonNull(m.get(key));
checkNotNull(key);
checkNotNull(m.get(key));
}
}

@ -80,7 +80,6 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/** Schema used for standard messages. */
final class MessageSchema<T> implements Schema<T> {
@ -1177,7 +1176,9 @@ final class MessageSchema<T> implements Schema<T> {
@Override
public void mergeFrom(T message, T other) {
Objects.requireNonNull(other);
if (other == null) {
throw new NullPointerException();
}
for (int i = 0; i < buffer.length; i += INTS_PER_FIELD) {
// A separate method allows for better JIT optimizations
mergeSingleField(message, other, i);
@ -3849,7 +3850,9 @@ final class MessageSchema<T> implements Schema<T> {
@Override
public void mergeFrom(T message, Reader reader, ExtensionRegistryLite extensionRegistry)
throws IOException {
Objects.requireNonNull(extensionRegistry);
if (extensionRegistry == null) {
throw new NullPointerException();
}
mergeFromHelper(unknownFieldSchema, extensionSchema, message, reader, extensionRegistry);
}

@ -30,6 +30,8 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.io.IOException;
import java.io.InputStream;
import java.io.InvalidObjectException;
@ -42,14 +44,13 @@ import java.nio.InvalidMarkException;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/** A {@link ByteString} that wraps around a {@link ByteBuffer}. */
final class NioByteString extends ByteString.LeafByteString {
private final ByteBuffer buffer;
NioByteString(ByteBuffer buffer) {
Objects.requireNonNull(buffer, "buffer");
checkNotNull(buffer, "buffer");
// Use native byte order for fast fixed32/64 operations.
this.buffer = buffer.slice().order(ByteOrder.nativeOrder());

@ -30,8 +30,9 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@ -82,7 +83,7 @@ final class Protobuf {
/** Gets the schema for the given message type. */
public <T> Schema<T> schemaFor(Class<T> messageType) {
Objects.requireNonNull(messageType, "messageType");
checkNotNull(messageType, "messageType");
@SuppressWarnings("unchecked")
Schema<T> schema = (Schema<T>) schemaCache.get(messageType);
if (schema == null) {
@ -112,8 +113,8 @@ final class Protobuf {
* registered.
*/
public Schema<?> registerSchema(Class<?> messageType, Schema<?> schema) {
Objects.requireNonNull(messageType, "messageType");
Objects.requireNonNull(schema, "schema");
checkNotNull(messageType, "messageType");
checkNotNull(schema, "schema");
return schemaCache.putIfAbsent(messageType, schema);
}
@ -127,8 +128,8 @@ final class Protobuf {
* previously.
*/
public Schema<?> registerSchemaOverride(Class<?> messageType, Schema<?> schema) {
Objects.requireNonNull(messageType, "messageType");
Objects.requireNonNull(schema, "schema");
checkNotNull(messageType, "messageType");
checkNotNull(schema, "schema");
return schemaCache.put(messageType, schema);
}

@ -30,12 +30,13 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* {@code RepeatedFieldBuilder} implements a structure that a protocol message uses to hold a
@ -276,7 +277,7 @@ public class RepeatedFieldBuilder<
* @return the builder
*/
public RepeatedFieldBuilder<MType, BType, IType> setMessage(int index, MType message) {
Objects.requireNonNull(message);
checkNotNull(message);
ensureMutableMessageList();
messages.set(index, message);
if (builders != null) {
@ -297,7 +298,7 @@ public class RepeatedFieldBuilder<
* @return the builder
*/
public RepeatedFieldBuilder<MType, BType, IType> addMessage(MType message) {
Objects.requireNonNull(message);
checkNotNull(message);
ensureMutableMessageList();
messages.add(message);
if (builders != null) {
@ -318,7 +319,7 @@ public class RepeatedFieldBuilder<
* @return the builder
*/
public RepeatedFieldBuilder<MType, BType, IType> addMessage(int index, MType message) {
Objects.requireNonNull(message);
checkNotNull(message);
ensureMutableMessageList();
messages.add(index, message);
if (builders != null) {
@ -339,7 +340,7 @@ public class RepeatedFieldBuilder<
public RepeatedFieldBuilder<MType, BType, IType> addAllMessages(
Iterable<? extends MType> values) {
for (final MType value : values) {
Objects.requireNonNull(value);
checkNotNull(value);
}
// If we can inspect the size, we can more efficiently add messages.

@ -30,12 +30,13 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* {@code RepeatedFieldBuilderV3} implements a structure that a protocol message uses to hold a
@ -276,7 +277,7 @@ public class RepeatedFieldBuilderV3<
* @return the builder
*/
public RepeatedFieldBuilderV3<MType, BType, IType> setMessage(int index, MType message) {
Objects.requireNonNull(message);
checkNotNull(message);
ensureMutableMessageList();
messages.set(index, message);
if (builders != null) {
@ -297,7 +298,7 @@ public class RepeatedFieldBuilderV3<
* @return the builder
*/
public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(MType message) {
Objects.requireNonNull(message);
checkNotNull(message);
ensureMutableMessageList();
messages.add(message);
if (builders != null) {
@ -318,7 +319,7 @@ public class RepeatedFieldBuilderV3<
* @return the builder
*/
public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(int index, MType message) {
Objects.requireNonNull(message);
checkNotNull(message);
ensureMutableMessageList();
messages.add(index, message);
if (builders != null) {
@ -339,7 +340,7 @@ public class RepeatedFieldBuilderV3<
public RepeatedFieldBuilderV3<MType, BType, IType> addAllMessages(
Iterable<? extends MType> values) {
for (final MType value : values) {
Objects.requireNonNull(value);
checkNotNull(value);
}
// If we can inspect the size, we can more efficiently add messages.

@ -44,7 +44,6 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
/**
* Class to represent {@code ByteStrings} formed by concatenation of other ByteStrings, without
@ -845,8 +844,9 @@ final class RopeByteString extends ByteString {
*/
@Override
public int read(byte[] b, int offset, int length) {
Objects.requireNonNull(b);
if (offset < 0 || length < 0 || length > b.length - offset) {
if (b == null) {
throw new NullPointerException();
} else if (offset < 0 || length < 0 || length > b.length - offset) {
throw new IndexOutOfBoundsException();
}
int bytesRead = readSkipInternal(b, offset, length);

@ -30,7 +30,7 @@
package com.google.protobuf;
import java.util.Objects;
import static com.google.protobuf.Internal.checkNotNull;
/**
* {@code SingleFieldBuilder} implements a structure that a protocol message uses to hold a single
@ -77,7 +77,7 @@ public class SingleFieldBuilder<
private boolean isClean;
public SingleFieldBuilder(MType message, GeneratedMessage.BuilderParent parent, boolean isClean) {
this.message = Objects.requireNonNull(message);
this.message = checkNotNull(message);
this.parent = parent;
this.isClean = isClean;
}
@ -157,7 +157,7 @@ public class SingleFieldBuilder<
* @return the builder
*/
public SingleFieldBuilder<MType, BType, IType> setMessage(MType message) {
this.message = Objects.requireNonNull(message);
this.message = checkNotNull(message);
if (builder != null) {
builder.dispose();
builder = null;

@ -30,7 +30,7 @@
package com.google.protobuf;
import java.util.Objects;
import static com.google.protobuf.Internal.checkNotNull;
/**
* {@code SingleFieldBuilderV3} implements a structure that a protocol message uses to hold a single
@ -77,7 +77,7 @@ public class SingleFieldBuilderV3<
private boolean isClean;
public SingleFieldBuilderV3(MType message, AbstractMessage.BuilderParent parent, boolean isClean) {
this.message = Objects.requireNonNull(message);
this.message = checkNotNull(message);
this.parent = parent;
this.isClean = isClean;
}
@ -157,7 +157,7 @@ public class SingleFieldBuilderV3<
* @return the builder
*/
public SingleFieldBuilderV3<MType, BType, IType> setMessage(MType message) {
this.message = Objects.requireNonNull(message);
this.message = checkNotNull(message);
if (builder != null) {
builder.dispose();
builder = null;

@ -30,10 +30,11 @@
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* Information for the layout of a protobuf message class. This describes all of the fields
@ -63,7 +64,7 @@ final class StructuralMessageInfo implements MessageInfo {
this.messageSetWireFormat = messageSetWireFormat;
this.checkInitialized = checkInitialized;
this.fields = fields;
this.defaultInstance = (MessageLite) Objects.requireNonNull(defaultInstance, "defaultInstance");
this.defaultInstance = (MessageLite) checkNotNull(defaultInstance, "defaultInstance");
}
/** Gets the syntax for the message (e.g. PROTO2, PROTO3). */
@ -128,7 +129,7 @@ final class StructuralMessageInfo implements MessageInfo {
}
public void withSyntax(ProtoSyntax syntax) {
this.syntax = Objects.requireNonNull(syntax, "syntax");
this.syntax = checkNotNull(syntax, "syntax");
}
public void withMessageSetWireFormat(boolean messageSetWireFormat) {

@ -166,6 +166,27 @@
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.20</version>
<configuration>
<signature>
<groupId>net.sf.androidscents.signature</groupId>
<artifactId>android-api-level-14</artifactId>
<version>4.0_r4</version>
</signature>
</configuration>
<executions>
<execution>
<id>android</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

Loading…
Cancel
Save