diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml index af3651fc13..ee7d1c5522 100644 --- a/pmd-java/src/main/resources/category/java/performance.xml +++ b/pmd-java/src/main/resources/category/java/performance.xml @@ -120,10 +120,14 @@ public class Test { class="net.sourceforge.pmd.lang.rule.XPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_performance.html#avoidfilestream"> -Use Files.newInputStream(Paths.get(fileName)) instead of new FileInputStream(fileName). -Use Files.newOutputStream(Paths.get(fileName)) instead of new FileOutputStream(fileName). -Use Files.newBufferedReader(Paths.get(fileName)) instead of new FileReader(fileName). -Use Files.newBufferedWriter(Paths.get(fileName)) instead of new FileWriter(fileName). +The FileInputStream and FileOutputStream classes contains a finalizer method which will cause garbage collection pauses. See [JDK-8080225](https://bugs.openjdk.java.net/browse/JDK-8080225) for details. + +The FileReader and FileWriter constructors instantiate FileInputStream and FileOutputStream, again causing garbage collection issues while finalizer methods are called. + +* Use `Files.newInputStream(Paths.get(fileName))` instead of `new FileInputStream(fileName)`. +* Use `Files.newOutputStream(Paths.get(fileName))` instead of `new FileOutputStream(fileName)`. +* Use `Files.newBufferedReader(Paths.get(fileName))` instead of `new FileReader(fileName)`. +* Use `Files.newBufferedWriter(Paths.get(fileName))` instead of `new FileWriter(fileName)`. 1