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.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 java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import picocli.CommandLine;

@CommandLine.Command(name = "jar", showAtFileInUsageHelp = true, description = "Containerize a jar")
public class Jar implements Callable<Integer> {
  @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 TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();

  @Override
  public Integer call() {
    globalOptions.validate();
    try {
      ConsoleLogger logger =
          CliLogger.newLogger(globalOptions.getVerbosity(), globalOptions.getConsoleOutput());

      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;
      }

      Containerizer containerizer = Containerizers.from(globalOptions, logger);

      JibContainerBuilder containerBuilder =
          JarFiles.toJibContainerBuilder(jarFile, tempDirectoryProvider.newDirectory());

      containerBuilder.containerize(containerizer);
    } catch (Exception ex) {
      if (globalOptions.isStacktrace()) {
        ex.printStackTrace();
      }

Review comment (suggestion):
```suggestion
    try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {
```
and remove the field and the `finally` block.

Code after:
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 java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import picocli.CommandLine;

@CommandLine.Command(name = "jar", showAtFileInUsageHelp = true, description = "Containerize a jar")
public class Jar implements Callable<Integer> {
  @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();
    try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {
      ConsoleLogger logger =
          CliLogger.newLogger(globalOptions.getVerbosity(), globalOptions.getConsoleOutput());

      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;
      }

      Containerizer containerizer = Containerizers.from(globalOptions, logger);

      JibContainerBuilder containerBuilder =
          JarFiles.toJibContainerBuilder(jarFile, tempDirectoryProvider.newDirectory());

      containerBuilder.containerize(containerizer);
    } catch (Exception ex) {
      if (globalOptions.isStacktrace()) {
        ex.printStackTrace();
      }
      System.err.println(ex.getClass().getName() + ": " + ex.getMessage());
      return 1;