Skip to content

Commit aac1e8d

Browse files
committed
Issue #1039: Fix OutOfMemoryError in postProcessCheckstyleReport by replacing whole-file read with line-by-line streaming
1 parent 074d25a commit aac1e8d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

checkstyle-tester/diff.groovy

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,15 @@ def postProcessCheckstyleReport(targetDir, repoName, repoPath) {
710710
def checkstyleResultFile = new File(getOsSpecificPath("$targetDir", "checkstyle-result.xml"))
711711
def oldPath = new File(getOsSpecificPath("src", "main", "java", "$repoName")).absolutePath
712712
def newPath = getOsSpecificPath("$repoPath")
713+
def tempFile = Files.createTempFile("temp", ".xml").toFile()
713714

714-
def content = checkstyleResultFile.text
715-
content = content.replace(oldPath, newPath)
716-
checkstyleResultFile.text = content
715+
tempFile.withWriter { writer ->
716+
checkstyleResultFile.eachLine { line ->
717+
writer.writeLine(line.replace(oldPath, newPath))
718+
}
719+
}
720+
Files.copy(tempFile.toPath(), checkstyleResultFile.toPath(), REPLACE_EXISTING)
721+
tempFile.delete()
717722
}
718723

719724
def copyDir(source, destination) {

0 commit comments

Comments
 (0)