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

ZipParameters.clone() does not work #421

Closed
jeffrey-easyesi opened this issue Apr 7, 2022 · 4 comments
Closed

ZipParameters.clone() does not work #421

jeffrey-easyesi opened this issue Apr 7, 2022 · 4 comments

Comments

@jeffrey-easyesi
Copy link

ZipParameters has a public clone() method, but it doesn't work as (since commit 4c50a6a) the class does not implement Cloneable.

  Exception java.lang.CloneNotSupportedException: net.lingala.zip4j.model.ZipParameters
        at Object.clone (Native Method)
        at ZipParameters.clone (ZipParameters.java:208)
@srikanth-lingala
Copy link
Owner

ZipParameters does not implement Cloneable anymore because Cloneable is generally considered to be broken and not implemented correctly in Java. Instead ZipParameters now has constructor that does exactly that - it creates a new instance of ZipParameters from the input zipParameters. Just call new ZipParameters(zipParameters) where zipParameters is your existing instance that you want to clone.

References:
https://blog.jcranky.com/2009/08/26/why-not-use-java-clone-method/
https://howtodoinjava.com/java/cloning/cloneable-interface-is-broken-in-java/

@jeffrey-easyesi
Copy link
Author

OK; the public clone() override should be removed then as it doesn't work and is just misleading.

@srikanth-lingala
Copy link
Owner

You are right. I will take it out.

@srikanth-lingala
Copy link
Owner

Fixed in v2.11.0 released today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants