====================Info Start============================
{
"id": 10,
"repo_name": "commons-csv",
"Commit URL":
"https://github.com/apache/commons-csv/commit/1282503fb97d621b4225bd031757adbfada66
181?diff=split",
"Issue URL": "https://issues.apache.org/jira/browse/CSV-120",
"language": "Java"
}
====================Info End====================================
====================Additional Info End====================================
For the Code Change area ,
Line of Code starting with "+" represents that the line is REMOVED.
Line of Code starting with "-" represents that the line is ADDED.
While extracting for desired refinement code please be careful in choosing the
right line of code.
Error types = [ code logic , best practice , code quality , security ]
====================Additional Info End====================================
====================Commit Message Start====================================
<action issue="CSV-120" type="add" dev="ggregory" due-to="Sergei Lebe… …
dev">CSVFormat#withHeader doesn't work with CSVPrinter</action>git-svn-id:
https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1601517 13f79535-47bb-
0310-9956-ffa450edef68
====================Commit Message End====================================
====================Code Change Start====================================
diff --git a/src/main/java/org/apache/commons/csv/CSVPrinter.java
b/src/main/java/org/apache/commons/csv/CSVPrinter.java
index d2968b5..94e5852 100644
--- a/src/main/java/org/apache/commons/csv/CSVPrinter.java
+++ b/src/main/java/org/apache/commons/csv/CSVPrinter.java
@@ -67,9 +67,6 @@ public final class CSVPrinter implements Flushable, Closeable {
this.format.validate();
// TODO: Is it a good idea to do this here instead of on the first call to
a print method?
// It seems a pain to have to track whether the header has already been
printed or not.
- if (format.getHeader() != null) {
- this.printRecord((Object[]) format.getHeader());
- }
}
// ======================================================
====================Code Change End====================================
====================Additional Info Start====================================
{
"Do you want to reject this annotation": {
"options": [
"1. Yes",
"2. No"
],
"answer": "2"
},
"Does the code have a valid bug": {
"options": [
"1. Yes",
"2. No"
],
"answer": "1"
},
"Is the provided refinement correct": {
"options": [
"1. Correct",
"2. Not Correct",
"3. Partially Correct"
],
"answer": "1"
},
"Annotator Name": "aprajit.10",
"Time taken to annotate (in mins)": "56"
}
====================Additional Info End====================================
====================Debug Prompt Start====================================
Find the error in the following code.
====================Debug Prompt End=====================================
====================Error Type Start====================================
code logic
====================Error Type End=====================================
====================Error Explanation Start====================================
The `CSVPrinter` class creates a printer that will print values to the given stream
following the CSV format. In this code, the `format` having header is getting
validated. The code does not automatically print the header, and it will be
printed only when the first record is printed. This is because the
`CSVFormat.withHeader` does not work with `CSVPrinter` and only works with
`CSVParser`.
====================Error Explanation End====================================
===================Refinement Summary Start====================================
After the validation of `format`, an `if` condition is added in the code to check
if the `CSVFormat` has a header, and it automatically prints the header using
`printRecord` if a header is present. This will ensure that the header will be
printed automatically when creating a new `CSVPrinter` instance.
===================Refinement Summary End====================================
===================Desired Refinement Code
Start====================================
src/main/java/org/apache/commons/csv/CSVPrinter.java
```
@@ -67,9 +67,6 @@ public final class CSVPrinter implements Flushable, Closeable {
this.format.validate();
// TODO: Is it a good idea to do this here instead of on the first call to
a print method?
// It seems a pain to have to track whether the header has already been
printed or not.
if (format.getHeader() != null) {
this.printRecord((Object[]) format.getHeader());
}
}
// ======================================================
```
===================Desired Refinement Code End ====================================
===================Alternative Refinement Summary
Start=================================
===================Alternative Refinement Summary
End====================================
===================Alternative Refinement Code
Start====================================
===================Alternative Refinement Code
End====================================