Skip to content

Commit c5726c1

Browse files
committed
Fix NPE
1 parent 0816ed8 commit c5726c1

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/main/java/software/coley/llzip/format/write/CopyZipWriterStrategy.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,26 @@ public void write(ZipArchive archive, OutputStream os) throws IOException {
109109

110110
// Write end of central directory record.
111111
final EndOfCentralDirectory end = archive.getEnd();
112-
// Header
113-
writeIntLE(os, ZipPatterns.END_OF_CENTRAL_DIRECTORY_QUAD);
114-
// Disk number
115-
writeShortLE(os, end.getDiskNumber());
116-
// Central directory start disk
117-
writeShortLE(os, end.getCentralDirectoryStartDisk());
118-
// TODO What is this?
119-
writeShortLE(os, end.getCentralDirectoryStartOffset());
120-
// Central directory entries
121-
writeShortLE(os, end.getNumEntries());
122-
// Central directory size
123-
writeIntLE(os, (int) end.getCentralDirectorySize());
124-
// Central directory offset
125-
writeIntLE(os, (int) end.getCentralDirectoryOffset());
126-
// Comment length
127-
writeShortLE(os, end.getZipCommentLength());
128-
// Comment
129-
os.write(ByteDataUtil.toByteArray(end.getZipComment()));
112+
// TODO Handle null EndOfCentralDirectory more gracefully
113+
if (end != null) {
114+
// Header
115+
writeIntLE(os, ZipPatterns.END_OF_CENTRAL_DIRECTORY_QUAD);
116+
// Disk number
117+
writeShortLE(os, end.getDiskNumber());
118+
// Central directory start disk
119+
writeShortLE(os, end.getCentralDirectoryStartDisk());
120+
// TODO What is this?
121+
writeShortLE(os, end.getCentralDirectoryStartOffset());
122+
// Central directory entries
123+
writeShortLE(os, end.getNumEntries());
124+
// Central directory size
125+
writeIntLE(os, (int) end.getCentralDirectorySize());
126+
// Central directory offset
127+
writeIntLE(os, (int) end.getCentralDirectoryOffset());
128+
// Comment length
129+
writeShortLE(os, end.getZipCommentLength());
130+
// Comment
131+
os.write(ByteDataUtil.toByteArray(end.getZipComment()));
132+
}
130133
}
131134
}

0 commit comments

Comments
 (0)