Repository: GoogleContainerTools/jib
File: jib-cli/src/main/java/com/google/cloud/tools/jib/cli/cli2/Jar.java (Java)

Code before:
import com.google.cloud.tools.jib.api.JibContainerBuilder;
import com.google.cloud.tools.jib.api.LogEvent;
import com.google.cloud.tools.jib.cli.cli2.logging.CliLogger;
import com.google.cloud.tools.jib.cli.jar.JarFiles;
import com.google.cloud.tools.jib.filesystem.TempDirectoryProvider;
import com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger;
import com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import picocli.CommandLine;
import picocli.CommandLine.Model.CommandSpec;

@CommandLine.Command(name = "jar", showAtFileInUsageHelp = true, description = "Containerize a jar")
public class Jar implements Callable<Integer> {
  @CommandLine.Spec CommandSpec spec = CommandSpec.create();

  @CommandLine.ParentCommand
  @SuppressWarnings("NullAway.Init") // initialized by picocli
  protected JibCli globalOptions;

  @CommandLine.Parameters(description = "The path to the jar file (ex: path/to/my-jar.jar)")
  @SuppressWarnings("NullAway.Init") // initialized by picocli
  private Path jarFile;

  private final SingleThreadedExecutor executor = new SingleThreadedExecutor();

  @Override
  public Integer call() {
    globalOptions.validate();
    try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {

      ConsoleLogger logger =
          CliLogger.newLogger(
              globalOptions.getVerbosity(),
              globalOptions.getConsoleOutput(),
              spec.commandLine().getOut(),
              spec.commandLine().getErr(),
              executor);

      if (!Files.exists(jarFile)) {
        logger.log(LogEvent.Level.ERROR, "The file path provided does not exist: " + jarFile);
        return 1;
      }
      if (Files.isDirectory(jarFile)) {
        logger.log(
            LogEvent.Level.ERROR,
            "The file path provided is for a directory. Please provide a path to a jar file: "
                + jarFile);
        return 1;
      }

Review comment (suggestion):
I don't think this needs to be a field. Just instantiate as a local variable in `call()`. I know you'll going to use it in a `finally` block, so you can create it before `try {`.

Code after:
import com.google.cloud.tools.jib.api.JibContainerBuilder;
import com.google.cloud.tools.jib.api.LogEvent;
import com.google.cloud.tools.jib.cli.cli2.logging.CliLogger;
import com.google.cloud.tools.jib.cli.jar.JarFiles;
import com.google.cloud.tools.jib.filesystem.TempDirectoryProvider;
import com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger;
import com.google.cloud.tools.jib.plugins.common.logging.SingleThreadedExecutor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import picocli.CommandLine;
import picocli.CommandLine.Model.CommandSpec;

@CommandLine.Command(name = "jar", showAtFileInUsageHelp = true, description = "Containerize a jar")
public class Jar implements Callable<Integer> {

  @CommandLine.Spec private CommandSpec spec = CommandSpec.create();

  @CommandLine.ParentCommand
  @SuppressWarnings("NullAway.Init") // initialized by picocli
  protected JibCli globalOptions;

  @CommandLine.Parameters(description = "The path to the jar file (ex: path/to/my-jar.jar)")
  @SuppressWarnings("NullAway.Init") // initialized by picocli
  private Path jarFile;

  @Override
  public Integer call() {
    globalOptions.validate();
    SingleThreadedExecutor executor = new SingleThreadedExecutor();
    try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {

      ConsoleLogger logger =
          CliLogger.newLogger(
              globalOptions.getVerbosity(),
              globalOptions.getConsoleOutput(),
              spec.commandLine().getOut(),
              spec.commandLine().getErr(),
              executor);

      if (!Files.exists(jarFile)) {
        logger.log(LogEvent.Level.ERROR, "The file path provided does not exist: " + jarFile);
        return 1;
      }
      if (Files.isDirectory(jarFile)) {
        logger.log(
            LogEvent.Level.ERROR,
            "The file path provided is for a directory. Please provide a path to a jar file: "
                + jarFile);
        return 1;
      }