Issue #1039: Fix OutOfMemoryError in postProcessCheckstyleReport by r…#1044
Conversation
bae8f59 to
01e42b9
Compare
checkstyle-tester/diff.groovy
Outdated
| writer.writeLine(line.replace(oldPath, newPath)) | ||
| } | ||
| } | ||
| Files.move(tempFile.toPath(), checkstyleResultFile.toPath(), REPLACE_EXISTING) |
There was a problem hiding this comment.
can it be?
import java.nio.file.Files
Files.copy(sourcePath, destPath, StandardCopyOption.REPLACE_EXISTING)
There was a problem hiding this comment.
@romani
Yes, we can but i thought of using Files.move over Files.copy because it automatically removes the temp file after the operation, no manual tempFile.delete() needed. With Files.copy, the temp file remains on disk, if we do not clean. It would be helpful if I could get some clarity on why Files.copy is preferred here.
There was a problem hiding this comment.
No preference. Just tried to use already written standard method.
There was a problem hiding this comment.
Sure will use Files.copy
…eport by replacing whole-file read with line-by-line streaming
01e42b9 to
aac1e8d
Compare
| checkstyleResultFile.text = content | ||
| tempFile.withWriter { writer -> | ||
| checkstyleResultFile.eachLine { line -> | ||
| writer.writeLine(line.replace(oldPath, newPath)) |
There was a problem hiding this comment.
My bad, ....
I started above discussion on this code.
Why we need such custom each line read write?
There was a problem hiding this comment.
it is needed because the original file.text loads the entire file into a single String, which causes OutOfMemoryError for large files, Error we saw earlier, i find eachLine/withWriter as the simplest streaming solution in Groovy that avoids loading the whole file into memory.
Issue #1039:
Fix OutOfMemoryError for large checkstyle-result.xml files by streaming line-by-line instead of loading entire file into memory