0% found this document useful (0 votes)
11 views4 pages

Java_Java10commonscsv

The document details a commit to the Apache Commons CSV project addressing issue CSV-120, where the CSVFormat#withHeader functionality was not working with CSVPrinter. The code change involved adding logic to automatically print the header if present during the creation of a new CSVPrinter instance. The error identified was related to code logic, and the proposed refinement was deemed correct.

Uploaded by

goutam_dutta123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Java_Java10commonscsv

The document details a commit to the Apache Commons CSV project addressing issue CSV-120, where the CSVFormat#withHeader functionality was not working with CSVPrinter. The code change involved adding logic to automatically print the header if present during the creation of a new CSVPrinter instance. The error identified was related to code logic, and the proposed refinement was deemed correct.

Uploaded by

goutam_dutta123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

====================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====================================

You might also like