Bump spotbugs-maven-plugin from 4.2.3 to 4.3.0.

Fix SpotBugs Errors
- Error: Medium: org.apache.commons.csv.CSVParser.getHeaderNames() may
expose internal representation by returning CSVParser.headerNames
[org.apache.commons.csv.CSVParser] At CSVParser.java:[line 599]
EI_EXPOSE_REP
- Error: Medium: new org.apache.commons.csv.CSVParser(Reader, CSVFormat,
long, long) may expose internal representation by storing an externally
mutable object into CSVParser.format [org.apache.commons.csv.CSVParser]
At CSVParser.java:[line 433] EI_EXPOSE_REP2
- Error: Medium: new org.apache.commons.csv.CSVParser(Reader, CSVFormat,
long, long) may expose internal representation by storing an externally
mutable object into CSVParser.headerMap
[org.apache.commons.csv.CSVParser] At CSVParser.java:[line 437]
EI_EXPOSE_REP2
- Error: Medium: new org.apache.commons.csv.CSVParser(Reader, CSVFormat,
long, long) may expose internal representation by storing an externally
mutable object into CSVParser.headerNames
[org.apache.commons.csv.CSVParser] At CSVParser.java:[line 438]
EI_EXPOSE_REP2
- Error: Medium: new org.apache.commons.csv.CSVPrinter(Appendable,
CSVFormat) may expose internal representation by storing an externally
mutable object into CSVPrinter.format
[org.apache.commons.csv.CSVPrinter] At CSVPrinter.java:[line 100]
EI_EXPOSE_REP2

Suppresss SpotBugs Errors:
- Error: Medium: org.apache.commons.csv.CSVFormat$Predefined.getFormat()
may expose internal representation by returning
CSVFormat$Predefined.format [org.apache.commons.csv.CSVFormat$Predefined]
At CSVFormat.java:[line 758] EI_EXPOSE_REP
- Error: Medium: org.apache.commons.csv.CSVParser.iterator() may expose
internal representation by returning CSVParser.csvRecordIterator
[org.apache.commons.csv.CSVParser] At CSVParser.java:[line 690]
EI_EXPOSE_REP
- Error: Medium: org.apache.commons.csv.CSVRecord.getParser() may expose
internal representation by returning CSVRecord.parser
[org.apache.commons.csv.CSVRecord] At CSVRecord.java:[line 171]
EI_EXPOSE_REP
This commit is contained in:
Gary Gregory 2021-07-14 11:29:27 -04:00
parent bda783580a
commit a2ba9b5288
6 changed files with 47 additions and 19 deletions

View File

@ -174,7 +174,7 @@
<commons.pmd.version>3.14.0</commons.pmd.version>
<commons.pmd-impl.version>6.36.0</commons.pmd-impl.version>
<commons.jacoco.version>0.8.7</commons.jacoco.version>
<commons.spotbugs.version>4.2.3</commons.spotbugs.version>
<commons.spotbugs.version>4.3.0</commons.spotbugs.version>
<commons.japicmp.version>0.15.3</commons.japicmp.version>
<commons.javadoc.version>3.3.0</commons.javadoc.version>
<biz.aQute.bndlib.version>5.3.0</biz.aQute.bndlib.version>

View File

@ -66,6 +66,11 @@
<action issue="CSV-283" type="fix" dev="ggregory" due-to="belugabehr">Remove Whitespace Check Determines Delimiter Twice #167.</action>
<action issue="CSV-283" type="fix" dev="ggregory" due-to="belugabehr">Document and Automate CSV Benchmark Harness #166.</action>
<action issue="CSV-279" type="fix" dev="ggregory" due-to="belugabehr">Optimize Lexer Delimiter Check for One Character Delimiter #163.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">SpotBugs Error: Medium: org.apache.commons.csv.CSVParser.getHeaderNames() may expose internal representation by returning CSVParser.headerNames [org.apache.commons.csv.CSVParser] At CSVParser.java:[line 599] EI_EXPOSE_REP.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">SpotBugs Error: Medium: new org.apache.commons.csv.CSVParser(Reader, CSVFormat, long, long) may expose internal representation by storing an externally mutable object into CSVParser.format [org.apache.commons.csv.CSVParser] At CSVParser.java:[line 433] EI_EXPOSE_REP2.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">SpotBugs Error: Medium: new org.apache.commons.csv.CSVParser(Reader, CSVFormat, long, long) may expose internal representation by storing an externally mutable object into CSVParser.headerMap [org.apache.commons.csv.CSVParser] At CSVParser.java:[line 437] EI_EXPOSE_REP2.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">SpotBugs Error: Medium: new org.apache.commons.csv.CSVParser(Reader, CSVFormat, long, long) may expose internal representation by storing an externally mutable object into CSVParser.headerNames [org.apache.commons.csv.CSVParser] At CSVParser.java:[line 438] EI_EXPOSE_REP2.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">SpotBugs Error: Medium: new org.apache.commons.csv.CSVPrinter(Appendable, CSVFormat) may expose internal representation by storing an externally mutable object into CSVPrinter.format [org.apache.commons.csv.CSVPrinter] At CSVPrinter.java:[line 100] EI_EXPOSE_REP2.</action>
<!-- ADD -->
<action issue="CSV-275" type="add" dev="ggregory" due-to="Michael Wyraz, Gary Gregory">Make CSVRecord#toList() public.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add CSVRecord#stream().</action>
@ -90,7 +95,7 @@
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump checkstyle from 8.29 to 8.44.</action>
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump junit-jupiter from 5.7.0 to 5.8.0-M1 #133, #149.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons.jacoco.version from 0.8.5 to 0.8.7 (Java 16).</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons.spotbugs.version from 4.0.4 to 4.2.3 (Java 16).</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons.spotbugs.version from 4.0.4 to 4.3.0 (Java 16).</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump maven-javadoc-plugin from 3.2.0 to 3.3.0.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump jmh-generator-annprocess from 1.5.2 to 1.32 #151.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump PMD core from 6.29.0 to 6.36.0.</action>

View File

@ -1396,6 +1396,15 @@ public final class CSVFormat implements Serializable {
return Builder.create(this);
}
/**
* Creates a copy of this instance.
*
* @return a copy of this instance.
*/
CSVFormat copy() {
return builder().build();
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {

View File

@ -355,11 +355,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
private final CSVFormat format;
/** A mapping of column names to column indices */
private final Map<String, Integer> headerMap;
/** The column order to avoid re-computing it. */
private final List<String> headerNames;
private final Headers headers;
private final Lexer lexer;
@ -430,12 +426,10 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
Objects.requireNonNull(reader, "reader");
Objects.requireNonNull(format, "format");
this.format = format;
this.format = format.copy();
this.lexer = new Lexer(format, new ExtendedBufferedReader(reader));
this.csvRecordIterator = new CSVRecordIterator();
final Headers headers = createHeaders();
this.headerMap = headers.headerMap;
this.headerNames = headers.headerNames;
this.headers = createHeaders();
this.characterOffset = characterOffset;
this.recordNumber = recordNumber - 1;
}
@ -566,11 +560,11 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
* @return a copy of the header map.
*/
public Map<String, Integer> getHeaderMap() {
if (this.headerMap == null) {
if (this.headers.headerMap == null) {
return null;
}
final Map<String, Integer> map = createEmptyHeaderMap();
map.putAll(this.headerMap);
map.putAll(this.headers.headerMap);
return map;
}
@ -580,7 +574,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
* @return the header map.
*/
Map<String, Integer> getHeaderMapRaw() {
return this.headerMap;
return this.headers.headerMap;
}
/**
@ -596,7 +590,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
* @since 1.7
*/
public List<String> getHeaderNames() {
return headerNames;
return Collections.unmodifiableList(headers.headerNames);
}
/**

View File

@ -97,7 +97,7 @@ public final class CSVPrinter implements Flushable, Closeable {
Objects.requireNonNull(format, "format");
this.appendable = appendable;
this.format = format;
this.format = format.copy();
// 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.getHeaderComments() != null) {

View File

@ -20,12 +20,32 @@
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
<!-- Deliberate switch statement fall-through. -->
<Match>
<Class name="org.apache.commons.csv.CSVPrinter" />
<Method name="printComment" >
<!-- Deliberate switch statement fall-through -->
</Method>
<Method name="printComment" />
<Bug code="SF" />
</Match>
<!-- A format is immutable. -->
<Match>
<Class name="org.apache.commons.csv.CSVFormat$Predefined" />
<Method name="getFormat" />
<Bug pattern="EI_EXPOSE_REP"/>
</Match>
<!-- Should not have called this method iterator() since it returns the current iterator and not a new one. -->
<Match>
<Class name="org.apache.commons.csv.CSVParser" />
<Method name="iterator" />
<Bug pattern="EI_EXPOSE_REP"/>
</Match>
<!-- Could make package private in the next major version. -->
<Match>
<Class name="org.apache.commons.csv.CSVRecord" />
<Method name="getParser" />
<Bug pattern="EI_EXPOSE_REP"/>
</Match>
</FindBugsFilter>