commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1094856 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Date Tue, 19 Apr 2011 11:02:35 GMT
On 19 April 2011 06:35,  <bodewig@apache.org> wrote:
> Author: bodewig
> Date: Tue Apr 19 05:35:04 2011
> New Revision: 1094856
>
> URL: http://svn.apache.org/viewvc?rev=1094856&view=rev
> Log:
> print a warning if finalize closes the archive
>
> Modified:
>    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
>
> Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
> URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java?rev=1094856&r1=1094855&r2=1094856&view=diff
> ==============================================================================
> --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
(original)
> +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Tue Apr 19 05:35:04 2011
> @@ -102,6 +102,11 @@ public class ZipFile {
>     private final ZipEncoding zipEncoding;
>
>     /**
> +     * File name of actual source.
> +     */
> +    private final String archiveName;
> +
> +    /**
>      * The actual data source.
>      */
>     private final RandomAccessFile archive;
> @@ -180,6 +185,7 @@ public class ZipFile {
>      */
>     public ZipFile(File f, String encoding, boolean useUnicodeExtraFields)
>         throws IOException {
> +        this.archiveName = f.getAbsolutePath();
>         this.encoding = encoding;
>         this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding);
>         this.useUnicodeExtraFields = useUnicodeExtraFields;
> @@ -214,7 +220,11 @@ public class ZipFile {
>      * @throws IOException if an error occurs closing the archive.
>      */
>     public void close() throws IOException {
> +        // this flag is only written here and read in finalize() which
> +        // can never be run in parallel.
> +        // no synchronization needed.

Are you sure?

If finalize() runs in a different thread from close(), then the field
should be volatile to ensure safe publication.

>         closed = true;
> +
>         archive.close();
>     }
>
> @@ -320,7 +330,11 @@ public class ZipFile {
>      */
>     protected void finalize() throws Throwable {
>         try {
> -            close();
> +            if (!closed) {
> +                System.err.println("Cleaning up unclosed ZipFile for archive
"
> +                                   + archiveName);
> +                close();
> +            }
>         } finally {
>             super.finalize();
>         }
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message