Suppress go/nullness warnings caused by Matcher#group(String) and Matcher#group(int)

This is required to align google3's stub (currently marked non-null) with Checker Framework's.

More information: go/matcher-nullness-lsc

Tested:
    TAP train for global presubmit queue
    http://test/OCL:303344687:BASE:303326748:1585344475427:29edc250
PiperOrigin-RevId: 303709053
This commit is contained in:
ibaker 2020-03-30 12:00:35 +01:00 committed by Oliver Woodman
parent fd03949f85
commit c7164a30a0
11 changed files with 51 additions and 5 deletions

View File

@ -818,6 +818,8 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
Matcher matcher = CONTENT_RANGE_HEADER_PATTERN.matcher(contentRangeHeader);
if (matcher.find()) {
try {
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
long contentLengthFromRange =
Long.parseLong(matcher.group(2)) - Long.parseLong(matcher.group(1)) + 1;
if (contentLength < 0) {

View File

@ -1021,13 +1021,16 @@ public final class Util {
}
/**
* Parses an xs:dateTime attribute value, returning the parsed timestamp in milliseconds since
* the epoch.
* Parses an xs:dateTime attribute value, returning the parsed timestamp in milliseconds since the
* epoch.
*
* @param value The attribute value to decode.
* @return The parsed timestamp in milliseconds since the epoch.
* @throws ParserException if an error occurs parsing the dateTime attribute value.
*/
// incompatible types in argument.
// dereference of possibly-null reference matcher.group(9)
@SuppressWarnings({"nullness:argument.type.incompatible", "nullness:dereference.of.nullable"})
public static long parseXsDateTime(String value) throws ParserException {
Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value);
if (!matcher.matches()) {
@ -1719,6 +1722,8 @@ public final class Util {
Matcher matcher = ESCAPED_CHARACTER_PATTERN.matcher(fileName);
int startOfNotEscaped = 0;
while (percentCharacterCount > 0 && matcher.find()) {
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
char unescapedCharacter = (char) Integer.parseInt(matcher.group(1), 16);
builder.append(fileName, startOfNotEscaped, matcher.start()).append(unescapedCharacter);
startOfNotEscaped = matcher.end();

View File

@ -44,6 +44,8 @@ public final class IcyDecoder implements MetadataDecoder {
iso88591Decoder = Charset.forName(C.ISO88591_NAME).newDecoder();
}
// switching on a possibly-null value (key)
@SuppressWarnings("nullness:switching.nullable")
@Override
public Metadata decode(MetadataInputBuffer inputBuffer) {
ByteBuffer buffer = Assertions.checkNotNull(inputBuffer.data);

View File

@ -229,6 +229,8 @@ import java.util.regex.Pattern;
while (matcher.find()) {
String braceContents = matcher.group(1);
try {
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
PointF parsedPosition = parsePosition(braceContents);
if (parsedPosition != null) {
position = parsedPosition;
@ -237,7 +239,10 @@ import java.util.regex.Pattern;
// Ignore invalid \pos() or \move() function.
}
try {
@SsaAlignment int parsedAlignment = parseAlignmentOverride(braceContents);
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@SsaAlignment
int parsedAlignment = parseAlignmentOverride(braceContents);
if (parsedAlignment != SSA_ALIGNMENT_UNKNOWN) {
alignment = parsedAlignment;
}
@ -292,6 +297,8 @@ import java.util.regex.Pattern;
Float.parseFloat(Assertions.checkNotNull(y).trim()));
}
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@SsaAlignment
private static int parseAlignmentOverride(String braceContents) {
Matcher matcher = ALIGNMENT_OVERRIDE_PATTERN.matcher(braceContents);

View File

@ -230,6 +230,8 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
Cue.DIMEN_UNSET);
}
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
private static long parseTimecode(Matcher matcher, int groupOffset) {
@Nullable String hours = matcher.group(groupOffset + 1);
long timestampMs = hours != null ? Long.parseLong(hours) * 60 * 60 * 1000 : 0;

View File

@ -322,9 +322,11 @@ import java.util.regex.Pattern;
}
/**
* 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.
* 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.
*/
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
private void applySelectorToStyle(WebvttCssStyle style, String selector) {
if ("".equals(selector)) {
return; // Universal selector.

View File

@ -322,6 +322,8 @@ public final class WebvttCueParser {
// Internal methods
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@Nullable
private static WebvttCueInfo parseCue(
@Nullable String id,
@ -354,6 +356,8 @@ public final class WebvttCueParser {
return builder.build();
}
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
private static void parseCueSettingsList(String cueSettingsList, WebvttCueInfoBuilder builder) {
// Parse the cue settings list.
Matcher cueSettingMatcher = CUE_SETTING_PATTERN.matcher(cueSettingsList);

View File

@ -113,6 +113,8 @@ import java.util.regex.Pattern;
* @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.
*/
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@Nullable
public static SimpleCacheSpan createCacheEntry(
File file, long length, long lastTouchTimestamp, CachedContentIndex index) {
@ -131,6 +133,8 @@ import java.util.regex.Pattern;
return null;
}
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
int id = Integer.parseInt(matcher.group(1));
@Nullable String key = index.getKeyForId(id);
if (key == null) {
@ -144,6 +148,8 @@ import java.util.regex.Pattern;
return null;
}
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
long position = Long.parseLong(matcher.group(2));
if (lastTouchTimestamp == C.TIME_UNSET) {
lastTouchTimestamp = Long.parseLong(matcher.group(3));
@ -159,6 +165,8 @@ import java.util.regex.Pattern;
* @return Upgraded cache file or {@code null} if the file name is not correctly formatted or the
* file can not be renamed.
*/
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@Nullable
private static File upgradeFile(File file, CachedContentIndex index) {
@Nullable String key = null;
@ -177,6 +185,8 @@ import java.util.regex.Pattern;
return null;
}
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
File newCacheFile =
getCacheFile(
Assertions.checkStateNotNull(file.getParentFile()),

View File

@ -63,6 +63,8 @@ public final class ColorParser {
return parseColorInternal(colorExpression, true);
}
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
private static int parseColorInternal(String colorExpression, boolean alphaHasFloatFormat) {
Assertions.checkArgument(!TextUtils.isEmpty(colorExpression));
colorExpression = colorExpression.replace(" ", "");

View File

@ -133,6 +133,8 @@ public final class WebvttExtractor implements Extractor {
return Extractor.RESULT_END_OF_INPUT;
}
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
@RequiresNonNull("output")
private void processSample() throws ParserException {
ParsableByteArray webvttData = new ParsableByteArray(sampleData);
@ -170,6 +172,8 @@ public final class WebvttExtractor implements Extractor {
return;
}
// incompatible types in argument.
@SuppressWarnings("nullness:argument.type.incompatible")
long firstCueTimeUs = WebvttParserUtil.parseTimestampUs(cueHeaderMatcher.group(1));
long sampleTimeUs = timestampAdjuster.adjustTsTimestamp(
TimestampAdjuster.usToPts(firstCueTimeUs + tsTimestampUs - vttTimestampUs));

View File

@ -823,6 +823,8 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
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) {
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
@ -855,6 +857,8 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
return parseOptionalStringAttr(line, pattern, null, variableDefinitions);
}
// incompatible types in return.
@SuppressWarnings("nullness:return.type.incompatible")
private static @PolyNull String parseOptionalStringAttr(
String line,
Pattern pattern,
@ -885,6 +889,8 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
return stringWithReplacements.toString();
}
// dereference of possibly-null reference matcher.group(1)
@SuppressWarnings("nullness:dereference.of.nullable")
private static boolean parseOptionalBooleanAttribute(
String line, Pattern pattern, boolean defaultValue) {
Matcher matcher = pattern.matcher(line);