Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when writing extra data records with no data #154

Closed
srikanth-lingala opened this issue Mar 6, 2020 · 2 comments
Closed

NPE when writing extra data records with no data #154

srikanth-lingala opened this issue Mar 6, 2020 · 2 comments
Assignees
Labels
bug Something isn't working resolved

Comments

@srikanth-lingala
Copy link
Owner

@srikanth-lingala @nicolabeghin
I have other problem 。when I add fille in zip ,will get NullPointException. but not All zip .
reappear it steps:

  1. download this file http://oss.youxifan.com/MGInc6E .yes it's apk .(apk is a zip)
  2. use the add Api code .
    ZipFile zipFile = new ZipFile("/Users/engine/apk/test.apk");
    ArrayList<File> addFiles = new ArrayList<>();
    addFiles.add(new File("/Users/engine/apk/test.txt"));
    ZipParameters parameters = new ZipParameters();
    parameters.setCompressionMethod(CompressionMethod.DEFLATE);
    parameters.setCompressionLevel(CompressionLevel.NORMAL);
    // 目标路径
    parameters.setRootFolderNameInZip("META-INF/");
    zipFile.addFiles(addFiles, parameters);
  1. you will get java.lang.NullPointerException and damage the apk
Stack trace:
 net.lingala.zip4j.exception.ZipException: java.lang.NullPointerException
	at net.lingala.zip4j.headers.HeaderWriter.writeFileHeader(HeaderWriter.java:501)
	at net.lingala.zip4j.headers.HeaderWriter.writeCentralDirectory(HeaderWriter.java:382)
	at net.lingala.zip4j.headers.HeaderWriter.finalizeZipFile(HeaderWriter.java:177)
Caused by: java.lang.NullPointerException
	at java.io.OutputStream.write(OutputStream.java:75)
	at net.lingala.zip4j.headers.HeaderWriter.writeRemainingExtraDataRecordsIfPresent(HeaderWriter.java:54
	at net.lingala.zip4j.headers.HeaderWriter.writeFileHeader(HeaderWriter.java:495)
	... 37 more
  1. I have fix this Exception by modify HeaderWriter.writeRemainingExtraDataRecordsIfPresent() .at the latest code :
    if(extraDataRecord.getData()!=null){
        outputStream.write(extraDataRecord.getData());
      }

but I'm not sure I'm right

Originally posted by @lovekill in #148 (comment)

@srikanth-lingala
Copy link
Owner Author

Issue fixed, will include it in next release

@srikanth-lingala
Copy link
Owner Author

Fix included in v2.5.0 released today. A couple of more features have been added in this release. Please have a look at release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved
Projects
None yet
Development

No branches or pull requests

1 participant