Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[Bug] xlsx stream write leaves temp file

オープン 初心者向け
#1,137 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
backend

調査の方向性

バグは WriteContextImpl.java の 663-694 行目にあります。まず doOutputStreamEncrypt07 メソッドを読んで、一時ファイルのフローを理解してください。修正には、すべての終了パスで tempXlsx.delete() が実行されるように try-finally ブロックを再構築することが含まれます。暗号化を使用した XLSX 書き込みの既存のテストを実行し、修正が既存の機能を損なわないことを確認してください。

索引モデルが issue の本文から書いたものです。

説明

bug
Search before asking
  • I searched in the issues and found nothing similar.
Fesod version

main

JDK version

any

Operating system

Linux

Steps To Reproduce

When an xlsx is written to an OutputStream with .password(...), WriteContextImpl#doOutputStreamEncrypt07() first writes the workbook unencrypted to a temp file, then encrypts that file into the caller's stream (code). The temp file is deleted on every path except one:

FileOutputStream tempFileOutputStream = new FileOutputStream(tempXlsx);
try {
    writeWorkbookHolder.getWorkbook().write(tempFileOutputStream);   // 1. fails, e.g. disk full
} finally {
    try {
        writeWorkbookHolder.getWorkbook().close();
        tempFileOutputStream.close();                                 // 2. succeeds
    } catch (Exception e) {
        if (!tempXlsx.delete()) { ... }                               // only runs if 2. fails
        throw e;
    }
}
try (POIFSFileSystem fileSystem = openFileSystemAndEncrypt(tempXlsx)) {
    fileSystem.writeFilesystem(writeWorkbookHolder.getOutputStream());
} finally {
    if (!tempXlsx.delete()) { ... }                                   // never reached after 1.
}

If writing the temp file fails but closing succeeds, the exception from step 1 leaves the method without ever reaching a delete.

Current Behavior

The partly or fully written, unencrypted xlsx stays in Fesod's temp directory.

Expected Behavior

The temp file is deleted however doOutputStreamEncrypt07() exits, including when writing it fails.

Anything else?

Proposed fix. Move the delete into one outer finally that covers both the temp-file write and the encryption step:

FileOutputStream tempFileOutputStream = new FileOutputStream(tempXlsx);
try {
    try {
        writeWorkbookHolder.getWorkbook().write(tempFileOutputStream);
    } finally {
        writeWorkbookHolder.getWorkbook().close();
        tempFileOutputStream.close();
    }
    try (POIFSFileSystem fileSystem = openFileSystemAndEncrypt(tempXlsx)) {
        fileSystem.writeFilesystem(writeWorkbookHolder.getOutputStream());
    }
} finally {
    if (!tempXlsx.delete()) {
        throw new ExcelGenerateException("Can not delete temp File!");
    }
}
  • A successful write, a failed close and a failed encryption behave as before: the temp file is deleted in each case.
  • A failed write now deletes the temp file too.
Are you willing to submit a PR?
  • I'm willing to submit a PR!
主要言語
Java
スター
6.2k
フォーク
532
平均マージ
11時間 55分
マージ済み PR(30日)
22

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/fesod のほかの issue

apache/fesod の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。