Skip to content

8380542: ZipOutputStream.setComment should specify that it throws IllegalArgumentException for unmappable characters#30338

Open
eirbjo wants to merge 4 commits intoopenjdk:masterfrom
eirbjo:zos-setcomment-unmappable
Open

8380542: ZipOutputStream.setComment should specify that it throws IllegalArgumentException for unmappable characters#30338
eirbjo wants to merge 4 commits intoopenjdk:masterfrom
eirbjo:zos-setcomment-unmappable

Conversation

@eirbjo
Copy link
Contributor

@eirbjo eirbjo commented Mar 20, 2026

Please review this PR which updates the specification of ZipOutputStream.setComment(String) to match the long-standing behavior of throwing IllegalArgumentException when a comment contains characters which are unmappable using the Charset passed 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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Change requires CSR request JDK-8380546 to be approved
  • Commit message must refer to an issue

Issues

  • JDK-8380542: ZipOutputStream.setComment should specify that it throws IllegalArgumentException for unmappable characters (Enhancement - P4)
  • JDK-8380546: ZipOutputStream.setComment should specify that it throws IllegalArgumentException for unmappable characters (CSR)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30338/head:pull/30338
$ git checkout pull/30338

Update a local copy of the PR:
$ git checkout pull/30338
$ git pull https://git.openjdk.org/jdk.git pull/30338/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30338

View PR using the GUI difftool:
$ git pr show -t 30338

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30338.diff

Using Webrev

Link to Webrev Comment

…gumentException for unmappable characters in comment
@eirbjo
Copy link
Contributor Author

eirbjo commented Mar 20, 2026

/csr needed

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 20, 2026

👋 Welcome back eirbjo! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Mar 20, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Mar 20, 2026
@openjdk
Copy link

openjdk bot commented Mar 20, 2026

@eirbjo an approved CSR request is already required for this pull request.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Mar 20, 2026
@openjdk
Copy link

openjdk bot commented Mar 20, 2026

@eirbjo The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@eirbjo eirbjo marked this pull request as ready for review March 20, 2026 13:33
@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 20, 2026
@mlbridge
Copy link

mlbridge bot commented Mar 20, 2026

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) {
Copy link
Member

@jaikiran jaikiran Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}
 */

Copy link
Member

@jaikiran jaikiran Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure if accepting null should be a @implSpec or just a formal API specification.

Copy link
Contributor Author

@eirbjo eirbjo Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure if accepting null should be a @implSpec or 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be just part of the specification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be just part of the specification.

Yes, it needs to normative.

import static org.junit.jupiter.api.Assertions.assertThrows;

/* @test
* @bug 8380542
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import for assertDoesNotThrow is unused?

Copy link
Contributor Author

@eirbjo eirbjo Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in 7845c5e!

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

Labels

core-libs core-libs-dev@openjdk.org csr Pull request needs approved CSR before integration rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

5 participants