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

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

@ -34,7 +34,6 @@ import static com.google.protobuf.MessageSchema.getMutableUnknownFields;
import com.google.protobuf.Internal.ProtobufList; import com.google.protobuf.Internal.ProtobufList;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
/** /**
* Helper functions to decode protobuf wire format from a byte array. * Helper functions to decode protobuf wire format from a byte array.
@ -65,7 +64,10 @@ final class ArrayDecoders {
} }
Registers(ExtensionRegistryLite extensionRegistry) { 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; 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.FIXED32_SIZE;
import static com.google.protobuf.WireFormat.FIXED64_SIZE; import static com.google.protobuf.WireFormat.FIXED64_SIZE;
import static com.google.protobuf.WireFormat.MAX_VARINT32_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.ArrayDeque;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Queue; import java.util.Queue;
/** /**
@ -146,7 +146,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer {
if (chunkSize <= 0) { if (chunkSize <= 0) {
throw new IllegalArgumentException("chunkSize must be > 0"); throw new IllegalArgumentException("chunkSize must be > 0");
} }
this.alloc = Objects.requireNonNull(alloc, "alloc"); this.alloc = checkNotNull(alloc, "alloc");
this.chunkSize = chunkSize; this.chunkSize = chunkSize;
} }

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

@ -55,7 +55,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects;
/** /**
* Immutable sequence of bytes. Provides conversions to and from {@code byte[]}, {@link * 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 * @param bytes array to wrap
*/ */
LiteralByteString(byte[] bytes) { LiteralByteString(byte[] bytes) {
this.bytes = Objects.requireNonNull(bytes); if (bytes == null) {
throw new NullPointerException();
}
this.bytes = bytes;
} }
@Override @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_ARRAY;
import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER; import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER;
import static com.google.protobuf.Internal.UTF_8; 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.FIXED32_SIZE;
import static com.google.protobuf.WireFormat.FIXED64_SIZE; import static com.google.protobuf.WireFormat.FIXED64_SIZE;
import static com.google.protobuf.WireFormat.MAX_VARINT_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.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* Reads and decodes protocol message fields. * Reads and decodes protocol message fields.
@ -2056,7 +2056,8 @@ public abstract class CodedInputStream {
private int currentLimit = Integer.MAX_VALUE; private int currentLimit = Integer.MAX_VALUE;
private StreamDecoder(final InputStream input, int bufferSize) { 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.buffer = new byte[bufferSize];
this.bufferSize = 0; this.bufferSize = 0;
pos = 0; pos = 0;

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

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

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

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

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

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

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

@ -30,6 +30,8 @@
package com.google.protobuf; package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.LazyField.LazyIterator; import com.google.protobuf.LazyField.LazyIterator;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,7 +39,6 @@ import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; 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 * 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) { private static boolean isValidType(final WireFormat.FieldType type, final Object value) {
Objects.requireNonNull(value); checkNotNull(value);
switch (type.getJavaType()) { switch (type.getJavaType()) {
case INT: case INT:
return value instanceof Integer; return value instanceof Integer;

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

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

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

@ -57,6 +57,22 @@ public final class Internal {
static final Charset UTF_8 = Charset.forName("UTF-8"); static final Charset UTF_8 = Charset.forName("UTF-8");
static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); 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. * Helper called by generated code to construct default values for string fields.
* *

@ -31,7 +31,6 @@
package com.google.protobuf; package com.google.protobuf;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
/** /**
* LazyFieldLite encapsulates the logic of lazily parsing message fields. It stores the message in a * 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. */ /** Constructs a LazyFieldLite with bytes that will be parsed lazily. */
public LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes) { public LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes) {
this.extensionRegistry = Objects.requireNonNull(extensionRegistry, "found null ExtensionRegistry"); checkArguments(extensionRegistry, bytes);
this.delayedBytes = Objects.requireNonNull(bytes, "found null ByteString"); this.extensionRegistry = extensionRegistry;
this.delayedBytes = bytes;
} }
/** Constructs a LazyFieldLite with no contents, and no ability to parse extensions. */ /** 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. */ /** Sets this field with bytes to delay-parse. */
public void setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry) { public void setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry) {
this.delayedBytes = Objects.requireNonNull(bytes, "found null ByteString"); checkArguments(extensionRegistry, bytes);
this.extensionRegistry = Objects.requireNonNull(extensionRegistry, "found null ExtensionRegistry"); this.delayedBytes = bytes;
this.extensionRegistry = extensionRegistry;
this.value = null; this.value = null;
this.memoizedBytes = 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; package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Internal.LongList; import com.google.protobuf.Internal.LongList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Objects;
import java.util.RandomAccess; import java.util.RandomAccess;
/** /**
@ -236,7 +237,7 @@ final class LongArrayList extends AbstractProtobufList<Long>
public boolean addAll(Collection<? extends Long> collection) { public boolean addAll(Collection<? extends Long> collection) {
ensureIsMutable(); ensureIsMutable();
Objects.requireNonNull(collection); checkNotNull(collection);
// We specialize when adding another LongArrayList to avoid boxing elements. // We specialize when adding another LongArrayList to avoid boxing elements.
if (!(collection instanceof LongArrayList)) { if (!(collection instanceof LongArrayList)) {

@ -30,7 +30,7 @@
package com.google.protobuf; 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. * 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) { private ManifestSchemaFactory(MessageInfoFactory messageInfoFactory) {
this.messageInfoFactory = Objects.requireNonNull(messageInfoFactory, "messageInfoFactory"); this.messageInfoFactory = checkNotNull(messageInfoFactory, "messageInfoFactory");
} }
@Override @Override

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

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

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

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

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

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

@ -30,12 +30,13 @@
package com.google.protobuf; package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import java.util.AbstractList; import java.util.AbstractList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* {@code RepeatedFieldBuilderV3} implements a structure that a protocol message uses to hold a * {@code RepeatedFieldBuilderV3} implements a structure that a protocol message uses to hold a
@ -276,7 +277,7 @@ public class RepeatedFieldBuilderV3<
* @return the builder * @return the builder
*/ */
public RepeatedFieldBuilderV3<MType, BType, IType> setMessage(int index, MType message) { public RepeatedFieldBuilderV3<MType, BType, IType> setMessage(int index, MType message) {
Objects.requireNonNull(message); checkNotNull(message);
ensureMutableMessageList(); ensureMutableMessageList();
messages.set(index, message); messages.set(index, message);
if (builders != null) { if (builders != null) {
@ -297,7 +298,7 @@ public class RepeatedFieldBuilderV3<
* @return the builder * @return the builder
*/ */
public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(MType message) { public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(MType message) {
Objects.requireNonNull(message); checkNotNull(message);
ensureMutableMessageList(); ensureMutableMessageList();
messages.add(message); messages.add(message);
if (builders != null) { if (builders != null) {
@ -318,7 +319,7 @@ public class RepeatedFieldBuilderV3<
* @return the builder * @return the builder
*/ */
public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(int index, MType message) { public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(int index, MType message) {
Objects.requireNonNull(message); checkNotNull(message);
ensureMutableMessageList(); ensureMutableMessageList();
messages.add(index, message); messages.add(index, message);
if (builders != null) { if (builders != null) {
@ -339,7 +340,7 @@ public class RepeatedFieldBuilderV3<
public RepeatedFieldBuilderV3<MType, BType, IType> addAllMessages( public RepeatedFieldBuilderV3<MType, BType, IType> addAllMessages(
Iterable<? extends MType> values) { Iterable<? extends MType> values) {
for (final MType value : values) { for (final MType value : values) {
Objects.requireNonNull(value); checkNotNull(value);
} }
// If we can inspect the size, we can more efficiently add messages. // 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.Iterator;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects;
/** /**
* Class to represent {@code ByteStrings} formed by concatenation of other ByteStrings, without * Class to represent {@code ByteStrings} formed by concatenation of other ByteStrings, without
@ -845,8 +844,9 @@ final class RopeByteString extends ByteString {
*/ */
@Override @Override
public int read(byte[] b, int offset, int length) { public int read(byte[] b, int offset, int length) {
Objects.requireNonNull(b); if (b == null) {
if (offset < 0 || length < 0 || length > b.length - offset) { throw new NullPointerException();
} else if (offset < 0 || length < 0 || length > b.length - offset) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
int bytesRead = readSkipInternal(b, offset, length); int bytesRead = readSkipInternal(b, offset, length);

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

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

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

@ -166,6 +166,27 @@
<artifactId>maven-antrun-plugin</artifactId> <artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version> <version>1.8</version>
</plugin> </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> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>

Loading…
Cancel
Save