Fix some analysis warnings.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=139901449
This commit is contained in:
andrewlewis 2016-11-22 06:30:14 -08:00 committed by Oliver Woodman
parent e84fa5835d
commit 77715fbfbe
15 changed files with 94 additions and 96 deletions

View file

@ -48,5 +48,5 @@ dependencies {
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile project(':library')
androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:runner:0.5'
}

View file

@ -57,7 +57,7 @@ dependencies {
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
compile 'com.android.support:support-annotations:24.2.1'
compile 'com.android.support:support-annotations:25.0.1'
}
android.libraryVariants.all { variant ->

View file

@ -110,8 +110,8 @@ public final class DefaultOggSeekerTest extends TestCase {
long granuleDiff = currentGranule - targetGranule;
if ((granuleDiff > DefaultOggSeeker.MATCH_RANGE || granuleDiff < 0)
&& positionDiff > DefaultOggSeeker.MATCH_BYTE_RANGE) {
fail(String.format("granuleDiff (%d) or positionDiff (%d) is more than allowed.",
granuleDiff, positionDiff));
fail("granuleDiff (" + granuleDiff + ") or positionDiff (" + positionDiff
+ ") is more than allowed.");
}
}
}

View file

@ -28,7 +28,7 @@ import junit.framework.TestCase;
*/
public class DefaultOggSeekerUtilMethodsTest extends TestCase {
private Random random = new Random(0);
private final Random random = new Random(0);
public void testSkipToNextPage() throws Exception {
FakeExtractorInput extractorInput = TestData.createInput(

View file

@ -25,16 +25,16 @@ import junit.framework.Assert;
*/
/* package */ final class OggTestFile {
public static final int MAX_PACKET_LENGTH = 2048;
public static final int MAX_SEGMENT_COUNT = 10;
public static final int MAX_GRANULES_IN_PAGE = 100000;
private static final int MAX_PACKET_LENGTH = 2048;
private static final int MAX_SEGMENT_COUNT = 10;
private static final int MAX_GRANULES_IN_PAGE = 100000;
byte[] data;
long lastGranule;
int packetCount;
int pageCount;
int firstPayloadPageSize;
long firstPayloadPageGranulePosition;
public final byte[] data;
public final long lastGranule;
public final int packetCount;
public final int pageCount;
public final int firstPayloadPageSize;
public final long firstPayloadPageGranulePosition;
private OggTestFile(byte[] data, long lastGranule, int packetCount, int pageCount,
int firstPayloadPageSize, long firstPayloadPageGranulePosition) {

View file

@ -31,7 +31,6 @@ import com.google.android.exoplayer2.testutil.FakeTrackOutput;
import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.util.ParsableByteArray;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Random;
/**
@ -114,7 +113,7 @@ public final class TsExtractorTest extends InstrumentationTestCase {
assertEquals(1, factory.sdtReader.consumedSdts);
}
private static void writeJunkData(ByteArrayOutputStream out, int length) throws IOException {
private static void writeJunkData(ByteArrayOutputStream out, int length) {
for (int i = 0; i < length; i++) {
if (((byte) i) == TS_SYNC_BYTE) {
out.write(0);

View file

@ -97,7 +97,7 @@ public final class Mp4WebvttDecoderTest extends TestCase {
public void testNoCueSample() throws SubtitleDecoderException {
Mp4WebvttDecoder decoder = new Mp4WebvttDecoder();
Subtitle result = decoder.decode(NO_CUE_SAMPLE, NO_CUE_SAMPLE.length);
assertMp4WebvttSubtitleEquals(result, new Cue[0]);
assertMp4WebvttSubtitleEquals(result);
}
// Negative tests.

View file

@ -28,7 +28,7 @@ public class CachedContentIndexTest extends InstrumentationTestCase {
0, 0, 0, 0, 0, 0, 0, 10, // original_content_length
0, 0, 0, 2, // cache_id
0, 5, 75, 76, 77, 78, 79, // cache_key
0, 0, 0, 0, 0, 0, 10, 00, // original_content_length
0, 0, 0, 0, 0, 0, 10, 0, // original_content_length
(byte) 0xF6, (byte) 0xFB, 0x50, 0x41 // hashcode_of_CachedContent_array
};
private CachedContentIndex index;

View file

@ -69,10 +69,12 @@ public class AtomicFileTest extends InstrumentationTestCase {
output.write(6);
assertRead();
output.close();
output = atomicFile.startWrite();
assertRead();
output.close();
}
private void assertRead() throws IOException {

View file

@ -447,15 +447,15 @@ public class StreamingDrmSessionManager<T extends ExoMediaCrypto> implements Drm
switch (msg.what) {
case MediaDrm.EVENT_KEY_REQUIRED:
postKeyRequest();
return;
break;
case MediaDrm.EVENT_KEY_EXPIRED:
state = STATE_OPENED;
onError(new KeysExpiredException());
return;
break;
case MediaDrm.EVENT_PROVISION_REQUIRED:
state = STATE_OPENED;
postProvisionRequest();
return;
break;
}
}
@ -483,10 +483,10 @@ public class StreamingDrmSessionManager<T extends ExoMediaCrypto> implements Drm
switch (msg.what) {
case MSG_PROVISION:
onProvisionResponse(msg.obj);
return;
break;
case MSG_KEYS:
onKeyResponse(msg.obj);
return;
break;
}
}

View file

@ -431,18 +431,18 @@ public final class MatroskaExtractor implements Extractor {
}
segmentContentPosition = contentPosition;
segmentContentSize = contentSize;
return;
break;
case ID_SEEK:
seekEntryId = UNSET_ENTRY_ID;
seekEntryPosition = C.POSITION_UNSET;
return;
break;
case ID_CUES:
cueTimesUs = new LongArray();
cueClusterPositions = new LongArray();
return;
break;
case ID_CUE_POINT:
seenClusterPositionForCurrentCuePoint = false;
return;
break;
case ID_CLUSTER:
if (!sentSeekMap) {
// We need to build cues before parsing the cluster.
@ -456,21 +456,21 @@ public final class MatroskaExtractor implements Extractor {
sentSeekMap = true;
}
}
return;
break;
case ID_BLOCK_GROUP:
sampleSeenReferenceBlock = false;
return;
break;
case ID_CONTENT_ENCODING:
// TODO: check and fail if more than one content encoding is present.
return;
break;
case ID_CONTENT_ENCRYPTION:
currentTrack.hasContentEncryption = true;
return;
break;
case ID_TRACK_ENTRY:
currentTrack = new Track();
return;
break;
default:
return;
break;
}
}
@ -484,7 +484,7 @@ public final class MatroskaExtractor implements Extractor {
if (durationTimecode != C.TIME_UNSET) {
durationUs = scaleTimecodeToUs(durationTimecode);
}
return;
break;
case ID_SEEK:
if (seekEntryId == UNSET_ENTRY_ID || seekEntryPosition == C.POSITION_UNSET) {
throw new ParserException("Mandatory element SeekID or SeekPosition not found");
@ -492,7 +492,7 @@ public final class MatroskaExtractor implements Extractor {
if (seekEntryId == ID_CUES) {
cuesContentPosition = seekEntryPosition;
}
return;
break;
case ID_CUES:
if (!sentSeekMap) {
extractorOutput.seekMap(buildSeekMap());
@ -500,7 +500,7 @@ public final class MatroskaExtractor implements Extractor {
} else {
// We have already built the cues. Ignore.
}
return;
break;
case ID_BLOCK_GROUP:
if (blockState != BLOCK_STATE_DATA) {
// We've skipped this block (due to incompatible track number).
@ -512,7 +512,7 @@ public final class MatroskaExtractor implements Extractor {
}
commitSampleToOutput(tracks.get(blockTrackNumber), blockTimeUs);
blockState = BLOCK_STATE_START;
return;
break;
case ID_CONTENT_ENCODING:
if (currentTrack.hasContentEncryption) {
if (currentTrack.encryptionKeyId == null) {
@ -521,12 +521,12 @@ public final class MatroskaExtractor implements Extractor {
currentTrack.drmInitData = new DrmInitData(
new SchemeData(C.UUID_NIL, MimeTypes.VIDEO_WEBM, currentTrack.encryptionKeyId));
}
return;
break;
case ID_CONTENT_ENCODINGS:
if (currentTrack.hasContentEncryption && currentTrack.sampleStrippedBytes != null) {
throw new ParserException("Combining encryption and compression is not supported");
}
return;
break;
case ID_TRACK_ENTRY:
if (tracks.get(currentTrack.number) == null && isCodecSupported(currentTrack.codecId)) {
currentTrack.initializeOutput(extractorOutput, currentTrack.number);
@ -535,15 +535,15 @@ public final class MatroskaExtractor implements Extractor {
// We've seen this track entry before, or the codec is unsupported. Do nothing.
}
currentTrack = null;
return;
break;
case ID_TRACKS:
if (tracks.size() == 0) {
throw new ParserException("No valid tracks were found");
}
extractorOutput.endTracks();
return;
break;
default:
return;
break;
}
}
@ -554,99 +554,99 @@ public final class MatroskaExtractor implements Extractor {
if (value != 1) {
throw new ParserException("EBMLReadVersion " + value + " not supported");
}
return;
break;
case ID_DOC_TYPE_READ_VERSION:
// Validate that DocTypeReadVersion is supported. This extractor only supports up to v2.
if (value < 1 || value > 2) {
throw new ParserException("DocTypeReadVersion " + value + " not supported");
}
return;
break;
case ID_SEEK_POSITION:
// Seek Position is the relative offset beginning from the Segment. So to get absolute
// offset from the beginning of the file, we need to add segmentContentPosition to it.
seekEntryPosition = value + segmentContentPosition;
return;
break;
case ID_TIMECODE_SCALE:
timecodeScale = value;
return;
break;
case ID_PIXEL_WIDTH:
currentTrack.width = (int) value;
return;
break;
case ID_PIXEL_HEIGHT:
currentTrack.height = (int) value;
return;
break;
case ID_DISPLAY_WIDTH:
currentTrack.displayWidth = (int) value;
return;
break;
case ID_DISPLAY_HEIGHT:
currentTrack.displayHeight = (int) value;
return;
break;
case ID_DISPLAY_UNIT:
currentTrack.displayUnit = (int) value;
return;
break;
case ID_TRACK_NUMBER:
currentTrack.number = (int) value;
return;
break;
case ID_FLAG_DEFAULT:
currentTrack.flagForced = value == 1;
return;
break;
case ID_FLAG_FORCED:
currentTrack.flagDefault = value == 1;
return;
break;
case ID_TRACK_TYPE:
currentTrack.type = (int) value;
return;
break;
case ID_DEFAULT_DURATION:
currentTrack.defaultSampleDurationNs = (int) value;
return;
break;
case ID_CODEC_DELAY:
currentTrack.codecDelayNs = value;
return;
break;
case ID_SEEK_PRE_ROLL:
currentTrack.seekPreRollNs = value;
return;
break;
case ID_CHANNELS:
currentTrack.channelCount = (int) value;
return;
break;
case ID_AUDIO_BIT_DEPTH:
currentTrack.audioBitDepth = (int) value;
return;
break;
case ID_REFERENCE_BLOCK:
sampleSeenReferenceBlock = true;
return;
break;
case ID_CONTENT_ENCODING_ORDER:
// This extractor only supports one ContentEncoding element and hence the order has to be 0.
if (value != 0) {
throw new ParserException("ContentEncodingOrder " + value + " not supported");
}
return;
break;
case ID_CONTENT_ENCODING_SCOPE:
// This extractor only supports the scope of all frames.
if (value != 1) {
throw new ParserException("ContentEncodingScope " + value + " not supported");
}
return;
break;
case ID_CONTENT_COMPRESSION_ALGORITHM:
// This extractor only supports header stripping.
if (value != 3) {
throw new ParserException("ContentCompAlgo " + value + " not supported");
}
return;
break;
case ID_CONTENT_ENCRYPTION_ALGORITHM:
// Only the value 5 (AES) is allowed according to the WebM specification.
if (value != 5) {
throw new ParserException("ContentEncAlgo " + value + " not supported");
}
return;
break;
case ID_CONTENT_ENCRYPTION_AES_SETTINGS_CIPHER_MODE:
// Only the value 1 is allowed according to the WebM specification.
if (value != 1) {
throw new ParserException("AESSettingsCipherMode " + value + " not supported");
}
return;
break;
case ID_CUE_TIME:
cueTimesUs.add(scaleTimecodeToUs(value));
return;
break;
case ID_CUE_CLUSTER_POSITION:
if (!seenClusterPositionForCurrentCuePoint) {
// If there's more than one video/audio track, then there could be more than one
@ -655,13 +655,13 @@ public final class MatroskaExtractor implements Extractor {
cueClusterPositions.add(value);
seenClusterPositionForCurrentCuePoint = true;
}
return;
break;
case ID_TIME_CODE:
clusterTimecodeUs = scaleTimecodeToUs(value);
return;
break;
case ID_BLOCK_DURATION:
blockDurationUs = scaleTimecodeToUs(value);
return;
break;
case ID_STEREO_MODE:
int layout = (int) value;
switch (layout) {
@ -677,9 +677,9 @@ public final class MatroskaExtractor implements Extractor {
default:
break;
}
return;
break;
default:
return;
break;
}
}
@ -687,12 +687,12 @@ public final class MatroskaExtractor implements Extractor {
switch (id) {
case ID_DURATION:
durationTimecode = (long) value;
return;
break;
case ID_SAMPLING_FREQUENCY:
currentTrack.sampleRate = (int) value;
return;
break;
default:
return;
break;
}
}
@ -703,15 +703,15 @@ public final class MatroskaExtractor implements Extractor {
if (!DOC_TYPE_WEBM.equals(value) && !DOC_TYPE_MATROSKA.equals(value)) {
throw new ParserException("DocType " + value + " not supported");
}
return;
break;
case ID_CODEC_ID:
currentTrack.codecId = value;
return;
break;
case ID_LANGUAGE:
currentTrack.language = value;
return;
break;
default:
return;
break;
}
}
@ -723,24 +723,24 @@ public final class MatroskaExtractor implements Extractor {
input.readFully(seekEntryIdBytes.data, 4 - contentSize, contentSize);
seekEntryIdBytes.setPosition(0);
seekEntryId = (int) seekEntryIdBytes.readUnsignedInt();
return;
break;
case ID_CODEC_PRIVATE:
currentTrack.codecPrivate = new byte[contentSize];
input.readFully(currentTrack.codecPrivate, 0, contentSize);
return;
break;
case ID_PROJECTION_PRIVATE:
currentTrack.projectionData = new byte[contentSize];
input.readFully(currentTrack.projectionData, 0, contentSize);
return;
break;
case ID_CONTENT_COMPRESSION_SETTINGS:
// This extractor only supports header stripping, so the payload is the stripped bytes.
currentTrack.sampleStrippedBytes = new byte[contentSize];
input.readFully(currentTrack.sampleStrippedBytes, 0, contentSize);
return;
break;
case ID_CONTENT_ENCRYPTION_KEY_ID:
currentTrack.encryptionKeyId = new byte[contentSize];
input.readFully(currentTrack.encryptionKeyId, 0, contentSize);
return;
break;
case ID_SIMPLE_BLOCK:
case ID_BLOCK:
// Please refer to http://www.matroska.org/technical/specs/index.html#simpleblock_structure
@ -873,7 +873,7 @@ public final class MatroskaExtractor implements Extractor {
writeSampleData(input, track, blockLacingSampleSizes[0]);
}
return;
break;
default:
throw new ParserException("Unexpected id: " + id);
}

View file

@ -369,22 +369,22 @@ public final class Cea608Decoder extends CeaDecoder {
if (captionMode == CC_MODE_ROLL_UP || captionMode == CC_MODE_PAINT_ON) {
captionStringBuilder.setLength(0);
}
return;
break;
case CTRL_ERASE_NON_DISPLAYED_MEMORY:
captionStringBuilder.setLength(0);
return;
break;
case CTRL_END_OF_CAPTION:
captionString = getDisplayCaption();
captionStringBuilder.setLength(0);
return;
break;
case CTRL_CARRIAGE_RETURN:
maybeAppendNewline();
return;
break;
case CTRL_BACKSPACE:
if (captionStringBuilder.length() > 0) {
captionStringBuilder.setLength(captionStringBuilder.length() - 1);
}
return;
break;
}
}

View file

@ -113,8 +113,8 @@ public final class ParsingLoadable<T> implements Loadable {
inputStream.open();
result = parser.parse(dataSource.getUri(), inputStream);
} finally {
inputStream.close();
bytesLoaded = inputStream.bytesRead();
inputStream.close();
}
}

View file

@ -354,10 +354,7 @@ public final class SimpleCache implements Cache {
@Override
public synchronized boolean isCached(String key, long position, long length) {
CachedContent cachedContent = index.get(key);
if (cachedContent == null) {
return false;
}
return cachedContent.isCached(position, length);
return cachedContent != null && cachedContent.isCached(position, length);
}
@Override

View file

@ -98,7 +98,7 @@ public final class AtomicFile {
baseName.delete();
}
}
OutputStream str = null;
OutputStream str;
try {
str = new AtomicFileOutputStream(baseName);
} catch (FileNotFoundException e) {