Possible FileHandle leak in BenchmarkGenerator

Alex Blewitt alex.blewitt at gmail.com
Sun May 1 22:42:38 UTC 2016


I was doing a JMH demo (on Windows) using Eclipse’s APT to run the annotation processor, and I kept getting errors about inability to clean the target directory because a file BenchmarkList could not be found. 

Since Windows typically doesn’t let you delete a directory when there’s an open file handle (and it went away after time, such as when a GC had run) I had a look through the codebase to see if I could find where it might occur.

I think the BenchmarkList is generated in the BenchmarkGenerator file:

http://hg.openjdk.java.net/code-tools/jmh/file/eb41bdab96cf/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java#l198

It looks like there’s a potential for the PrintWriter in 199 (v1.12) is created, and then closed; but if an error occurs during the writer.println then the exception will be caught by the surrounding catch block and then leave the writer dangling. I think the writer comes from the APGeneratorDestination (when triggered from Eclipse’s Annotation Processor support) which looks like it will create a file-backed Writer of some description:

http://hg.openjdk.java.net/code-tools/jmh/file/eb41bdab96cf/jmh-generator-annprocess/src/main/java/org/openjdk/jmh/generators/annotations/APGeneratorDestinaton.java#l49

So my questions are:

1. Is my understanding on the right lines for how it works and how a leak may occur?
2. Should I create a bug, and if so, where?
3. Should I contribute a fix, and if so, how?

Thanks,

Alex


More information about the jmh-dev mailing list