Skip to content

Commit

Permalink
Fix various issues detected by errorprone.
Browse files Browse the repository at this point in the history
  • Loading branch information
bramp committed Mar 11, 2024
1 parent 235084b commit a9901ab
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 45 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/bramp/ffmpeg/FFmpegUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static net.bramp.ffmpeg.Preconditions.checkNotEmpty;

import com.google.common.base.CharMatcher;
import com.google.errorprone.annotations.InlineMe;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -36,6 +37,10 @@ public final class FFmpegUtils {
* @deprecated please use #toTimecode() instead.
*/
@Deprecated
@InlineMe(
replacement = "FFmpegUtils.toTimecode(milliseconds, MILLISECONDS)",
imports = "net.bramp.ffmpeg.FFmpegUtils",
staticImports = "java.util.concurrent.TimeUnit.MILLISECONDS")
public static String millisecondsToString(long milliseconds) {
return toTimecode(milliseconds, MILLISECONDS);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/bramp/ffmpeg/Preconditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Ascii;
import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -41,7 +42,7 @@ public static String checkNotEmpty(String arg, @Nullable Object errorMessage) {
*/
public static URI checkValidStream(URI uri) throws IllegalArgumentException {
String scheme = checkNotNull(uri).getScheme();
scheme = checkNotNull(scheme, "URI is missing a scheme").toLowerCase();
scheme = Ascii.toLowerCase(checkNotNull(scheme, "URI is missing a scheme"));

if (rtps.contains(scheme)) {
return uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ protected List<String> build(FFmpegBuilder parent, int pass) {
} else if (uri != null) {
args.add(uri.toString());
} else {
assert (false);
assert false;
}

return args.build();
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/net/bramp/ffmpeg/builder/FFmpegBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static net.bramp.ffmpeg.Preconditions.checkNotEmpty;

import com.google.common.base.Ascii;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -32,10 +33,10 @@ public enum Strict {
UNOFFICIAL, // allow unofficial extensions
EXPERIMENTAL;

// ffmpeg command line requires these options in lower case
@Override
public String toString() {
return name().toLowerCase();
// ffmpeg command line requires these options in lower case
return Ascii.toLowerCase(name());
}
}

Expand All @@ -52,7 +53,8 @@ public enum Verbosity {

@Override
public String toString() {
return name().toLowerCase();
// ffmpeg command line requires these options in lower case
return Ascii.toLowerCase(name());
}
}

Expand Down Expand Up @@ -179,8 +181,8 @@ public FFmpegBuilder addProgress(URI uri) {
/**
* Sets the complex filter flag.
*
* @param filter
* @return
* @param filter the complex filter string
* @return this
*/
public FFmpegBuilder setComplexFilter(String filter) {
this.complexFilter = checkNotEmpty(filter, "filter must not be empty");
Expand All @@ -190,8 +192,8 @@ public FFmpegBuilder setComplexFilter(String filter) {
/**
* Sets the audio filter flag.
*
* @param filter
* @return
* @param filter the audio filter string
* @return this
*/
public FFmpegBuilder setAudioFilter(String filter) {
this.audioFilter = checkNotEmpty(filter, "filter must not be empty");
Expand All @@ -201,8 +203,8 @@ public FFmpegBuilder setAudioFilter(String filter) {
/**
* Sets the video filter flag.
*
* @param filter
* @return
* @param filter the video filter string
* @return this
*/
public FFmpegBuilder setVideoFilter(String filter) {
this.videoFilter = checkNotEmpty(filter, "filter must not be empty");
Expand All @@ -211,6 +213,7 @@ public FFmpegBuilder setVideoFilter(String filter) {

/**
* Sets vbr quality when decoding mp3 output.
*
* @param quality the quality between 0 and 9. Where 0 is best.
* @return FFmpegBuilder
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.InlineMe;

import java.net.URI;
import java.util.List;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -113,7 +115,8 @@ public FFmpegOutputBuilder setVideoFilter(String filter) {
* @deprecated use {@link #setAudioSampleFormat} instead.
*/
@Deprecated
public FFmpegOutputBuilder setAudioBitDepth(String bit_depth) {
@InlineMe(replacement = "this.setAudioSampleFormat(bit_depth)")
final public FFmpegOutputBuilder setAudioBitDepth(String bit_depth) {
return setAudioSampleFormat(bit_depth);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected Optional<Boolean> readBoolean(JsonReader reader) throws IOException {
protected void setField(T target, String name, boolean value) throws IllegalAccessException {
try {
Field f = clazz.getField(name);
if ((boolean.class.equals(f.getType()))) {
if (boolean.class.equals(f.getType())) {
f.setBoolean(target, value);
} else if (int.class.equals(f.getType())) {
f.setInt(target, value ? 1 : 0);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/bramp/ffmpeg/info/Codec.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Codec(String name, String longName, String flags) {
this.longName = Preconditions.checkNotNull(longName).trim();

Preconditions.checkNotNull(flags);
Preconditions.checkArgument(flags.length() == 6, "Format flags is invalid '{}'", flags);
Preconditions.checkArgument(flags.length() == 6, "Format flags is invalid '%s'", flags);
this.canDecode = flags.charAt(0) == 'D';
this.canEncode = flags.charAt(1) == 'E';

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/bramp/ffmpeg/info/FilterPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public FilterPattern(String pattern) {
this.variableStreams = pattern.contains("N");
List<CodecType> streams = new ArrayList<>();

for (char c : pattern.toCharArray()) {
for (int i = 0; i < pattern.length(); i++) {
final char c = pattern.charAt(i);

if (c == '|' || c == 'N') {
// These symbols are handled separately
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/bramp/ffmpeg/info/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Format(String name, String longName, String flags) {
this.longName = Preconditions.checkNotNull(longName).trim();

Preconditions.checkNotNull(flags);
Preconditions.checkArgument(flags.length() == 2, "Format flags is invalid '{}'", flags);
Preconditions.checkArgument(flags.length() == 2, "Format flags is invalid '%s'", flags);
canDemux = flags.charAt(0) == 'D';
canMux = flags.charAt(1) == 'E';
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/bramp/ffmpeg/info/InfoParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.io.IOException;
import java.util.*;

import com.google.common.base.Splitter;

public final class InfoParser {
private InfoParser() {
throw new AssertionError("No instances for you!");
Expand Down Expand Up @@ -35,7 +37,7 @@ public static List<ChannelLayout> parseLayouts(BufferedReader r) throws IOExcept
} else if (parsingChannelLayouts) {
String[] s = line.split(" ", 2);
List<IndividualChannel> decomposition = new ArrayList<>();
for (String channelName : s[1].trim().split("\\+")) {
for (String channelName : Splitter.on('+').split(s[1].trim())) {
decomposition.add(individualChannelLookup.get(channelName));
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/bramp/ffmpeg/io/ProcessUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.concurrent.TimeoutException;

/**
* A collection of utility methods for dealing with processes.
*
* @author bramp
*/
public final class ProcessUtils {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/bramp/ffmpeg/job/FFmpegJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.bramp.ffmpeg.progress.ProgressListener;

/**
* A FFmpegJob is a single job that can be run by FFmpeg. It can be a single pass, or a two pass job.
*
* @author bramp
*/
public abstract class FFmpegJob implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public SinglePassFFmpegJob(
// Build the args now (but throw away the results). This allows the illegal arguments to be
// caught early, but also allows the ffmpeg command to actually alter the arguments when
// running.
@SuppressWarnings("unused")
List<String> unused = this.builder.build();
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/bramp/ffmpeg/job/TwoPassFFmpegJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public TwoPassFFmpegJob(
// Build the args now (but throw away the results). This allows the illegal arguments to be
// caught early, but also allows the ffmpeg command to actually alter the arguments when
// running.
@SuppressWarnings("unused")
List<String> unused = this.builder.setPass(1).build();
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/bramp/ffmpeg/nut/Frame.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.bramp.ffmpeg.nut;

import com.google.common.base.MoreObjects;

import java.io.EOFException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -145,6 +146,7 @@ public void read(NutReader nut, NutDataInputStream in, int code) throws IOExcept
}

if ((flags & FLAG_CHECKSUM) == FLAG_CHECKSUM) {
@SuppressWarnings("unused")
long checksum = in.readInt();
// TODO Test checksum
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/bramp/ffmpeg/nut/MainHeaderPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected void readBody(NutDataInputStream in) throws IOException {
if (fields > 5) {
count = in.readVarLong();
} else {
count = mul - size;
count = (long) mul - size;
}
if (fields > 6) {
match = in.readSignedVarInt();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/bramp/ffmpeg/options/EncodingOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.beans.ConstructorProperties;

/**
* Audio, Video and Main encoding options for ffmpeg.
*
* @author bramp
*/
public class EncodingOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.beans.ConstructorProperties;

/**
* Encoding options that are specific to the main output.
*
* @author bramp
*/
public class MainEncodingOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public AbstractSocketProgressParser(ProgressListener listener) {
*
* <p>TODO Move this method to somewhere better.
*
* @param scheme
* @param address
* @param port
* @return
* @throws URISyntaxException
* @param scheme The scheme to use (e.g. "tcp", "udp", "rtp", "http")
* @param address The address of the server
* @param port The port to connect to
* @return A URI representing the address and port
* @throws URISyntaxException if the URI is invalid
*/
@CheckReturnValue
static URI createUri(String scheme, InetAddress address, int port) throws URISyntaxException {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/bramp/ffmpeg/progress/Progress.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public boolean isEnd() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof Progress)) return false;

Progress progress1 = (Progress) o;
return frame == progress1.frame
&& bitrate == progress1.bitrate
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/net/bramp/ffmpeg/FFmpegAvTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public void testVersion() throws Exception {

/**
* We don't support avconv, so all methods should throw an exception.
*
* @throws IOException
*/
@Test(expected = IllegalArgumentException.class)
public void testProbeVideo() throws IOException {
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ public void testMetaTags() throws InterruptedException, ExecutionException, IOEx

/**
* Test if addStdoutOutput() actually works, and the output can be correctly captured.
*
* @throws InterruptedException
* @throws ExecutionException
* @throws IOException
*/
@Test
public void testStdout() throws InterruptedException, ExecutionException, IOException {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/net/bramp/ffmpeg/FFmpegUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void testAbstractUtilsClass() {
}

@Test
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "InlineMeInliner"})
public void testMillisecondsToString() {
assertEquals("00:01:03.123", millisecondsToString(63123));
assertEquals("00:01:03", millisecondsToString(63000));
Expand All @@ -24,13 +24,13 @@ public void testMillisecondsToString() {
}

@Test(expected = IllegalArgumentException.class)
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "InlineMeInliner"})
public void testMillisecondsToStringNegative() {
millisecondsToString(-1);
}

@Test(expected = IllegalArgumentException.class)
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "InlineMeInliner"})
public void testMillisecondsToStringNegativeMinValue() {
millisecondsToString(Long.MIN_VALUE);
}
Expand Down
6 changes: 0 additions & 6 deletions src/test/java/net/bramp/ffmpeg/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public InputStream apply(@Nullable String input) {
/**
* Simple wrapper around "new SequenceInputStream", so the user doesn't have to deal with the
* horribly dated Enumeration type.
*
* @param input
* @return
*/
public static InputStream sequenceInputStream(Iterable<InputStream> input) {
checkNotNull(input);
Expand All @@ -41,9 +38,6 @@ public static InputStream loadResource(String name) {

/**
* Loads all resources, and returns one stream containing them all.
*
* @param names
* @return
*/
public static InputStream combineResource(List<String> names) {
checkNotNull(names);
Expand Down
1 change: 1 addition & 0 deletions src/test/java/net/bramp/ffmpeg/ReadmeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ReadmeTest {
public ReadmeTest() throws IOException {}

@Test
@SuppressWarnings("unused")
public void testCreateFF() throws IOException {
FFmpeg ffmpeg = new FFmpeg(FFmpeg.DEFAULT_PATH);
FFprobe ffprobe = new FFprobe(FFmpeg.DEFAULT_PATH);
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/net/bramp/ffmpeg/builder/FFmpegBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
import java.net.URI;
import java.util.List;
import java.util.concurrent.TimeUnit;

import net.bramp.ffmpeg.builder.FFmpegBuilder.Verbosity;
import net.bramp.ffmpeg.options.AudioEncodingOptions;
import net.bramp.ffmpeg.options.EncodingOptions;
import net.bramp.ffmpeg.options.MainEncodingOptions;
import net.bramp.ffmpeg.options.VideoEncodingOptions;
import org.junit.Test;

/**
* @author bramp
*/
@SuppressWarnings("unused")
public class FFmpegBuilderTest {

public FFmpegBuilderTest() throws IOException {}
Expand Down Expand Up @@ -229,7 +229,6 @@ public void testConflictingVideoSize() {

@Test
public void testURIOutput() {

List<String> args =
new FFmpegBuilder()
.setInput("input")
Expand Down
Loading

0 comments on commit a9901ab

Please sign in to comment.