ryantenney / passkit4j

Java library for generating Apple Passbook (.pkpass) files

Home Page:http://www.ryantenney.com/passkit4j/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't create passfile: PassSerializationException: Error closing output stream

fkrauthan opened this issue · comments

If I call this PassSerializer.writePkPassArchive(pass, signer, byteOutputStream); I the following exception:

Caused by: com.ryantenney.passkit4j.PassSerializationException: Error closing output stream
        at com.ryantenney.passkit4j.PassSerializer.writePkPassArchive(PassSerializer.java:76)
        at com.***.service.passbook.PassbookGeneratorServiceLocalServiceBean.generatePass(PassbookGeneratorServiceLocalServiceBean.java:143)
        ... 85 more
Caused by: java.util.zip.ZipException: ZIP file must have at least one entry
        at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:304)
        at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:140)
        at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:321)
        at com.ryantenney.passkit4j.PassSerializer.writePkPassArchive(PassSerializer.java:74)
        ... 86 more
|#]

Found the issue. If you don't add any files to a pass then files is null and the foreach throws a Exception.

Good to know! I'll add a null-check and instead of rethrowing the IOException from the call to close() I'll just log it instead?

The IOException is thrown because of the nullpointer. So I think it is enough if you add the null pointer check.