You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flink.apache.org by "wuguihu (Jira)" <ji...@apache.org> on 2021/06/08 16:30:00 UTC

[jira] [Created] (FLINK-22930) [flink-python]: Resources should be closed

wuguihu created FLINK-22930:
-------------------------------

             Summary: [flink-python]: Resources should be closed
                 Key: FLINK-22930
                 URL: https://issues.apache.org/jira/browse/FLINK-22930
             Project: Flink
          Issue Type: Bug
          Components: API / Python
    Affects Versions: 1.13.1
            Reporter: wuguihu



Files that implement the Closeable interface or its super-interface, AutoCloseable, needs to be closed after use.


In flink-python module, the class "org.apache.flink.python.util.ZipUtils" 's  method extractZipFileWithPermissions(),  the OutputStream should be closed.

The details are shown below:


{code:java}
// class: org.apache.flink.python.util.ZipUtils
// method: extractZipFileWithPermissions
// line71:Use try-with-resources

    public static void extractZipFileWithPermissions(String zipFilePath, String targetPath)
            throws IOException {
        try (ZipFile zipFile = new ZipFile(zipFilePath)) {
            Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
            boolean isUnix = isUnix();

            while (entries.hasMoreElements()) {
                ZipArchiveEntry entry = entries.nextElement();
                File file;
                if (entry.isDirectory()) {
                    ……
                } else {
                    ……
                    if (file.createNewFile()) {
//line 71
                        OutputStream output = new FileOutputStream(file);
                        IOUtils.copyBytes(zipFile.getInputStream(entry), output);
                    } else {
                        throw new IOException(
                                "Create file: " + file.getAbsolutePath() + " failed!");
                    }
                }
                if (isUnix) {
                    ……
                }
            }
        }
    }
{code}






--
This message was sent by Atlassian Jira
(v8.3.4#803005)