Commit bf0a7937 by tonihei Committed by Oliver Woodman

Fix util nullness warnings.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=212276150
parent 09aaec6b
...@@ -1409,10 +1409,8 @@ public final class Format implements Parcelable { ...@@ -1409,10 +1409,8 @@ public final class Format implements Parcelable {
// Utility methods // Utility methods
/** /** Returns a prettier {@link String} than {@link #toString()}, intended for logging. */
* Returns a prettier {@link String} than {@link #toString()}, intended for logging. public static String toLogString(@Nullable Format format) {
*/
public static String toLogString(Format format) {
if (format == null) { if (format == null) {
return "null"; return "null";
} }
......
...@@ -19,6 +19,7 @@ import com.google.android.exoplayer2.C; ...@@ -19,6 +19,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataDecoder; import com.google.android.exoplayer2.metadata.MetadataDecoder;
import com.google.android.exoplayer2.metadata.MetadataInputBuffer; import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
...@@ -39,8 +40,8 @@ public final class EventMessageDecoder implements MetadataDecoder { ...@@ -39,8 +40,8 @@ public final class EventMessageDecoder implements MetadataDecoder {
byte[] data = buffer.array(); byte[] data = buffer.array();
int size = buffer.limit(); int size = buffer.limit();
ParsableByteArray emsgData = new ParsableByteArray(data, size); ParsableByteArray emsgData = new ParsableByteArray(data, size);
String schemeIdUri = emsgData.readNullTerminatedString(); String schemeIdUri = Assertions.checkNotNull(emsgData.readNullTerminatedString());
String value = emsgData.readNullTerminatedString(); String value = Assertions.checkNotNull(emsgData.readNullTerminatedString());
long timescale = emsgData.readUnsignedInt(); long timescale = emsgData.readUnsignedInt();
long presentationTimeUs = Util.scaleLargeTimestamp(emsgData.readUnsignedInt(), long presentationTimeUs = Util.scaleLargeTimestamp(emsgData.readUnsignedInt(),
C.MICROS_PER_SECOND, timescale); C.MICROS_PER_SECOND, timescale);
......
...@@ -103,7 +103,7 @@ public final class AtomicFile { ...@@ -103,7 +103,7 @@ public final class AtomicFile {
str = new AtomicFileOutputStream(baseName); str = new AtomicFileOutputStream(baseName);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
File parent = baseName.getParentFile(); File parent = baseName.getParentFile();
if (!parent.mkdirs()) { if (parent == null || !parent.mkdirs()) {
throw new IOException("Couldn't create directory " + baseName, e); throw new IOException("Couldn't create directory " + baseName, e);
} }
try { try {
......
...@@ -42,6 +42,7 @@ import java.text.NumberFormat; ...@@ -42,6 +42,7 @@ import java.text.NumberFormat;
import java.util.Locale; import java.util.Locale;
/** Logs events from {@link Player} and other core components using {@link Log}. */ /** Logs events from {@link Player} and other core components using {@link Log}. */
@SuppressWarnings("UngroupedOverloads")
public class EventLogger implements AnalyticsListener { public class EventLogger implements AnalyticsListener {
private static final String DEFAULT_TAG = "EventLogger"; private static final String DEFAULT_TAG = "EventLogger";
...@@ -435,7 +436,7 @@ public class EventLogger implements AnalyticsListener { ...@@ -435,7 +436,7 @@ public class EventLogger implements AnalyticsListener {
* @param msg The message to log. * @param msg The message to log.
* @param tr The exception to log. * @param tr The exception to log.
*/ */
protected void loge(String msg, Throwable tr) { protected void loge(String msg, @Nullable Throwable tr) {
Log.e(tag, msg, tr); Log.e(tag, msg, tr);
} }
...@@ -449,12 +450,15 @@ public class EventLogger implements AnalyticsListener { ...@@ -449,12 +450,15 @@ public class EventLogger implements AnalyticsListener {
logd(getEventString(eventTime, eventName, eventDescription)); logd(getEventString(eventTime, eventName, eventDescription));
} }
private void loge(EventTime eventTime, String eventName, Throwable throwable) { private void loge(EventTime eventTime, String eventName, @Nullable Throwable throwable) {
loge(getEventString(eventTime, eventName), throwable); loge(getEventString(eventTime, eventName), throwable);
} }
private void loge( private void loge(
EventTime eventTime, String eventName, String eventDescription, Throwable throwable) { EventTime eventTime,
String eventName,
String eventDescription,
@Nullable Throwable throwable) {
loge(getEventString(eventTime, eventName, eventDescription), throwable); loge(getEventString(eventTime, eventName, eventDescription), throwable);
} }
...@@ -548,8 +552,8 @@ public class EventLogger implements AnalyticsListener { ...@@ -548,8 +552,8 @@ public class EventLogger implements AnalyticsListener {
// Suppressing reference equality warning because the track group stored in the track selection // Suppressing reference equality warning because the track group stored in the track selection
// must point to the exact track group object to be considered part of it. // must point to the exact track group object to be considered part of it.
@SuppressWarnings("ReferenceEquality") @SuppressWarnings("ReferenceEquality")
private static String getTrackStatusString(TrackSelection selection, TrackGroup group, private static String getTrackStatusString(
int trackIndex) { @Nullable TrackSelection selection, TrackGroup group, int trackIndex) {
return getTrackStatusString(selection != null && selection.getTrackGroup() == group return getTrackStatusString(selection != null && selection.getTrackGroup() == group
&& selection.indexOf(trackIndex) != C.INDEX_UNSET); && selection.indexOf(trackIndex) != C.INDEX_UNSET);
} }
......
...@@ -28,10 +28,10 @@ public final class ParsableBitArray { ...@@ -28,10 +28,10 @@ public final class ParsableBitArray {
private int bitOffset; private int bitOffset;
private int byteLimit; private int byteLimit;
/** /** Creates a new instance that initially has no backing data. */
* Creates a new instance that initially has no backing data. public ParsableBitArray() {
*/ data = Util.EMPTY_BYTE_ARRAY;
public ParsableBitArray() {} }
/** /**
* Creates a new instance that wraps an existing array. * Creates a new instance that wraps an existing array.
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.util; package com.google.android.exoplayer2.util;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
...@@ -30,10 +31,10 @@ public final class ParsableByteArray { ...@@ -30,10 +31,10 @@ public final class ParsableByteArray {
private int position; private int position;
private int limit; private int limit;
/** /** Creates a new instance that initially has no backing data. */
* Creates a new instance that initially has no backing data. public ParsableByteArray() {
*/ data = Util.EMPTY_BYTE_ARRAY;
public ParsableByteArray() {} }
/** /**
* Creates a new instance with {@code limit} bytes and sets the limit. * Creates a new instance with {@code limit} bytes and sets the limit.
...@@ -131,7 +132,7 @@ public final class ParsableByteArray { ...@@ -131,7 +132,7 @@ public final class ParsableByteArray {
* Returns the capacity of the array, which may be larger than the limit. * Returns the capacity of the array, which may be larger than the limit.
*/ */
public int capacity() { public int capacity() {
return data == null ? 0 : data.length; return data.length;
} }
/** /**
...@@ -481,7 +482,7 @@ public final class ParsableByteArray { ...@@ -481,7 +482,7 @@ public final class ParsableByteArray {
* @return The string not including any terminating NUL byte, or null if the end of the data has * @return The string not including any terminating NUL byte, or null if the end of the data has
* already been reached. * already been reached.
*/ */
public String readNullTerminatedString() { public @Nullable String readNullTerminatedString() {
if (bytesLeft() == 0) { if (bytesLeft() == 0) {
return null; return null;
} }
...@@ -507,7 +508,7 @@ public final class ParsableByteArray { ...@@ -507,7 +508,7 @@ public final class ParsableByteArray {
* @return The line not including any line-termination characters, or null if the end of the data * @return The line not including any line-termination characters, or null if the end of the data
* has already been reached. * has already been reached.
*/ */
public String readLine() { public @Nullable String readLine() {
if (bytesLeft() == 0) { if (bytesLeft() == 0) {
return null; return null;
} }
......
...@@ -35,6 +35,7 @@ public final class ParsableNalUnitBitArray { ...@@ -35,6 +35,7 @@ public final class ParsableNalUnitBitArray {
* @param offset The byte offset in {@code data} to start reading from. * @param offset The byte offset in {@code data} to start reading from.
* @param limit The byte offset of the end of the bitstream in {@code data}. * @param limit The byte offset of the end of the bitstream in {@code data}.
*/ */
@SuppressWarnings({"initialization.fields.uninitialized", "method.invocation.invalid"})
public ParsableNalUnitBitArray(byte[] data, int offset, int limit) { public ParsableNalUnitBitArray(byte[] data, int offset, int limit) {
reset(data, offset, limit); reset(data, offset, limit);
} }
......
...@@ -111,7 +111,7 @@ public final class PriorityTaskManager { ...@@ -111,7 +111,7 @@ public final class PriorityTaskManager {
public void remove(int priority) { public void remove(int priority) {
synchronized (lock) { synchronized (lock) {
queue.remove(priority); queue.remove(priority);
highestPriority = queue.isEmpty() ? Integer.MIN_VALUE : queue.peek(); highestPriority = queue.isEmpty() ? Integer.MIN_VALUE : Util.castNonNull(queue.peek());
lock.notifyAll(); lock.notifyAll();
} }
} }
......
...@@ -1678,9 +1678,9 @@ public final class Util { ...@@ -1678,9 +1678,9 @@ public final class Util {
* *
* @param input Wraps the compressed input data. * @param input Wraps the compressed input data.
* @param output Wraps an output buffer to be used to store the uncompressed data. If {@code * @param output Wraps an output buffer to be used to store the uncompressed data. If {@code
* output.data} is null or it isn't big enough to hold the uncompressed data, a new array is * output.data} isn't big enough to hold the uncompressed data, a new array is created. If
* created. If {@code true} is returned then the output's position will be set to 0 and its * {@code true} is returned then the output's position will be set to 0 and its limit will be
* limit will be set to the length of the uncompressed data. * set to the length of the uncompressed data.
* @param inflater If not null, used to uncompressed the input. Otherwise a new {@link Inflater} * @param inflater If not null, used to uncompressed the input. Otherwise a new {@link Inflater}
* is created. * is created.
* @return Whether the input is uncompressed successfully. * @return Whether the input is uncompressed successfully.
...@@ -1691,8 +1691,8 @@ public final class Util { ...@@ -1691,8 +1691,8 @@ public final class Util {
return false; return false;
} }
byte[] outputData = output.data; byte[] outputData = output.data;
if (outputData == null) { if (outputData.length < input.bytesLeft()) {
outputData = new byte[input.bytesLeft()]; outputData = new byte[2 * input.bytesLeft()];
} }
if (inflater == null) { if (inflater == null) {
inflater = new Inflater(); inflater = new Inflater();
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.util; package com.google.android.exoplayer2.util;
import android.support.annotation.Nullable;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
...@@ -93,7 +94,7 @@ public final class XmlPullParserUtil { ...@@ -93,7 +94,7 @@ public final class XmlPullParserUtil {
* @return The value of the attribute, or null if the current event is not a start tag or if no * @return The value of the attribute, or null if the current event is not a start tag or if no
* such attribute was found. * such attribute was found.
*/ */
public static String getAttributeValue(XmlPullParser xpp, String attributeName) { public static @Nullable String getAttributeValue(XmlPullParser xpp, String attributeName) {
int attributeCount = xpp.getAttributeCount(); int attributeCount = xpp.getAttributeCount();
for (int i = 0; i < attributeCount; i++) { for (int i = 0; i < attributeCount; i++) {
if (xpp.getAttributeName(i).equals(attributeName)) { if (xpp.getAttributeName(i).equals(attributeName)) {
...@@ -112,7 +113,8 @@ public final class XmlPullParserUtil { ...@@ -112,7 +113,8 @@ public final class XmlPullParserUtil {
* @return The value of the attribute, or null if the current event is not a start tag or if no * @return The value of the attribute, or null if the current event is not a start tag or if no
* such attribute was found. * such attribute was found.
*/ */
public static String getAttributeValueIgnorePrefix(XmlPullParser xpp, String attributeName) { public static @Nullable String getAttributeValueIgnorePrefix(
XmlPullParser xpp, String attributeName) {
int attributeCount = xpp.getAttributeCount(); int attributeCount = xpp.getAttributeCount();
for (int i = 0; i < attributeCount; i++) { for (int i = 0; i < attributeCount; i++) {
if (stripPrefix(xpp.getAttributeName(i)).equals(attributeName)) { if (stripPrefix(xpp.getAttributeName(i)).equals(attributeName)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment