private static boolean isValid(Statement stat, VarExprent closeable, boolean nullable) {
    if (nullable) {
      // Check for if statement that contains a null check and a close()
      if (stat instanceof IfStatement) {
        IfStatement ifStat = (IfStatement) stat;
        Exprent condition = ifStat.getHeadexprent().getCondition();

        if (condition instanceof FunctionExprent) {
          // This can sometimes be double inverted negative conditions too, handle that case
          FunctionExprent func = unwrapNegations((FunctionExprent) condition);

          // Ensure the exprent is the one we want to remove
          if (func.getFuncType() == FunctionType.NE && func.getLstOperands().get(0) instanceof VarExprent && func.getLstOperands().get(1).getExprType().equals(VarType.VARTYPE_NULL)) {
            if (func.getLstOperands().get(0) instanceof VarExprent && ((VarExprent) func.getLstOperands().get(0)).getVarVersionPair().equals(closeable.getVarVersionPair())) {
              return true;
            }
          }
        }
      }
    } else {
      if (stat instanceof BasicBlockStatement) {
        if (stat.getExprents() != null && !stat.getExprents().isEmpty()) {
          Exprent exprent = stat.getExprents().get(0);

          if (exprent instanceof InvocationExprent) {
            Exprent inst = ((InvocationExprent) exprent).getInstance();

            // Ensure the var exprent we want to remove is the right one
            if (inst instanceof VarExprent && inst.equals(closeable) && isCloseable(exprent)) {
              return true;
            }
          }
        }
      }
    }

    return false;
  }
Processes try catch statements to turns them into try-with-resources statements wherever possible.
Including the entire classpath is generally needed for this to work as it needs to know which classes implement AutoCloseable.

@author ForgeFlower devs, SuperCoder79
src/org/jetbrains/java/decompiler/modules/decompiler/TryWithResourcesProcessor.java