On Mon, 30 Nov 2026 20:27:12 GMT, Sean Coffey <[email protected]> wrote:

> This patch overrides toString() in FileInputStream, FileOutputStream, and 
> RandomAccessFile to return the file's base name followed by its identity 
> hash. It follows similar changes made a few years ago for ZipFile 
> (JDK-8319626). 
> 
> Filename retrieval shares the existing File.getName() logic, while streams 
> constructed from a file descriptor retain their previous behaviour.
> 
> ---------
> - [X] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

src/java.base/share/classes/java/io/FileInputStream.java line 537:

> 535:                 + "@" + 
> Integer.toHexString(System.identityHashCode(this))
> 536:                 : super.toString();
> 537:     }

I think it's useful for FIS/FOS/RAF to have a toString implementation for 
debugging purposes. In the ZipFile::toString we agreed to put "for debugging" 
in the method description to set the expectation for how it should be used.

The downside with name@identityHashCode is that it it might look like a class 
name in the unnamed package as it's the same format as Object::toString. So 
maybe think about  "[name=<file>]@identityHashCode" or something better. 
Looking at ZipFile::toString now makes me wonder if we should adjust that too.

For implementation then using `new File(path).getName()` should be okay to 
avoid touching java.io.File. The use of FiS::toString should be for debugging 
purposes so there is no concern that this has to re-normalize and creating a 
File object.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/34137#discussion_r4751800123

Reply via email to