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

Code before:
   * @throws IOException if I/O error occurs when opening the file.
   */
  public static JarType determineJarType(Path jarPath) throws IOException {
    JarFile jarFile = new JarFile(jarPath.toFile());
    if (jarFile.getEntry("BOOT-INF") != null) {
      return JarType.SPRING_BOOT;
    }
    return JarType.STANDARD;
  }

  /**
   * Explode jar and create three layers for classes, resources and dependencies on container.
   *
   * @param jarPath path to jar file.
   * @param tempDirPath path to temporary jib local directory to use.
   * @return list of {@link FileEntriesLayer}.
   * @throws IOException if I/O error occurs when opening the jar file or if the directory for the
   *     temporary directory path provided, doesn't exist.
   */
  public static List<FileEntriesLayer> explodeStandardJar(Path jarPath, @Nullable Path tempDirPath)
      throws IOException {
    Path localExplodedJarRoot;
    if (tempDirPath == null) {
      try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) {
        localExplodedJarRoot = tempDirectoryProvider.newDirectory();
      }
    } else {
      localExplodedJarRoot = tempDirPath;
    }
    ZipUtil.unzip(jarPath, localExplodedJarRoot);

    List<FileEntriesLayer> layers = new ArrayList<>();
    Predicate<Path> isClassFile = path -> path.getFileName().toString().endsWith(".class");
    Predicate<Path> isResourceFile = isClassFile.negate();

    // Determine class and resource files in the directory containing jar contents and create
    // FileEntriesLayer for each type of layer (class or resource), while maintaining the
    // file's original project structure.
    FileEntriesLayer classesLayer =
        addDirectoryContentsToLayer(
                FileEntriesLayer.builder(),
                localExplodedJarRoot,
                isClassFile,
                APP_ROOT.resolve(RelativeUnixPath.get("explodedJar")))
            .setName("Classes")
            .build();
    FileEntriesLayer resourcesLayer =
        addDirectoryContentsToLayer(
                FileEntriesLayer.builder(),
                localExplodedJarRoot,
                isResourceFile,

Review comment (suggestion):
Once a `Closeable` class is closed, it's permanently shutdown and not usable. So you should put the entire code that needs to use `localExplodedJarRoot` into the try-resource block.

Code after:
  public static JarType determineJarType(Path jarPath) throws IOException {
    JarFile jarFile = new JarFile(jarPath.toFile());
    if (jarFile.getEntry("BOOT-INF") != null) {
      return JarType.SPRING_BOOT;
    }
    return JarType.STANDARD;
  }

  /**
   * Explodes jar and create three layers for classes, resources and dependencies on container.
   *
   * @param jarPath path to jar file
   * @param tempDirPath path to temporary jib local directory
   * @return list of {@link FileEntriesLayer}
   * @throws IOException if I/O error occurs when opening the jar file or if temporary directory
   *     provided doesn't exist
   */
  public static List<FileEntriesLayer> explodeStandardJar(Path jarPath, Path tempDirPath)
      throws IOException {
    Path localExplodedJarRoot = tempDirPath;
    ZipUtil.unzip(jarPath, localExplodedJarRoot);
    List<FileEntriesLayer> layers = new ArrayList<>();

    // Get dependencies from Class-Path in the jar's manifest and add a layer with these
    // dependencies as entries. If Class-Path is not present in the jar's manifest then skip adding
    // a dependencies layer.
    JarFile jarFile = new JarFile(jarPath.toFile());
    String classPath =
        jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
    if (classPath != null) {
      List<Path> dependencies =
          Splitter.onPattern("\\s+")
              .splitToList(classPath.trim())
              .stream()
              .map(Paths::get)
              .collect(Collectors.toList());
      FileEntriesLayer.Builder dependenciesLayerBuilder =
          FileEntriesLayer.builder().setName("dependencies");
      dependencies.forEach(
          path ->
              dependenciesLayerBuilder.addEntry(
                  path, APP_ROOT.resolve(RelativeUnixPath.get("dependencies")).resolve(path)));
      layers.add(dependenciesLayerBuilder.build());
    }

    Predicate<Path> isClassFile = path -> path.getFileName().toString().endsWith(".class");
    Predicate<Path> isResourceFile = isClassFile.negate();

    // Determine class and resource files in the directory containing jar contents and create
    // FileEntriesLayer for each type of layer (classes or resources), while maintaining the
    // file's original project structure.