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

ExtractFile Failed with NullPointExcetion #435

Closed
LonelyTangzz opened this issue Jun 7, 2022 · 4 comments
Closed

ExtractFile Failed with NullPointExcetion #435

LonelyTangzz opened this issue Jun 7, 2022 · 4 comments
Labels
bug Something isn't working resolved

Comments

@LonelyTangzz
Copy link

Recently, I was doing a dependency upgrade of an old project, and planned to upgrade the original Zip4j@1.3.2 to 2.7.0, but when I did the unit test of the decompression part after the upgrade, I couldn't get the fileAttributeView normally, resulting in a null pointer exception.

    private static void applyWindowsFileAttributes(Path file, byte[] fileAttributes) {
        if (fileAttributes[0] != 0) {
            DosFileAttributeView fileAttributeView = (DosFileAttributeView)Files.getFileAttributeView(file, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);//here can't get fileAttributeView

            try {
                fileAttributeView.setReadOnly(BitUtils.isBitSet(fileAttributes[0], 0));
                fileAttributeView.setHidden(BitUtils.isBitSet(fileAttributes[0], 1));
                fileAttributeView.setSystem(BitUtils.isBitSet(fileAttributes[0], 2));
                fileAttributeView.setArchive(BitUtils.isBitSet(fileAttributes[0], 5));
            } catch (IOException var4) {
            }

        }
    }

I did breakpoint debugging, this path of file is non-empty, which is strange, and the folder access permission is also granted. Does the author know what happened?

@srikanth-lingala
Copy link
Owner

Do you have a stacktrace for me?

@LonelyTangzz
Copy link
Author

here

Caused by: net.lingala.zip4j.exception.ZipException: java.lang.NullPointerException
	at net.lingala.zip4j.tasks.AsyncZipTask.performTaskWithErrorHandling(AsyncZipTask.java:58)
	at net.lingala.zip4j.tasks.AsyncZipTask.execute(AsyncZipTask.java:45)
	at net.lingala.zip4j.ZipFile.extractFile(ZipFile.java:672)
	at net.lingala.zip4j.ZipFile.extractFile(ZipFile.java:528)
	at net.lingala.zip4j.ZipFile.extractFile(ZipFile.java:484)
	at com.manulife.productengine.mut.util.RegFileUtil.unzipFile(RegFileUtil.java:86)
	... 65 more
Caused by: java.lang.NullPointerException
	at net.lingala.zip4j.util.FileUtils.applyWindowsFileAttributes(FileUtils.java:469)
	at net.lingala.zip4j.util.FileUtils.setFileAttributes(FileUtils.java:54)
	at net.lingala.zip4j.util.UnzipUtil.applyFileAttributes(UnzipUtil.java:47)
	at net.lingala.zip4j.tasks.AbstractExtractFileTask.extractFile(AbstractExtractFileTask.java:68)
	at net.lingala.zip4j.tasks.ExtractFileTask.executeTask(ExtractFileTask.java:47)
	at net.lingala.zip4j.tasks.ExtractFileTask.executeTask(ExtractFileTask.java:26)
	at net.lingala.zip4j.tasks.AsyncZipTask.performTaskWithErrorHandling(AsyncZipTask.java:51)
	... 70 more

When calling getFileAttributeView, the @NotNull that triggers this method causes the initialization of fileAttributeView to fail, resulting in NPE in setReadOnly in try. But I guarantee that the incoming file is non-empty, which is quite strange. By the way, When I used zip4j@1.3.2, this question didn't happen.

@LonelyTangzz
Copy link
Author

LonelyTangzz commented Jun 7, 2022

begin status
after status

@srikanth-lingala
Copy link
Owner

Fixed in v2.11.0 released today

slp091020 pushed a commit to slp091020/zip4j that referenced this issue Jul 26, 2022
srikanth-lingala pushed a commit that referenced this issue Sep 8, 2022
* Fixup #435: Add null check when getting and applying Windows file attributes

* Clean up raw types

Co-authored-by: Shane Parris <s@zd.is>
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

2 participants