diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index cd199369..de0fd031 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -875,8 +875,8 @@ public final class CSVFormat implements Serializable { final StringWriter out = new StringWriter(); try (CSVPrinter csvPrinter = new CSVPrinter(out, this)) { csvPrinter.printRecord(values); - String res = out.toString(); - int len = recordSeparator != null ? res.length() - recordSeparator.length() : res.length(); + final String res = out.toString(); + final int len = recordSeparator != null ? res.length() - recordSeparator.length() : res.length(); return res.substring(0, len); } catch (final IOException e) { // should not happen because a StringWriter does not do IO. diff --git a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java index 2628f529..d71007bb 100644 --- a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java @@ -93,7 +93,7 @@ public class CSVFileParserTest { try (final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), Charset.defaultCharset(), format)) { for (final CSVRecord record : parser) { String parsed = Arrays.toString(record.values()); - String comment = record.getComment(); + final String comment = record.getComment(); if (checkComments && comment != null) { parsed += "#" + comment.replace("\n", "\\n"); } @@ -138,7 +138,7 @@ public class CSVFileParserTest { try (final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format)) { for (final CSVRecord record : parser) { String parsed = Arrays.toString(record.values()); - String comment = record.getComment(); + final String comment = record.getComment(); if (checkComments && comment != null) { parsed += "#" + comment.replace("\n", "\\n"); } diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index a31875f8..ded2ab9f 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -1216,14 +1216,14 @@ public class CSVFormatTest { @Test public void testWithHeaderEnumNull() { final CSVFormat format = CSVFormat.DEFAULT; - Class> simpleName = null; + final Class> simpleName = null; format.withHeader(simpleName); } @Test public void testWithHeaderResultSetNull() throws SQLException { final CSVFormat format = CSVFormat.DEFAULT; - ResultSet resultSet = null; + final ResultSet resultSet = null; format.withHeader(resultSet); } @@ -1231,7 +1231,7 @@ public class CSVFormatTest { public void testPrintWithQuoteModeIsNONE() throws IOException { final Reader in = new StringReader("a,b,c"); final Appendable out = new StringBuilder(); - CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NONE); + final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NONE); format.print(in, out, true); assertEquals("a?,b?,c", out.toString()); } @@ -1240,7 +1240,7 @@ public class CSVFormatTest { public void testPrintWithQuotes() throws IOException { final Reader in = new StringReader("\"a,b,c\r\nx,y,z"); final Appendable out = new StringBuilder(); - CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC); + final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC); format.print(in, out, true); assertEquals("\"\"\"\"a,b,c\r\nx,y,z\"", out.toString()); } @@ -1249,14 +1249,14 @@ public class CSVFormatTest { public void testPrintWithoutQuotes() throws IOException { final Reader in = new StringReader(""); final Appendable out = new StringBuilder(); - CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC); + final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC); format.print(in, out, true); assertEquals("\"\"", out.toString()); } @Test public void testTrim() throws IOException { - CSVFormat formatWithTrim = CSVFormat.DEFAULT.withDelimiter(',').withTrim().withQuote(null).withRecordSeparator(CRLF); + final CSVFormat formatWithTrim = CSVFormat.DEFAULT.withDelimiter(',').withTrim().withQuote(null).withRecordSeparator(CRLF); CharSequence in = "a,b,c"; final StringBuilder out = new StringBuilder(); diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java index 7126e9d4..8c8f19a3 100644 --- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java +++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java @@ -1343,7 +1343,7 @@ public class CSVPrinterTest { final CharArrayWriter charArrayWriter = new CharArrayWriter(0); try (final CSVParser parser = CSVFormat.DEFAULT.parse(new StringReader(rowData)); CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) { - for (CSVRecord record : parser) { + for (final CSVRecord record : parser) { csvPrinter.printRecord(record); } } diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java index deef5c6a..11401a07 100644 --- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java +++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java @@ -51,9 +51,9 @@ public class CSVRecordTest { SECOND("second"), THIRD("third"); - private String number; + private final String number; - EnumHeader(String number) { + EnumHeader(final String number) { this.number = number; } diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java index 83fb36fd..38394ba5 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java @@ -35,7 +35,7 @@ public class JiraCsv149Test { testJiraCsv149EndWithEolAtEof(true); } - private void testJiraCsv149EndWithEolAtEof(boolean eolAtEof) throws IOException { + private void testJiraCsv149EndWithEolAtEof(final boolean eolAtEof) throws IOException { String source = "A,B,C,D" + CR_LF + "a1,b1,c1,d1" + CR_LF + "a2,b2,c2,d2"; if (eolAtEof) { source += CR_LF; @@ -44,7 +44,7 @@ public class JiraCsv149Test { final CSVFormat format = CSVFormat.RFC4180.withFirstRecordAsHeader().withQuote('"'); int lineCounter = 2; try (final CSVParser parser = new CSVParser(records, format)) { - for (CSVRecord record : parser) { + for (final CSVRecord record : parser) { assertEquals(lineCounter++, parser.getCurrentLineNumber()); } } diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java index 26dc7021..d341c252 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java @@ -33,12 +33,12 @@ public class JiraCsv211Test { final String[] values = new String[] { "1", "Jane Doe", "USA", "" }; final CSVFormat printFormat = CSVFormat.DEFAULT.withDelimiter('\t').withHeader("ID", "Name", "Country", "Age"); - String formatted = printFormat.format(values); + final String formatted = printFormat.format(values); assertEquals("ID\tName\tCountry\tAge\r\n1\tJane Doe\tUSA\t", formatted); final CSVFormat parseFormat = CSVFormat.DEFAULT.withDelimiter('\t').withFirstRecordAsHeader(); - CSVParser parser = parseFormat.parse(new StringReader(formatted)); - for (CSVRecord record : parser) { + final CSVParser parser = parseFormat.parse(new StringReader(formatted)); + for (final CSVRecord record : parser) { assertEquals("1", record.get(0)); assertEquals("Jane Doe", record.get(1)); assertEquals("USA", record.get(2));