8380542: ZipOutputStream.setComment should specify that it throws IllegalArgumentException for unmappable characters#30338
Conversation
…gumentException for unmappable characters in comment
|
/csr needed |
|
👋 Welcome back eirbjo! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
Webrevs
|
| * ZIP file comment is greater than 0xFFFF bytes | ||
| * ZIP file comment is greater than 0xFFFF bytes or if the | ||
| * comment contains characters not mappable using the Charset | ||
| * passed to the constructor of this ZipOutputStream instance. | ||
| */ | ||
| public void setComment(String comment) { |
There was a problem hiding this comment.
Given what this method currently does and the class level specification which states that "unless otherwise noted" a NullPointerException gets thrown if null if passed for method params, I think we might have to update this documentation like:
/**
* Sets the ZIP file comment.
*
* @implSpec Passing {@code null} for {@code comment} will result in
* the ZIP file having no comment.
*
* @param comment the comment string, can be {@code null}
* @throws IllegalArgumentException if the length of the specified
* ZIP file comment is greater than 0xFFFF bytes or if the
* {@code comment} contains characters that cannot be mapped
* by the {@code Charset} of this {@code ZipOutputStream}
*/
There was a problem hiding this comment.
I am unsure if accepting null should be a @implSpec or just a formal API specification.
There was a problem hiding this comment.
I am unsure if accepting
nullshould be a@implSpecor just a formal API specification.
Me too. It's not like a subclass can affect the comment though other means than this method. One could imagine a subclass that filters or rejects comments. The distinction between these different spec levels is not super clear to me.
Perhaps other reviewers have opinions.
I'll update the PR to your suggestion in any case - that way we have something to base our discussion on.
There was a problem hiding this comment.
I think this can be just part of the specification.
There was a problem hiding this comment.
I replaced the @implSpec with a note on the comment param. Here I also mention that passing the empty string and null have equivalent effect:
* @param comment the comment string. Passing {@code null} or the empty string
* will result in the output having no ZIP file comment
Have a look and let me know how you think this works.
There was a problem hiding this comment.
I think this can be just part of the specification.
Yes, it needs to normative.
…to null or the empty string to produce no ZIP file comment
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| /* @test | ||
| * @bug 8380542 |
There was a problem hiding this comment.
Seeing this is a spec update, not a bug, should I remove the @bug tag here?
| import java.util.zip.ZipOutputStream; | ||
|
|
||
| import static java.io.OutputStream.nullOutputStream; | ||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
There was a problem hiding this comment.
Import for assertDoesNotThrow is unused?
Please review this PR which updates the specification of
ZipOutputStream.setComment(String)to match the long-standing behavior of throwingIllegalArgumentExceptionwhen a comment contains characters which are unmappable using theCharsetpassed in the constructor.A new tests is added to reproduce calling setComment with unmappable characters and verify that it throws IAE.
A CSR has been drafted. Its specification section will be updated after an initial round of review of the specification text in this PR.
Progress
Issues
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30338/head:pull/30338$ git checkout pull/30338Update a local copy of the PR:
$ git checkout pull/30338$ git pull https://git.openjdk.org/jdk.git pull/30338/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 30338View PR using the GUI difftool:
$ git pr show -t 30338Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30338.diff
Using Webrev
Link to Webrev Comment