jshell (tests?) leaking files in /tmp

Jonathan Gibbons jonathan.gibbons at oracle.com
Tue Aug 2 20:12:59 UTC 2016

I note that Files.createTempDirectory says this:
> As with the |createTempFile| methods, this method is only part of a 
> temporary-file facility. A |shutdown-hook| 
> <http://download.java.net/java/jdk9/docs/api/java/lang/Runtime.html#addShutdownHook-java.lang.Thread->, 
> or the |File.deleteOnExit()| 
> <http://download.java.net/java/jdk9/docs/api/java/io/File.html#deleteOnExit--> 
> mechanism may be used to delete the directory automatically. 
That being said, it would think it is better to avoid using 
Files.createTempDirectory, and to then use the favor of createTempFile 
that creates files directly in the default temporary directory, and to 
explicitly delete the file when it is no longer required.

public staticPath  <http://download.java.net/java/jdk9/docs/api/java/nio/file/Path.html>  createTempFile(String  <http://download.java.net/java/jdk9/docs/api/java/lang/String.html>  prefix,
                                   String  <http://download.java.net/java/jdk9/docs/api/java/lang/String.html>  suffix,
                                   FileAttribute  <http://download.java.net/java/jdk9/docs/api/java/nio/file/attribute/FileAttribute.html><?>... attrs)
                            throwsIOException  <http://download.java.net/java/jdk9/docs/api/java/io/IOException.html>

-- Jon

On 08/02/2016 01:03 PM, Andrei Eremeev wrote:
>   According to source code of JShell, a new temp file is created in ExternalEditor when a code snippet is modified.
> jdk.internal.jshell.tool.ExternalEditor.java:
> method setupWatch:
>      this.dir = Files.createTempDirectory("jshelltemp");
>      this.tmpfile = Files.createTempFile(dir, null, ".edit");
> The created file is not removed.
> I reproduced the problem with vim:
> int h = 10;
> /set editor vim
> /edit h
> A file is created in tmp if /edit is executed.
> Best regards,
> Andrei Eremeev
>> Tuesday, August  2, 2016 8:43 PM +03:00 from Jonathan Gibbons <jonathan.gibbons at oracle.com>:
>> On 08/02/2016 10:37 AM, Jonathan Gibbons wrote:
>>> A simple script to execute the jshell tests one at a time, and to
>>> check the /tmp directory after executing each test, shows that the
>>> culprit is ToolretainTest.java
>>> I'll file a bug.
>>> -- Jon
>> https://bugs.openjdk.java.net/browse/JDK-8162989

More information about the kulla-dev mailing list