Commit 8df6a4b3 by ibaker Committed by Oliver Woodman

Remove nullness warning suppressions from Matcher.group

These were introduced in https://github.com/google/ExoPlayer/commit/c7164a30a067e5ddf5f0c706d6861652d39fd967

In each case I checked that the groups are not optional,
so if they match they must be non-null.

PiperOrigin-RevId: 305213293
parent d87fc723
...@@ -818,10 +818,10 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource { ...@@ -818,10 +818,10 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
Matcher matcher = CONTENT_RANGE_HEADER_PATTERN.matcher(contentRangeHeader); Matcher matcher = CONTENT_RANGE_HEADER_PATTERN.matcher(contentRangeHeader);
if (matcher.find()) { if (matcher.find()) {
try { try {
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
long contentLengthFromRange = long contentLengthFromRange =
Long.parseLong(matcher.group(2)) - Long.parseLong(matcher.group(1)) + 1; Long.parseLong(Assertions.checkNotNull(matcher.group(2)))
- Long.parseLong(Assertions.checkNotNull(matcher.group(1)))
+ 1;
if (contentLength < 0) { if (contentLength < 0) {
// Some proxy servers strip the Content-Length header. Fall back to the length // Some proxy servers strip the Content-Length header. Fall back to the length
// calculated here in this case. // calculated here in this case.
......
...@@ -1740,9 +1740,8 @@ public final class Util { ...@@ -1740,9 +1740,8 @@ public final class Util {
Matcher matcher = ESCAPED_CHARACTER_PATTERN.matcher(fileName); Matcher matcher = ESCAPED_CHARACTER_PATTERN.matcher(fileName);
int startOfNotEscaped = 0; int startOfNotEscaped = 0;
while (percentCharacterCount > 0 && matcher.find()) { while (percentCharacterCount > 0 && matcher.find()) {
// incompatible types in argument. char unescapedCharacter =
@SuppressWarnings("nullness:argument.type.incompatible") (char) Integer.parseInt(Assertions.checkNotNull(matcher.group(1)), 16);
char unescapedCharacter = (char) Integer.parseInt(matcher.group(1), 16);
builder.append(fileName, startOfNotEscaped, matcher.start()).append(unescapedCharacter); builder.append(fileName, startOfNotEscaped, matcher.start()).append(unescapedCharacter);
startOfNotEscaped = matcher.end(); startOfNotEscaped = matcher.end();
percentCharacterCount--; percentCharacterCount--;
......
...@@ -44,8 +44,6 @@ public final class IcyDecoder implements MetadataDecoder { ...@@ -44,8 +44,6 @@ public final class IcyDecoder implements MetadataDecoder {
iso88591Decoder = Charset.forName(C.ISO88591_NAME).newDecoder(); iso88591Decoder = Charset.forName(C.ISO88591_NAME).newDecoder();
} }
// switching on a possibly-null value (key)
@SuppressWarnings("nullness:switching.nullable")
@Override @Override
public Metadata decode(MetadataInputBuffer inputBuffer) { public Metadata decode(MetadataInputBuffer inputBuffer) {
ByteBuffer buffer = Assertions.checkNotNull(inputBuffer.data); ByteBuffer buffer = Assertions.checkNotNull(inputBuffer.data);
...@@ -66,13 +64,17 @@ public final class IcyDecoder implements MetadataDecoder { ...@@ -66,13 +64,17 @@ public final class IcyDecoder implements MetadataDecoder {
while (matcher.find(index)) { while (matcher.find(index)) {
@Nullable String key = Util.toLowerInvariant(matcher.group(1)); @Nullable String key = Util.toLowerInvariant(matcher.group(1));
@Nullable String value = matcher.group(2); @Nullable String value = matcher.group(2);
switch (key) { if (key != null) {
case STREAM_KEY_NAME: switch (key) {
name = value; case STREAM_KEY_NAME:
break; name = value;
case STREAM_KEY_URL: break;
url = value; case STREAM_KEY_URL:
break; url = value;
break;
default:
break;
}
} }
index = matcher.end(); index = matcher.end();
} }
......
...@@ -227,10 +227,8 @@ import java.util.regex.Pattern; ...@@ -227,10 +227,8 @@ import java.util.regex.Pattern;
PointF position = null; PointF position = null;
Matcher matcher = BRACES_PATTERN.matcher(text); Matcher matcher = BRACES_PATTERN.matcher(text);
while (matcher.find()) { while (matcher.find()) {
String braceContents = matcher.group(1); String braceContents = Assertions.checkNotNull(matcher.group(1));
try { try {
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
PointF parsedPosition = parsePosition(braceContents); PointF parsedPosition = parsePosition(braceContents);
if (parsedPosition != null) { if (parsedPosition != null) {
position = parsedPosition; position = parsedPosition;
...@@ -239,8 +237,6 @@ import java.util.regex.Pattern; ...@@ -239,8 +237,6 @@ import java.util.regex.Pattern;
// Ignore invalid \pos() or \move() function. // Ignore invalid \pos() or \move() function.
} }
try { try {
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@SsaAlignment @SsaAlignment
int parsedAlignment = parseAlignmentOverride(braceContents); int parsedAlignment = parseAlignmentOverride(braceContents);
if (parsedAlignment != SSA_ALIGNMENT_UNKNOWN) { if (parsedAlignment != SSA_ALIGNMENT_UNKNOWN) {
...@@ -297,12 +293,12 @@ import java.util.regex.Pattern; ...@@ -297,12 +293,12 @@ import java.util.regex.Pattern;
Float.parseFloat(Assertions.checkNotNull(y).trim())); Float.parseFloat(Assertions.checkNotNull(y).trim()));
} }
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@SsaAlignment @SsaAlignment
private static int parseAlignmentOverride(String braceContents) { private static int parseAlignmentOverride(String braceContents) {
Matcher matcher = ALIGNMENT_OVERRIDE_PATTERN.matcher(braceContents); Matcher matcher = ALIGNMENT_OVERRIDE_PATTERN.matcher(braceContents);
return matcher.find() ? parseAlignment(matcher.group(1)) : SSA_ALIGNMENT_UNKNOWN; return matcher.find()
? parseAlignment(Assertions.checkNotNull(matcher.group(1)))
: SSA_ALIGNMENT_UNKNOWN;
} }
} }
} }
...@@ -22,6 +22,7 @@ import androidx.annotation.Nullable; ...@@ -22,6 +22,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.SimpleSubtitleDecoder; import com.google.android.exoplayer2.text.SimpleSubtitleDecoder;
import com.google.android.exoplayer2.text.Subtitle; import com.google.android.exoplayer2.text.Subtitle;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.LongArray; import com.google.android.exoplayer2.util.LongArray;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
...@@ -230,13 +231,12 @@ public final class SubripDecoder extends SimpleSubtitleDecoder { ...@@ -230,13 +231,12 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
Cue.DIMEN_UNSET); Cue.DIMEN_UNSET);
} }
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
private static long parseTimecode(Matcher matcher, int groupOffset) { private static long parseTimecode(Matcher matcher, int groupOffset) {
@Nullable String hours = matcher.group(groupOffset + 1); @Nullable String hours = matcher.group(groupOffset + 1);
long timestampMs = hours != null ? Long.parseLong(hours) * 60 * 60 * 1000 : 0; long timestampMs = hours != null ? Long.parseLong(hours) * 60 * 60 * 1000 : 0;
timestampMs += Long.parseLong(matcher.group(groupOffset + 2)) * 60 * 1000; timestampMs +=
timestampMs += Long.parseLong(matcher.group(groupOffset + 3)) * 1000; Long.parseLong(Assertions.checkNotNull(matcher.group(groupOffset + 2))) * 60 * 1000;
timestampMs += Long.parseLong(Assertions.checkNotNull(matcher.group(groupOffset + 3))) * 1000;
@Nullable String millis = matcher.group(groupOffset + 4); @Nullable String millis = matcher.group(groupOffset + 4);
if (millis != null) { if (millis != null) {
timestampMs += Long.parseLong(millis); timestampMs += Long.parseLong(millis);
......
...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.text.webvtt; ...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.text.webvtt;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ColorParser; import com.google.android.exoplayer2.util.ColorParser;
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;
...@@ -325,8 +326,6 @@ import java.util.regex.Pattern; ...@@ -325,8 +326,6 @@ import java.util.regex.Pattern;
* Sets the target of a {@link WebvttCssStyle} by splitting a selector of the form {@code * Sets the target of a {@link WebvttCssStyle} by splitting a selector of the form {@code
* ::cue(tag#id.class1.class2[voice="someone"]}, where every element is optional. * ::cue(tag#id.class1.class2[voice="someone"]}, where every element is optional.
*/ */
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
private void applySelectorToStyle(WebvttCssStyle style, String selector) { private void applySelectorToStyle(WebvttCssStyle style, String selector) {
if ("".equals(selector)) { if ("".equals(selector)) {
return; // Universal selector. return; // Universal selector.
...@@ -335,7 +334,7 @@ import java.util.regex.Pattern; ...@@ -335,7 +334,7 @@ import java.util.regex.Pattern;
if (voiceStartIndex != -1) { if (voiceStartIndex != -1) {
Matcher matcher = VOICE_NAME_PATTERN.matcher(selector.substring(voiceStartIndex)); Matcher matcher = VOICE_NAME_PATTERN.matcher(selector.substring(voiceStartIndex));
if (matcher.matches()) { if (matcher.matches()) {
style.setTargetVoice(matcher.group(1)); style.setTargetVoice(Assertions.checkNotNull(matcher.group(1)));
} }
selector = selector.substring(0, voiceStartIndex); selector = selector.substring(0, voiceStartIndex);
} }
......
...@@ -323,8 +323,6 @@ public final class WebvttCueParser { ...@@ -323,8 +323,6 @@ public final class WebvttCueParser {
// Internal methods // Internal methods
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@Nullable @Nullable
private static WebvttCueInfo parseCue( private static WebvttCueInfo parseCue(
@Nullable String id, @Nullable String id,
...@@ -334,14 +332,16 @@ public final class WebvttCueParser { ...@@ -334,14 +332,16 @@ public final class WebvttCueParser {
WebvttCueInfoBuilder builder = new WebvttCueInfoBuilder(); WebvttCueInfoBuilder builder = new WebvttCueInfoBuilder();
try { try {
// Parse the cue start and end times. // Parse the cue start and end times.
builder.startTimeUs = WebvttParserUtil.parseTimestampUs(cueHeaderMatcher.group(1)); builder.startTimeUs =
builder.endTimeUs = WebvttParserUtil.parseTimestampUs(cueHeaderMatcher.group(2)); WebvttParserUtil.parseTimestampUs(Assertions.checkNotNull(cueHeaderMatcher.group(1)));
builder.endTimeUs =
WebvttParserUtil.parseTimestampUs(Assertions.checkNotNull(cueHeaderMatcher.group(2)));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.w(TAG, "Skipping cue with bad header: " + cueHeaderMatcher.group()); Log.w(TAG, "Skipping cue with bad header: " + cueHeaderMatcher.group());
return null; return null;
} }
parseCueSettingsList(cueHeaderMatcher.group(3), builder); parseCueSettingsList(Assertions.checkNotNull(cueHeaderMatcher.group(3)), builder);
// Parse the cue text. // Parse the cue text.
StringBuilder textBuilder = new StringBuilder(); StringBuilder textBuilder = new StringBuilder();
...@@ -357,15 +357,13 @@ public final class WebvttCueParser { ...@@ -357,15 +357,13 @@ public final class WebvttCueParser {
return builder.build(); return builder.build();
} }
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
private static void parseCueSettingsList(String cueSettingsList, WebvttCueInfoBuilder builder) { private static void parseCueSettingsList(String cueSettingsList, WebvttCueInfoBuilder builder) {
// Parse the cue settings list. // Parse the cue settings list.
Matcher cueSettingMatcher = CUE_SETTING_PATTERN.matcher(cueSettingsList); Matcher cueSettingMatcher = CUE_SETTING_PATTERN.matcher(cueSettingsList);
while (cueSettingMatcher.find()) { while (cueSettingMatcher.find()) {
String name = cueSettingMatcher.group(1); String name = Assertions.checkNotNull(cueSettingMatcher.group(1));
String value = cueSettingMatcher.group(2); String value = Assertions.checkNotNull(cueSettingMatcher.group(2));
try { try {
if ("line".equals(name)) { if ("line".equals(name)) {
parseLineAttribute(value, builder); parseLineAttribute(value, builder);
......
...@@ -113,8 +113,6 @@ import java.util.regex.Pattern; ...@@ -113,8 +113,6 @@ import java.util.regex.Pattern;
* @return The span, or null if the file name is not correctly formatted, or if the id is not * @return The span, or null if the file name is not correctly formatted, or if the id is not
* present in the content index, or if the length is 0. * present in the content index, or if the length is 0.
*/ */
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@Nullable @Nullable
public static SimpleCacheSpan createCacheEntry( public static SimpleCacheSpan createCacheEntry(
File file, long length, long lastTouchTimestamp, CachedContentIndex index) { File file, long length, long lastTouchTimestamp, CachedContentIndex index) {
...@@ -133,9 +131,7 @@ import java.util.regex.Pattern; ...@@ -133,9 +131,7 @@ import java.util.regex.Pattern;
return null; return null;
} }
// incompatible types in argument. int id = Integer.parseInt(Assertions.checkNotNull(matcher.group(1)));
@SuppressWarnings("nullness:argument.type.incompatible")
int id = Integer.parseInt(matcher.group(1));
@Nullable String key = index.getKeyForId(id); @Nullable String key = index.getKeyForId(id);
if (key == null) { if (key == null) {
return null; return null;
...@@ -148,11 +144,9 @@ import java.util.regex.Pattern; ...@@ -148,11 +144,9 @@ import java.util.regex.Pattern;
return null; return null;
} }
// incompatible types in argument. long position = Long.parseLong(Assertions.checkNotNull(matcher.group(2)));
@SuppressWarnings("nullness:argument.type.incompatible")
long position = Long.parseLong(matcher.group(2));
if (lastTouchTimestamp == C.TIME_UNSET) { if (lastTouchTimestamp == C.TIME_UNSET) {
lastTouchTimestamp = Long.parseLong(matcher.group(3)); lastTouchTimestamp = Long.parseLong(Assertions.checkNotNull(matcher.group(3)));
} }
return new SimpleCacheSpan(key, position, length, lastTouchTimestamp, file); return new SimpleCacheSpan(key, position, length, lastTouchTimestamp, file);
} }
...@@ -165,19 +159,17 @@ import java.util.regex.Pattern; ...@@ -165,19 +159,17 @@ import java.util.regex.Pattern;
* @return Upgraded cache file or {@code null} if the file name is not correctly formatted or the * @return Upgraded cache file or {@code null} if the file name is not correctly formatted or the
* file can not be renamed. * file can not be renamed.
*/ */
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@Nullable @Nullable
private static File upgradeFile(File file, CachedContentIndex index) { private static File upgradeFile(File file, CachedContentIndex index) {
@Nullable String key = null; @Nullable String key = null;
String filename = file.getName(); String filename = file.getName();
Matcher matcher = CACHE_FILE_PATTERN_V2.matcher(filename); Matcher matcher = CACHE_FILE_PATTERN_V2.matcher(filename);
if (matcher.matches()) { if (matcher.matches()) {
key = Util.unescapeFileName(matcher.group(1)); key = Util.unescapeFileName(Assertions.checkNotNull(matcher.group(1)));
} else { } else {
matcher = CACHE_FILE_PATTERN_V1.matcher(filename); matcher = CACHE_FILE_PATTERN_V1.matcher(filename);
if (matcher.matches()) { if (matcher.matches()) {
key = matcher.group(1); // Keys were not escaped in version 1. key = Assertions.checkNotNull(matcher.group(1)); // Keys were not escaped in version 1.
} }
} }
...@@ -185,14 +177,12 @@ import java.util.regex.Pattern; ...@@ -185,14 +177,12 @@ import java.util.regex.Pattern;
return null; return null;
} }
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
File newCacheFile = File newCacheFile =
getCacheFile( getCacheFile(
Assertions.checkStateNotNull(file.getParentFile()), Assertions.checkStateNotNull(file.getParentFile()),
index.assignIdForKey(key), index.assignIdForKey(key),
Long.parseLong(matcher.group(2)), Long.parseLong(Assertions.checkNotNull(matcher.group(2))),
Long.parseLong(matcher.group(3))); Long.parseLong(Assertions.checkNotNull(matcher.group(3))));
if (!file.renameTo(newCacheFile)) { if (!file.renameTo(newCacheFile)) {
return null; return null;
} }
......
...@@ -63,8 +63,6 @@ public final class ColorParser { ...@@ -63,8 +63,6 @@ public final class ColorParser {
return parseColorInternal(colorExpression, true); return parseColorInternal(colorExpression, true);
} }
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
private static int parseColorInternal(String colorExpression, boolean alphaHasFloatFormat) { private static int parseColorInternal(String colorExpression, boolean alphaHasFloatFormat) {
Assertions.checkArgument(!TextUtils.isEmpty(colorExpression)); Assertions.checkArgument(!TextUtils.isEmpty(colorExpression));
colorExpression = colorExpression.replace(" ", ""); colorExpression = colorExpression.replace(" ", "");
...@@ -86,21 +84,20 @@ public final class ColorParser { ...@@ -86,21 +84,20 @@ public final class ColorParser {
.matcher(colorExpression); .matcher(colorExpression);
if (matcher.matches()) { if (matcher.matches()) {
return argb( return argb(
alphaHasFloatFormat ? (int) (255 * Float.parseFloat(matcher.group(4))) alphaHasFloatFormat
: Integer.parseInt(matcher.group(4), 10), ? (int) (255 * Float.parseFloat(Assertions.checkNotNull(matcher.group(4))))
Integer.parseInt(matcher.group(1), 10), : Integer.parseInt(Assertions.checkNotNull(matcher.group(4)), 10),
Integer.parseInt(matcher.group(2), 10), Integer.parseInt(Assertions.checkNotNull(matcher.group(1)), 10),
Integer.parseInt(matcher.group(3), 10) Integer.parseInt(Assertions.checkNotNull(matcher.group(2)), 10),
); Integer.parseInt(Assertions.checkNotNull(matcher.group(3)), 10));
} }
} else if (colorExpression.startsWith(RGB)) { } else if (colorExpression.startsWith(RGB)) {
Matcher matcher = RGB_PATTERN.matcher(colorExpression); Matcher matcher = RGB_PATTERN.matcher(colorExpression);
if (matcher.matches()) { if (matcher.matches()) {
return rgb( return rgb(
Integer.parseInt(matcher.group(1), 10), Integer.parseInt(Assertions.checkNotNull(matcher.group(1)), 10),
Integer.parseInt(matcher.group(2), 10), Integer.parseInt(Assertions.checkNotNull(matcher.group(2)), 10),
Integer.parseInt(matcher.group(3), 10) Integer.parseInt(Assertions.checkNotNull(matcher.group(3)), 10));
);
} }
} else { } else {
// we use our own color map // we use our own color map
......
...@@ -133,8 +133,6 @@ public final class WebvttExtractor implements Extractor { ...@@ -133,8 +133,6 @@ public final class WebvttExtractor implements Extractor {
return Extractor.RESULT_END_OF_INPUT; return Extractor.RESULT_END_OF_INPUT;
} }
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@RequiresNonNull("output") @RequiresNonNull("output")
private void processSample() throws ParserException { private void processSample() throws ParserException {
ParsableByteArray webvttData = new ParsableByteArray(sampleData); ParsableByteArray webvttData = new ParsableByteArray(sampleData);
...@@ -159,8 +157,12 @@ public final class WebvttExtractor implements Extractor { ...@@ -159,8 +157,12 @@ public final class WebvttExtractor implements Extractor {
if (!mediaTimestampMatcher.find()) { if (!mediaTimestampMatcher.find()) {
throw new ParserException("X-TIMESTAMP-MAP doesn't contain media timestamp: " + line); throw new ParserException("X-TIMESTAMP-MAP doesn't contain media timestamp: " + line);
} }
vttTimestampUs = WebvttParserUtil.parseTimestampUs(localTimestampMatcher.group(1)); vttTimestampUs =
tsTimestampUs = TimestampAdjuster.ptsToUs(Long.parseLong(mediaTimestampMatcher.group(1))); WebvttParserUtil.parseTimestampUs(
Assertions.checkNotNull(localTimestampMatcher.group(1)));
tsTimestampUs =
TimestampAdjuster.ptsToUs(
Long.parseLong(Assertions.checkNotNull(mediaTimestampMatcher.group(1))));
} }
} }
...@@ -172,9 +174,8 @@ public final class WebvttExtractor implements Extractor { ...@@ -172,9 +174,8 @@ public final class WebvttExtractor implements Extractor {
return; return;
} }
// incompatible types in argument. long firstCueTimeUs =
@SuppressWarnings("nullness:argument.type.incompatible") WebvttParserUtil.parseTimestampUs(Assertions.checkNotNull(cueHeaderMatcher.group(1)));
long firstCueTimeUs = WebvttParserUtil.parseTimestampUs(cueHeaderMatcher.group(1));
long sampleTimeUs = timestampAdjuster.adjustTsTimestamp( long sampleTimeUs = timestampAdjuster.adjustTsTimestamp(
TimestampAdjuster.usToPts(firstCueTimeUs + tsTimestampUs - vttTimestampUs)); TimestampAdjuster.usToPts(firstCueTimeUs + tsTimestampUs - vttTimestampUs));
long subsampleOffsetUs = sampleTimeUs - firstCueTimeUs; long subsampleOffsetUs = sampleTimeUs - firstCueTimeUs;
......
...@@ -845,12 +845,10 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli ...@@ -845,12 +845,10 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
return Integer.parseInt(parseStringAttr(line, pattern, Collections.emptyMap())); return Integer.parseInt(parseStringAttr(line, pattern, Collections.emptyMap()));
} }
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
private static int parseOptionalIntAttr(String line, Pattern pattern, int defaultValue) { private static int parseOptionalIntAttr(String line, Pattern pattern, int defaultValue) {
Matcher matcher = pattern.matcher(line); Matcher matcher = pattern.matcher(line);
if (matcher.find()) { if (matcher.find()) {
return Integer.parseInt(matcher.group(1)); return Integer.parseInt(Assertions.checkNotNull(matcher.group(1)));
} }
return defaultValue; return defaultValue;
} }
...@@ -879,15 +877,14 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli ...@@ -879,15 +877,14 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
return parseOptionalStringAttr(line, pattern, null, variableDefinitions); return parseOptionalStringAttr(line, pattern, null, variableDefinitions);
} }
// incompatible types in return.
@SuppressWarnings("nullness:return.type.incompatible")
private static @PolyNull String parseOptionalStringAttr( private static @PolyNull String parseOptionalStringAttr(
String line, String line,
Pattern pattern, Pattern pattern,
@PolyNull String defaultValue, @PolyNull String defaultValue,
Map<String, String> variableDefinitions) { Map<String, String> variableDefinitions) {
Matcher matcher = pattern.matcher(line); Matcher matcher = pattern.matcher(line);
String value = matcher.find() ? matcher.group(1) : defaultValue; @PolyNull
String value = matcher.find() ? Assertions.checkNotNull(matcher.group(1)) : defaultValue;
return variableDefinitions.isEmpty() || value == null return variableDefinitions.isEmpty() || value == null
? value ? value
: replaceVariableReferences(value, variableDefinitions); : replaceVariableReferences(value, variableDefinitions);
...@@ -911,13 +908,11 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli ...@@ -911,13 +908,11 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
return stringWithReplacements.toString(); return stringWithReplacements.toString();
} }
// dereference of possibly-null reference matcher.group(1)
@SuppressWarnings("nullness:dereference.of.nullable")
private static boolean parseOptionalBooleanAttribute( private static boolean parseOptionalBooleanAttribute(
String line, Pattern pattern, boolean defaultValue) { String line, Pattern pattern, boolean defaultValue) {
Matcher matcher = pattern.matcher(line); Matcher matcher = pattern.matcher(line);
if (matcher.find()) { if (matcher.find()) {
return matcher.group(1).equals(BOOLEAN_TRUE); return BOOLEAN_TRUE.equals(matcher.group(1));
} }
return defaultValue; return defaultValue;
} }
......
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