Skip to content

Commit 23c3b66

Browse files
authored
Flush writer after writing generated code (#5919)
BufferedWriter is created in a try-with-resources, so it is always closed, but closing the writer does not actually flush the output stream; it just flushes the remaining data *buffered* in BufferedWriter to the stream: https://github.com/openjdk/jdk/blob/3c72c04de7a43d265dae7160fe53baaaa8ae6f73/src/java.base/share/classes/java/io/BufferedWriter.java#L311-L322 We still need to call BufferedWriter#flush() explicitly so that the output stream is flushed: https://github.com/openjdk/jdk/blob/3c72c04de7a43d265dae7160fe53baaaa8ae6f73/src/java.base/share/classes/java/io/BufferedWriter.java#L298-L308 This should hopefully fix issues where CodeWriter#validateFileContentMatches fails when comparing contents because the file on disk is truncated.
1 parent cd04b47 commit 23c3b66

File tree

1 file changed

+1
-0
lines changed
  • codegen/src/main/java/software/amazon/awssdk/codegen/emitters

1 file changed

+1
-0
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/CodeWriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public void flush() {
119119
if (fileSize(outputFile) == 0) {
120120
try (BufferedWriter writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) {
121121
writer.write(formattedContents);
122+
writer.flush();
122123
}
123124
} else {
124125
validateFileContentMatches(outputFile, formattedContents);

0 commit comments

Comments
 (0)