Author: bodewig Date: Tue Aug 16 04:04:07 2011 New Revision: 1158101 URL: http://svn.apache.org/viewvc?rev=1158101&view=rev Log: address issues detected by findbugs
Modified: commons/proper/compress/trunk/findbugs-exclude-filter.xml commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntry.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveSummary.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java Modified: commons/proper/compress/trunk/findbugs-exclude-filter.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/findbugs-exclude-filter.xml?rev=1158101&r1=1158100&r2=1158101&view=diff ============================================================================== --- commons/proper/compress/trunk/findbugs-exclude-filter.xml (original) +++ commons/proper/compress/trunk/findbugs-exclude-filter.xml Tue Aug 16 04:04:07 2011 @@ -37,6 +37,11 @@ <Method name="finalize" /> <Bug pattern="NP_ALWAYS_NULL" /> </Match> + <Match> + <Class name="org.apache.commons.compress.archivers.dump.DumpArchiveUtil" /> + <Method name="dumpBlock" /> + <Bug pattern="NP_ALWAYS_NULL" /> + </Match> <!-- Reason: fallthrough is intended --> <Match> @@ -54,6 +59,11 @@ </Or> <Bug pattern="UWF_NULL_FIELD" /> </Match> + <Match> + <Class name="org.apache.commons.compress.archivers.dump.DumpArchiveEntry" /> + <Field name="summary"/> + <Bug pattern="UWF_NULL_FIELD" /> + </Match> <!-- Reason: exception in close swallowed in order to re-throw original --> <Match> Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntry.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntry.java?rev=1158101&r1=1158100&r2=1158101&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntry.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntry.java Tue Aug 16 04:04:07 2011 @@ -182,11 +182,14 @@ public class DumpArchiveEntry implements private int mode; private Set<PERMISSION> permissions = Collections.emptySet(); private long size; - private Date atime; - private Date mtime; + private long atime; + private long mtime; private int uid; private int gid; + /** + * Currently unused + */ private DumpArchiveSummary summary = null; // this information is available from standard index. @@ -198,7 +201,7 @@ public class DumpArchiveEntry implements private long offset; private int ino; private int nlink; - private Date ctime; + private long ctime; private int generation; private boolean isDeleted; @@ -280,14 +283,14 @@ public class DumpArchiveEntry implements * Get file creation time. */ public Date getCreationTime() { - return ctime; + return new Date(ctime); } /** * Set the file creation time. */ public void setCreationTime(Date ctime) { - this.ctime = ctime; + this.ctime = ctime.getTime(); } /** @@ -389,7 +392,7 @@ public class DumpArchiveEntry implements public boolean equals(Object o) { if (o == this) { return true; - } else if (!o.getClass().equals(getClass())) { + } else if (o == null || !o.getClass().equals(getClass())) { return false; } @@ -403,7 +406,8 @@ public class DumpArchiveEntry implements return false; } - if ((summary != null) || summary.equals(rhs.summary)) { + if ((summary == null && rhs.summary != null) + || (summary != null && !summary.equals(rhs.summary))) { return false; } @@ -461,7 +465,7 @@ public class DumpArchiveEntry implements entry.setLastModifiedDate(new Date(t)); t = (1000L * DumpArchiveUtil.convert32(buffer, 64)) + (DumpArchiveUtil.convert32(buffer, 68) / 1000); - entry.ctime = new Date(t); + entry.ctime = t; // db: 72-119 - direct blocks // id: 120-131 - indirect blocks @@ -565,7 +569,7 @@ public class DumpArchiveEntry implements /** {@inheritDoc} */ public Date getLastModifiedDate() { - return mtime; + return new Date(mtime); } /** @@ -664,21 +668,21 @@ public class DumpArchiveEntry implements * Set the time the file was last modified. */ public void setLastModifiedDate(Date mtime) { - this.mtime = mtime; + this.mtime = mtime.getTime(); } /** * Returns the time the file was last accessed. */ public Date getAccessTime() { - return atime; + return new Date(atime); } /** * Set the time the file was last accessed. */ public void setAccessTime(Date atime) { - this.atime = atime; + this.atime = atime.getTime(); } /** Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java?rev=1158101&r1=1158100&r2=1158101&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java Tue Aug 16 04:04:07 2011 @@ -21,6 +21,7 @@ package org.apache.commons.compress.arch import org.apache.commons.compress.archivers.ArchiveException; import org.apache.commons.compress.archivers.ArchiveInputStream; +import java.io.EOFException; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; @@ -141,7 +142,10 @@ public class DumpArchiveInputStream exte } // we don't do anything with this yet. - raw.skip(DumpArchiveConstants.TP_SIZE * active.getHeaderCount()); + if (raw.skip(DumpArchiveConstants.TP_SIZE * active.getHeaderCount()) + == -1) { + throw new EOFException(); + } readIdx = active.getHeaderCount(); } @@ -162,7 +166,10 @@ public class DumpArchiveInputStream exte } // we don't do anything with this yet. - raw.skip(DumpArchiveConstants.TP_SIZE * active.getHeaderCount()); + if (raw.skip(DumpArchiveConstants.TP_SIZE * active.getHeaderCount()) + == -1) { + throw new EOFException(); + } readIdx = active.getHeaderCount(); } @@ -189,8 +196,9 @@ public class DumpArchiveInputStream exte // block by block. We may want to revisit this if // the unnecessary decompression time adds up. while (readIdx < active.getHeaderCount()) { - if (!active.isSparseRecord(readIdx++)) { - raw.skip(DumpArchiveConstants.TP_SIZE); + if (!active.isSparseRecord(readIdx++) + && raw.skip(DumpArchiveConstants.TP_SIZE) == -1) { + throw new EOFException(); } } @@ -207,8 +215,11 @@ public class DumpArchiveInputStream exte // skip any remaining segments for prior file. while (DumpArchiveConstants.SEGMENT_TYPE.ADDR == active.getHeaderType()) { - raw.skip(DumpArchiveConstants.TP_SIZE * (active.getHeaderCount() - - active.getHeaderHoles())); + if (raw.skip(DumpArchiveConstants.TP_SIZE + * (active.getHeaderCount() + - active.getHeaderHoles())) == -1) { + throw new EOFException(); + } filepos = raw.getBytesRead(); headerBytes = raw.readRecord(); @@ -287,7 +298,9 @@ public class DumpArchiveInputStream exte blockBuffer = new byte[datalen]; } - raw.read(blockBuffer, 0, datalen); + if (raw.read(blockBuffer, 0, datalen) != datalen) { + throw new EOFException(); + } int reclen = 0; @@ -445,7 +458,10 @@ outer: } if (!active.isSparseRecord(readIdx++)) { - raw.read(readBuf, 0, readBuf.length); + int r = raw.read(readBuf, 0, readBuf.length); + if (r != readBuf.length) { + throw new EOFException(); + } } else { Arrays.fill(readBuf, (byte) 0); } Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveSummary.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveSummary.java?rev=1158101&r1=1158100&r2=1158101&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveSummary.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveSummary.java Tue Aug 16 04:04:07 2011 @@ -29,8 +29,8 @@ import java.util.Date; * For the corresponding C structure see the header of {@link DumpArchiveEntry}. */ public class DumpArchiveSummary { - private Date dumpDate; - private Date previousDumpDate; + private long dumpDate; + private long previousDumpDate; private int volume; private String label; private int level; @@ -42,8 +42,8 @@ public class DumpArchiveSummary { private int ntrec; DumpArchiveSummary(byte[] buffer) { - dumpDate = new Date(1000L * DumpArchiveUtil.convert32(buffer, 4)); - previousDumpDate = new Date(1000L * DumpArchiveUtil.convert32(buffer, 8)); + dumpDate = 1000L * DumpArchiveUtil.convert32(buffer, 4); + previousDumpDate = 1000L * DumpArchiveUtil.convert32(buffer, 8); volume = DumpArchiveUtil.convert32(buffer, 12); label = new String(buffer, 676, DumpArchiveConstants.LBLSIZE).trim(); level = DumpArchiveUtil.convert32(buffer, 692); @@ -62,14 +62,14 @@ public class DumpArchiveSummary { * @return the date of this dump. */ public Date getDumpDate() { - return dumpDate; + return new Date(dumpDate); } /** * Set dump date. */ public void setDumpDate(Date dumpDate) { - this.dumpDate = dumpDate; + this.dumpDate = dumpDate.getTime(); } /** @@ -77,14 +77,14 @@ public class DumpArchiveSummary { * @return dumpdate may be null */ public Date getPreviousDumpDate() { - return previousDumpDate; + return new Date(previousDumpDate); } /** * Set previous dump date. */ public void setPreviousDumpDate(Date previousDumpDate) { - this.previousDumpDate = previousDumpDate; + this.previousDumpDate = previousDumpDate.getTime(); } /** @@ -287,9 +287,7 @@ public class DumpArchiveSummary { hash = label.hashCode(); } - if (dumpDate != null) { - hash = (31 * dumpDate.hashCode()) + 17; - } + hash += 31 * dumpDate; if (hostname != null) { hash = (31 * hostname.hashCode()) + 17; @@ -311,13 +309,13 @@ public class DumpArchiveSummary { return true; } - if (!o.getClass().equals(getClass())) { + if (o == null || !o.getClass().equals(getClass())) { return false; } DumpArchiveSummary rhs = (DumpArchiveSummary) o; - if ((dumpDate == null) || !dumpDate.equals(rhs.dumpDate)) { + if (dumpDate != rhs.dumpDate) { return false; } Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java?rev=1158101&r1=1158100&r2=1158101&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java Tue Aug 16 04:04:07 2011 @@ -104,7 +104,12 @@ class TapeInputStream extends FilterInpu } /** - * @see java.io.InputStream#read(byte[], int, int) + * {@inheritDoc} + * + * <p>reads the full given length unless EOF is reached.</p> + * + * @param len length to read, must be a multiple of the stream's + * record size */ @Override public int read(byte[] b, int off, int len) throws IOException { @@ -146,7 +151,11 @@ class TapeInputStream extends FilterInpu /** * Skip bytes. Same as read but without the arraycopy. - * @see java.io.InputStream#read(byte[], int, int) + * + * <p>skips the full given length unless EOF is reached.</p> + * + * @param len length to read, must be a multiple of the stream's + * record size */ @Override public long skip(long len) throws IOException { @@ -254,7 +263,9 @@ class TapeInputStream extends FilterInpu success = readFully(blockBuffer, 0, blockSize); bytesRead += blockSize; } else { - in.read(blockBuffer, 0, 4); + if (!readFully(blockBuffer, 0, 4)) { + return false; + } bytesRead += 4; int h = DumpArchiveUtil.convert32(blockBuffer, 0);