Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[Bug] xlsx stream write leaves temp file

Abierto Apto para principiantes
#1,137 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
75/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java
Área
backend

Línea de trabajo

El error está en WriteContextImpl.java en las líneas 663-694. Comience leyendo el método doOutputStreamEncrypt07 para comprender el flujo del archivo temporal. La solución implica reestructurar los bloques try-finally para garantizar que tempXlsx.delete() se ejecute en todas las rutas de salida. Ejecute las pruebas existentes para la escritura de XLSX con cifrado para verificar que la solución no rompa la funcionalidad existente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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!
Lenguaje dominante
Java
Estrellas
6.2k
Forks
532
Merge medio
11 h 55 min
PR fusionados (30 d)
22

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/fesod

Todos los issues de apache/fesod

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.