Skip to content

8360575: java.util.Properties.list() methods trim each value to 37 characters in the listed output #26018

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/java.base/share/classes/java/util/Properties.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1211,10 +1211,22 @@ public Set<String> stringPropertyNames() {
}

/**
* Prints this property list out to the specified output stream.
* Prints this property list out to the specified {@link PrintStream}.
* This method is useful for debugging.
*
* @param out an output stream.
* @implNote If any property's value is greater than 40 characters then
* this method writes only the first 37 characters of that value
* followed by 3 dot characters.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the note needs to that specific. I think it need only say that the implementation truncates the output for very long property values.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hello Alan, I think not noting the character count which determines the truncation would lead to questions about what "very long property values" are. However, this is a method which is specified to be for debug purposes only and I see that there's a suggestion to deprecate these methods. So I have gone ahead and updated this text to follow your suggestion. I'll respond to the deprecation proposal separately in this PR.

* <p>
* An alternative for listing the {@code Properties} to a {@code PrintStream} is:

Choose a reason for hiding this comment

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

suggestion:
``
An alternative for listing the {@code Properties} to a {@code PrintStream} without truncation is:

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I've now updated the PR with this text.

* {@snippet lang=java :
* Properties p = ...
* PrintStream out = ...
* // list the properties to PrintStream
* p.forEach((k, v) -> out.println(k + "=" + v));
* }
*
* @param out a PrintStream

Choose a reason for hiding this comment

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

suggestion: (here and L1263) "the output PrintStream"

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

* @throws ClassCastException if any key in this property list
* is not a string.
*/
Expand All @@ -1233,10 +1245,22 @@ public void list(PrintStream out) {
}

/**
* Prints this property list out to the specified output stream.
* Prints this property list out to the specified {@link PrintWriter}.
* This method is useful for debugging.
*
* @param out an output stream.
* @implNote If any property's value is greater than 40 characters then
* this method writes only the first 37 characters of that value
* followed by 3 dot characters.
* <p>
* An alternative for listing the {@code Properties} to a {@code PrintWriter} is:
* {@snippet lang=java :
* Properties p = ...
* PrintWriter out = ...
* // list the properties to PrintWriter
* p.forEach((k, v) -> out.println(k + "=" + v));
Copy link
Member

Choose a reason for hiding this comment

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

Should our example recommend using toString as a utility to obtain a debug string instead, as it performs no truncation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Using toString() will be harder to read; as proposed each property is on a separate line.

* }
*
* @param out a PrintWriter
* @throws ClassCastException if any key in this property list
* is not a string.
* @since 1.1
Expand Down