Author: sebb Date: Mon Apr 27 20:57:10 2009 New Revision: 769157 URL: http://svn.apache.org/viewvc?rev=769157&view=rev Log: Check for closing non-existent entry
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java?rev=769157&r1=769156&r2=769157&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java Mon Apr 27 20:57:10 2009 @@ -37,7 +37,7 @@ private long archiveOffset = 0; private long entryOffset = 0; private ArArchiveEntry prevEntry; - private boolean haveUnclosedEntry = true; + private boolean haveUnclosedEntry = false; /** indicates if this archive is finished */ private boolean finished = false; @@ -56,7 +56,10 @@ if(finished) { throw new IOException("Stream has already been finished"); } - if (prevEntry != null && haveUnclosedEntry && (entryOffset % 2) != 0) { + if (prevEntry == null || !haveUnclosedEntry){ + throw new IOException("No current entry to close"); + } + if ((entryOffset % 2) != 0) { out.write('\n'); // Pad byte archiveOffset++; } @@ -76,7 +79,9 @@ throw new IOException("length does not match entry (" + prevEntry.getLength() + " != " + entryOffset); } - closeArchiveEntry(); + if (haveUnclosedEntry) { + closeArchiveEntry(); + } } prevEntry = pArEntry; @@ -184,7 +189,7 @@ */ public void finish() throws IOException { if(haveUnclosedEntry) { - throw new IOException("This archives contains unclosed entries."); + throw new IOException("This archive contains unclosed entries."); } else if(finished) { throw new IOException("This archive has already been finished"); }