[Demonstration 1]

[Buggy Method]
public static void saveNoteFile(File file, NoteData data) {
    try {
        Files.write(Paths.get(file.getAbsolutePath()), data.toString().getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

[Buggy Hunk]
Files.write(Paths.get(file.getAbsolutePath()), data.toString().getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);

[Patch]
Files.write(Paths.get(file.getAbsolutePath()), data.toOldFormat().getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);

[Demonstration 2]

[Buggy Method]
public void save(final String name, final String data) throws IOException {
    final Path path = FileSystems.getDefault().getPath(workingDir, name);
    Files.write(path, data.getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
}

[Buggy Hunk]
Files.write(path, data.getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);

[Patch]
Files.write(path, data.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);

[Demonstration 3]

[Buggy Method]
private RepositoryFile createFile(S3ObjectSummary objectSummary) {
    val objectId = objectSummary.getKey();
    val objectFile = new RepositoryFile().setId(context.ensureFileId(objectId)).setObjectId(objectId);
    objectFile.addFileCopy().setFileSize(objectSummary.getSize()).setLastModified(// Seconds
    objectSummary.getLastModified().getTime() / 1000L).setRepoFileId(objectId).setRepoType(server.getType().getId()).setRepoOrg(server.getSource().getId()).setRepoName(server.getName()).setRepoCode(server.getCode()).setRepoCountry(server.getCountry()).setRepoBaseUrl(server.getBaseUrl()).setRepoDataPath(objectSummary.getBucketName() + server.getType().getDataPath() + objectId);
    return objectFile;
}

[Buggy Hunk]
val objectId = objectSummary.getKey();

[Patch]
val objectId = resolveObjectId(objectSummary);