This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git


The following commit(s) were added to refs/heads/master by this push:
     new a36d5bcb Bump commons-parent from 69 to 70
a36d5bcb is described below

commit a36d5bcbb1fc0bdcdd49dca6a607fabb3c4ab857
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Wed May 22 09:43:28 2024 -0400

    Bump commons-parent from 69 to 70
    
    Fix PMD issues for port to PMD 7.1.0
---
 pom.xml                                            |   5 +-
 src/changes/changes.xml                            |   2 +
 .../java/org/apache/commons/csv/CSVFormat.java     | 111 ++++++++++-----------
 src/main/java/org/apache/commons/csv/Lexer.java    |  60 +++++------
 4 files changed, 78 insertions(+), 100 deletions(-)

diff --git a/pom.xml b/pom.xml
index c65214d4..3466ee81 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
   <parent>
     <groupId>org.apache.commons</groupId>
     <artifactId>commons-parent</artifactId>
-    <version>69</version>
+    <version>70</version>
   </parent>
   <artifactId>commons-csv</artifactId>
   <version>1.11.1-SNAPSHOT</version>
@@ -216,9 +216,6 @@
           <configuration>
             <targetJdk>${maven.compiler.target}</targetJdk>
             <skipEmptyReport>false</skipEmptyReport>
-            <rulesets>
-              
<ruleset>${basedir}/src/site/resources/pmd/pmd-ruleset.xml</ruleset>
-            </rulesets>
           </configuration>
         </plugin>
         <!-- We need to add our test data files to rat exclusions -->
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 99b973f9..f6acb87c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -43,8 +43,10 @@
     <release version="1.11.1" date="YYYY-MM-DD" description="Feature and bug 
fix release (Java 8 or above)">
       <!-- ADD -->
       <!-- FIX -->
+      <action type="update" dev="ggregory" due-to="Gary Gregory">Fix PMD 
issues for port to PMD 7.1.0.</action>
       <!-- UPDATE -->
       <action type="update" dev="ggregory" due-to="Dependabot">Bump 
commons-codec:commons-codec from 1.16.1 to 1.17.0 #422.</action>
+      <action type="update" dev="ggregory" due-to="Gary Gregory">Bump 
commons-parent from 69 to 70.</action>
     </release>
     <release version="1.11.0" date="2024-04-28" description="Feature and bug 
fix release (Java 8 or above)">
       <!-- ADD -->
diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java 
b/src/main/java/org/apache/commons/csv/CSVFormat.java
index c2356c54..5c511c60 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -17,17 +17,6 @@
 
 package org.apache.commons.csv;
 
-import static org.apache.commons.csv.Constants.BACKSLASH;
-import static org.apache.commons.csv.Constants.COMMA;
-import static org.apache.commons.csv.Constants.COMMENT;
-import static org.apache.commons.csv.Constants.CR;
-import static org.apache.commons.csv.Constants.CRLF;
-import static org.apache.commons.csv.Constants.DOUBLE_QUOTE_CHAR;
-import static org.apache.commons.csv.Constants.EMPTY;
-import static org.apache.commons.csv.Constants.LF;
-import static org.apache.commons.csv.Constants.PIPE;
-import static org.apache.commons.csv.Constants.SP;
-import static org.apache.commons.csv.Constants.TAB;
 import static org.apache.commons.io.IOUtils.EOF;
 
 import java.io.File;
@@ -203,7 +192,7 @@ public final class CSVFormat implements Serializable {
          * @return a copy of the builder
          */
         public static Builder create() {
-            return new Builder(CSVFormat.DEFAULT);
+            return new Builder(DEFAULT);
         }
 
         /**
@@ -850,57 +839,57 @@ public final class CSVFormat implements Serializable {
         /**
          * @see CSVFormat#DEFAULT
          */
-        Default(CSVFormat.DEFAULT),
+        Default(DEFAULT),
 
         /**
          * @see CSVFormat#EXCEL
          */
-        Excel(CSVFormat.EXCEL),
+        Excel(EXCEL),
 
         /**
          * @see CSVFormat#INFORMIX_UNLOAD
          * @since 1.3
          */
-        InformixUnload(CSVFormat.INFORMIX_UNLOAD),
+        InformixUnload(INFORMIX_UNLOAD),
 
         /**
          * @see CSVFormat#INFORMIX_UNLOAD_CSV
          * @since 1.3
          */
-        InformixUnloadCsv(CSVFormat.INFORMIX_UNLOAD_CSV),
+        InformixUnloadCsv(INFORMIX_UNLOAD_CSV),
 
         /**
          * @see CSVFormat#MONGODB_CSV
          * @since 1.7
          */
-        MongoDBCsv(CSVFormat.MONGODB_CSV),
+        MongoDBCsv(MONGODB_CSV),
 
         /**
          * @see CSVFormat#MONGODB_TSV
          * @since 1.7
          */
-        MongoDBTsv(CSVFormat.MONGODB_TSV),
+        MongoDBTsv(MONGODB_TSV),
 
         /**
          * @see CSVFormat#MYSQL
          */
-        MySQL(CSVFormat.MYSQL),
+        MySQL(MYSQL),
 
         /**
          * @see CSVFormat#ORACLE
          */
-        Oracle(CSVFormat.ORACLE),
+        Oracle(ORACLE),
 
         /**
          * @see CSVFormat#POSTGRESQL_CSV
          * @since 1.5
          */
-        PostgreSQLCsv(CSVFormat.POSTGRESQL_CSV),
+        PostgreSQLCsv(POSTGRESQL_CSV),
 
         /**
          * @see CSVFormat#POSTGRESQL_CSV
          */
-        PostgreSQLText(CSVFormat.POSTGRESQL_TEXT),
+        PostgreSQLText(POSTGRESQL_TEXT),
 
         /**
          * @see CSVFormat#RFC4180
@@ -945,8 +934,8 @@ public final class CSVFormat implements Serializable {
      *
      * @see Predefined#Default
      */
-    public static final CSVFormat DEFAULT = new CSVFormat(COMMA, 
DOUBLE_QUOTE_CHAR, null, null, null, false, true, CRLF, null, null, null, 
false, false, false,
-            false, false, false, DuplicateHeaderMode.ALLOW_ALL, false, false);
+    public static final CSVFormat DEFAULT = new CSVFormat(Constants.COMMA, 
Constants.DOUBLE_QUOTE_CHAR, null, null, null, false, true, Constants.CRLF, 
null,
+            null, null, false, false, false, false, false, false, 
DuplicateHeaderMode.ALLOW_ALL, false, false);
 
     /**
      * Excel file format (using a comma as the value delimiter). Note that the 
actual value delimiter used by Excel is locale-dependent, it might be necessary
@@ -1014,10 +1003,10 @@ public final class CSVFormat implements Serializable {
      */
     // @formatter:off
     public static final CSVFormat INFORMIX_UNLOAD = DEFAULT.builder()
-            .setDelimiter(PIPE)
-            .setEscape(BACKSLASH)
-            .setQuote(DOUBLE_QUOTE_CHAR)
-            .setRecordSeparator(LF)
+            .setDelimiter(Constants.PIPE)
+            .setEscape(Constants.BACKSLASH)
+            .setQuote(Constants.DOUBLE_QUOTE_CHAR)
+            .setRecordSeparator(Constants.LF)
             .build();
     // @formatter:on
 
@@ -1045,9 +1034,9 @@ public final class CSVFormat implements Serializable {
      */
     // @formatter:off
     public static final CSVFormat INFORMIX_UNLOAD_CSV = DEFAULT.builder()
-            .setDelimiter(COMMA)
-            .setQuote(DOUBLE_QUOTE_CHAR)
-            .setRecordSeparator(LF)
+            .setDelimiter(Constants.COMMA)
+            .setQuote(Constants.DOUBLE_QUOTE_CHAR)
+            .setRecordSeparator(Constants.LF)
             .build();
     // @formatter:on
 
@@ -1085,9 +1074,9 @@ public final class CSVFormat implements Serializable {
      */
     // @formatter:off
     public static final CSVFormat MONGODB_CSV = DEFAULT.builder()
-            .setDelimiter(COMMA)
-            .setEscape(DOUBLE_QUOTE_CHAR)
-            .setQuote(DOUBLE_QUOTE_CHAR)
+            .setDelimiter(Constants.COMMA)
+            .setEscape(Constants.DOUBLE_QUOTE_CHAR)
+            .setQuote(Constants.DOUBLE_QUOTE_CHAR)
             .setQuoteMode(QuoteMode.MINIMAL)
             .setSkipHeaderRecord(false)
             .build();
@@ -1122,9 +1111,9 @@ public final class CSVFormat implements Serializable {
      */
     // @formatter:off
     public static final CSVFormat MONGODB_TSV = DEFAULT.builder()
-            .setDelimiter(TAB)
-            .setEscape(DOUBLE_QUOTE_CHAR)
-            .setQuote(DOUBLE_QUOTE_CHAR)
+            .setDelimiter(Constants.TAB)
+            .setEscape(Constants.DOUBLE_QUOTE_CHAR)
+            .setQuote(Constants.DOUBLE_QUOTE_CHAR)
             .setQuoteMode(QuoteMode.MINIMAL)
             .setSkipHeaderRecord(false)
             .build();
@@ -1157,11 +1146,11 @@ public final class CSVFormat implements Serializable {
      */
     // @formatter:off
     public static final CSVFormat MYSQL = DEFAULT.builder()
-            .setDelimiter(TAB)
-            .setEscape(BACKSLASH)
+            .setDelimiter(Constants.TAB)
+            .setEscape(Constants.BACKSLASH)
             .setIgnoreEmptyLines(false)
             .setQuote(null)
-            .setRecordSeparator(LF)
+            .setRecordSeparator(Constants.LF)
             .setNullString(Constants.SQL_NULL_STRING)
             .setQuoteMode(QuoteMode.ALL_NON_NULL)
             .build();
@@ -1196,10 +1185,10 @@ public final class CSVFormat implements Serializable {
      */
     // @formatter:off
     public static final CSVFormat ORACLE = DEFAULT.builder()
-            .setDelimiter(COMMA)
-            .setEscape(BACKSLASH)
+            .setDelimiter(Constants.COMMA)
+            .setEscape(Constants.BACKSLASH)
             .setIgnoreEmptyLines(false)
-            .setQuote(DOUBLE_QUOTE_CHAR)
+            .setQuote(Constants.DOUBLE_QUOTE_CHAR)
             .setNullString(Constants.SQL_NULL_STRING)
             .setTrim(true)
             .setRecordSeparator(System.lineSeparator())
@@ -1235,12 +1224,12 @@ public final class CSVFormat implements Serializable {
      */
     // @formatter:off
     public static final CSVFormat POSTGRESQL_CSV = DEFAULT.builder()
-            .setDelimiter(COMMA)
+            .setDelimiter(Constants.COMMA)
             .setEscape(null)
             .setIgnoreEmptyLines(false)
-            .setQuote(DOUBLE_QUOTE_CHAR)
-            .setRecordSeparator(LF)
-            .setNullString(EMPTY)
+            .setQuote(Constants.DOUBLE_QUOTE_CHAR)
+            .setRecordSeparator(Constants.LF)
+            .setNullString(Constants.EMPTY)
             .setQuoteMode(QuoteMode.ALL_NON_NULL)
             .build();
     // @formatter:off
@@ -1273,11 +1262,11 @@ public final class CSVFormat implements Serializable {
      */
     // @formatter:off
     public static final CSVFormat POSTGRESQL_TEXT = DEFAULT.builder()
-            .setDelimiter(TAB)
-            .setEscape(BACKSLASH)
+            .setDelimiter(Constants.TAB)
+            .setEscape(Constants.BACKSLASH)
             .setIgnoreEmptyLines(false)
             .setQuote(null)
-            .setRecordSeparator(LF)
+            .setRecordSeparator(Constants.LF)
             .setNullString(Constants.SQL_NULL_STRING)
             .setQuoteMode(QuoteMode.ALL_NON_NULL)
             .build();
@@ -1319,7 +1308,7 @@ public final class CSVFormat implements Serializable {
      */
     // @formatter:off
     public static final CSVFormat TDF = DEFAULT.builder()
-            .setDelimiter(TAB)
+            .setDelimiter(Constants.TAB)
             .setIgnoreSurroundingSpaces(true)
             .build();
     // @formatter:on
@@ -1356,7 +1345,7 @@ public final class CSVFormat implements Serializable {
      * @return true if {@code c} contains a line break character.
      */
     private static boolean containsLineBreak(final String source) {
-        return contains(source, CR) || contains(source, LF);
+        return contains(source, Constants.CR) || contains(source, 
Constants.LF);
     }
 
     static boolean isBlank(final String value) {
@@ -1371,7 +1360,7 @@ public final class CSVFormat implements Serializable {
      * @return true if {@code c} is a line break character.
      */
     private static boolean isLineBreak(final char c) {
-        return c == LF || c == CR;
+        return c == Constants.LF || c == Constants.CR;
     }
 
     /**
@@ -1387,7 +1376,7 @@ public final class CSVFormat implements Serializable {
 
     /** Same test as in as {@link String#trim()}. */
     private static boolean isTrimChar(final char ch) {
-        return ch <= SP;
+        return ch <= Constants.SP;
     }
 
     /** Same test as in as {@link String#trim()}. */
@@ -2121,7 +2110,7 @@ public final class CSVFormat implements Serializable {
         if (value == null) {
             // https://issues.apache.org/jira/browse/CSV-203
             if (null == nullString) {
-                charSequence = EMPTY;
+                charSequence = Constants.EMPTY;
             } else if (QuoteMode.ALL == quoteMode) {
                 charSequence = quotedNullString;
             } else {
@@ -2259,8 +2248,8 @@ public final class CSVFormat implements Serializable {
         while (pos < end) {
             char c = charSeq.charAt(pos);
             final boolean isDelimiterStart = isDelimiter(c, charSeq, pos, 
delimArray, delimLength);
-            final boolean isCr = c == CR;
-            final boolean isLf = c == LF;
+            final boolean isCr = c == Constants.CR;
+            final boolean isLf = c == Constants.LF;
             if (isCr || isLf || c == escape || isDelimiterStart) {
                 // write out segment up until this char
                 if (pos > start) {
@@ -2308,8 +2297,8 @@ public final class CSVFormat implements Serializable {
             Arrays.fill(lookAheadBuffer, (char) 0);
             final String test = builder.toString() + new 
String(bufferedReader.lookAhead(lookAheadBuffer));
             final boolean isDelimiterStart = isDelimiter((char) c, test, pos, 
delimArray, delimLength);
-            final boolean isCr = c == CR;
-            final boolean isLf = c == LF;
+            final boolean isCr = c == Constants.CR;
+            final boolean isLf = c == Constants.LF;
             if (isCr || isLf || c == escape || isDelimiterStart) {
                 // write out segment up until this char
                 if (pos > start) {
@@ -2381,7 +2370,7 @@ public final class CSVFormat implements Serializable {
                 }
             } else {
                 char c = charSeq.charAt(pos);
-                if (c <= COMMENT) {
+                if (c <= Constants.COMMENT) {
                     // Some other chars at the start of a value caused the 
parser to fail, so for now
                     // encapsulate if we start in anything less than '#'. We 
are being conservative
                     // by including the default comment char too.
@@ -2389,7 +2378,7 @@ public final class CSVFormat implements Serializable {
                 } else {
                     while (pos < len) {
                         c = charSeq.charAt(pos);
-                        if (c == LF || c == CR || c == quoteChar || c == 
escapeChar || isDelimiter(c, charSeq, pos, delim, delimLength)) {
+                        if (c == Constants.LF || c == Constants.CR || c == 
quoteChar || c == escapeChar || isDelimiter(c, charSeq, pos, delim, 
delimLength)) {
                             quote = true;
                             break;
                         }
diff --git a/src/main/java/org/apache/commons/csv/Lexer.java 
b/src/main/java/org/apache/commons/csv/Lexer.java
index 1ffef81f..d2b9ba6c 100644
--- a/src/main/java/org/apache/commons/csv/Lexer.java
+++ b/src/main/java/org/apache/commons/csv/Lexer.java
@@ -17,16 +17,6 @@
 
 package org.apache.commons.csv;
 
-import static org.apache.commons.csv.Constants.BACKSPACE;
-import static org.apache.commons.csv.Constants.CR;
-import static org.apache.commons.csv.Constants.FF;
-import static org.apache.commons.csv.Constants.LF;
-import static org.apache.commons.csv.Constants.TAB;
-import static org.apache.commons.csv.Constants.UNDEFINED;
-import static org.apache.commons.csv.Token.Type.COMMENT;
-import static org.apache.commons.csv.Token.Type.EORECORD;
-import static org.apache.commons.csv.Token.Type.INVALID;
-import static org.apache.commons.csv.Token.Type.TOKEN;
 import static org.apache.commons.io.IOUtils.EOF;
 
 import java.io.Closeable;
@@ -37,8 +27,8 @@ import java.io.IOException;
  */
 final class Lexer implements Closeable {
 
-    private static final String CR_STRING = Character.toString(CR);
-    private static final String LF_STRING = Character.toString(LF);
+    private static final String CR_STRING = Character.toString(Constants.CR);
+    private static final String LF_STRING = Character.toString(Constants.LF);
 
     /**
      * Constant char to use for disabling comments, escapes, and 
encapsulation. The value -2 is used because it
@@ -202,7 +192,7 @@ final class Lexer implements Closeable {
      * @return true if the character is at the start of a line.
      */
     boolean isStartOfLine(final int ch) {
-        return ch == LF || ch == CR || ch == UNDEFINED;
+        return ch == Constants.LF || ch == Constants.CR || ch == 
Constants.UNDEFINED;
     }
 
     private char mapNullToDisabled(final Character c) {
@@ -257,11 +247,11 @@ final class Lexer implements Closeable {
             }
             final String comment = line.trim();
             token.content.append(comment);
-            token.type = COMMENT;
+            token.type = Token.Type.COMMENT;
             return token;
         }
         // Important: make sure a new char gets consumed in each iteration
-        while (token.type == INVALID) {
+        while (token.type == Token.Type.INVALID) {
             // ignore whitespaces at beginning of a token
             if (ignoreSurroundingSpaces) {
                 while (Character.isWhitespace((char) c) && !isDelimiter(c) && 
!eol) {
@@ -272,11 +262,11 @@ final class Lexer implements Closeable {
             // ok, start of token reached: encapsulated, or token
             if (isDelimiter(c)) {
                 // empty token return TOKEN("")
-                token.type = TOKEN;
+                token.type = Token.Type.TOKEN;
             } else if (eol) {
                 // empty token return EORECORD("")
                 // noop: token.content.append("");
-                token.type = EORECORD;
+                token.type = Token.Type.EORECORD;
             } else if (isQuoteChar(c)) {
                 // consume encapsulated token
                 parseEncapsulatedToken(token);
@@ -334,7 +324,7 @@ final class Lexer implements Closeable {
                     while (true) {
                         c = reader.read();
                         if (isDelimiter(c)) {
-                            token.type = TOKEN;
+                            token.type = Token.Type.TOKEN;
                             return token;
                         }
                         if (isEndOfFile(c)) {
@@ -343,7 +333,7 @@ final class Lexer implements Closeable {
                             return token;
                         }
                         if (readEndOfLine(c)) {
-                            token.type = EORECORD;
+                            token.type = Token.Type.EORECORD;
                             return token;
                         }
                         if (trailingData) {
@@ -406,7 +396,7 @@ final class Lexer implements Closeable {
         // Faster to use while(true)+break than while(token.type == INVALID)
         while (true) {
             if (readEndOfLine(ch)) {
-                token.type = EORECORD;
+                token.type = Token.Type.EORECORD;
                 break;
             }
             if (isEndOfFile(ch)) {
@@ -415,7 +405,7 @@ final class Lexer implements Closeable {
                 break;
             }
             if (isDelimiter(ch)) {
-                token.type = TOKEN;
+                token.type = Token.Type.TOKEN;
                 break;
             }
             // continue
@@ -450,7 +440,7 @@ final class Lexer implements Closeable {
      */
     boolean readEndOfLine(int ch) throws IOException {
         // check if we have \r\n...
-        if (ch == CR && reader.lookAhead() == LF) {
+        if (ch == Constants.CR && reader.lookAhead() == Constants.LF) {
             // note: does not change ch outside of this method!
             ch = reader.read();
             // Save the EOL state
@@ -460,14 +450,14 @@ final class Lexer implements Closeable {
         }
         // save EOL state here.
         if (firstEol == null) {
-            if (ch == LF) {
+            if (ch == Constants.LF) {
                 this.firstEol = LF_STRING;
-            } else if (ch == CR) {
+            } else if (ch == Constants.CR) {
                 this.firstEol = CR_STRING;
             }
         }
 
-        return ch == LF || ch == CR;
+        return ch == Constants.LF || ch == Constants.CR;
     }
 
     // TODO escape handling needs more work
@@ -487,20 +477,20 @@ final class Lexer implements Closeable {
         final int ch = reader.read();
         switch (ch) {
         case 'r':
-            return CR;
+            return Constants.CR;
         case 'n':
-            return LF;
+            return Constants.LF;
         case 't':
-            return TAB;
+            return Constants.TAB;
         case 'b':
-            return BACKSPACE;
+            return Constants.BACKSPACE;
         case 'f':
-            return FF;
-        case CR:
-        case LF:
-        case FF: // TODO is this correct?
-        case TAB: // TODO is this correct? Do tabs need to be escaped?
-        case BACKSPACE: // TODO is this correct?
+            return Constants.FF;
+        case Constants.CR:
+        case Constants.LF:
+        case Constants.FF: // TODO is this correct?
+        case Constants.TAB: // TODO is this correct? Do tabs need to be 
escaped?
+        case Constants.BACKSPACE: // TODO is this correct?
             return ch;
         case EOF:
             throw new IOException("EOF whilst processing escape sequence");

Reply via email to