Skip to content

Commit

Permalink
Fix SpotBugs errors
Browse files Browse the repository at this point in the history
- [ERROR] Medium: org.apache.commons.io.IOExceptionList.getCauseList()
may expose internal representation by returning
IOExceptionList.causeList [org.apache.commons.io.IOExceptionList] At
IOExceptionList.java:[line 118] EI_EXPOSE_REP
- [ERROR] Medium:
org.apache.commons.io.IOExceptionList.getCauseList(Class) may expose
internal representation by returning IOExceptionList.causeList
[org.apache.commons.io.IOExceptionList] At IOExceptionList.java:[line
129] EI_EXPOSE_REP
  • Loading branch information
garydgregory committed Nov 23, 2023
1 parent 05e745f commit 4a3e4f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="fix" due-to="Gary Gregory">Fix SpotBugs error: Class org.apache.commons.io.monitor.FileAlterationObserver defines non-transient non-serializable instance field fileFilter [org.apache.commons.io.monitor.FileAlterationObserver] In FileAlterationObserver.java SE_BAD_FIELD.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Fix SpotBugs error: Class org.apache.commons.io.monitor.FileAlterationObserver defines non-transient non-serializable instance field listeners [org.apache.commons.io.monitor.FileAlterationObserver] In FileAlterationObserver.java SE_BAD_FIELD.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Fix SpotBugs error: org.apache.commons.io.FileCleaningTracker.getDeleteFailures() may expose internal representation by returning FileCleaningTracker.deleteFailures [org.apache.commons.io.FileCleaningTracker] At FileCleaningTracker.java:[line 218] EI_EXPOSE_REP.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Fix SpotBugs error: org.apache.commons.io.IOExceptionList.getCauseList() may expose internal representation by returning IOExceptionList.causeList [org.apache.commons.io.IOExceptionList] At IOExceptionList.java:[line 118] EI_EXPOSE_REP.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Fix SpotBugs error: org.apache.commons.io.IOExceptionList.getCauseList(Class) may expose internal representation by returning IOExceptionList.causeList [org.apache.commons.io.IOExceptionList] At IOExceptionList.java:[line 129] EI_EXPOSE_REP.</action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Gary Gregory">Bump org.codehaus.mojo:exec-maven-plugin from 3.1.0 to 3.1.1 #512.</action>
<action dev="ggregory" type="update" due-to="Gary Gregory">Bump commons-lang3 from 3.13.0 to 3.14.0.</action>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/apache/commons/io/IOExceptionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.commons.io;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -115,7 +116,7 @@ public <T extends Throwable> T getCause(final int index, final Class<T> clazz) {
* @return The list of causes.
*/
public <T extends Throwable> List<T> getCauseList() {
return (List<T>) causeList;
return (List<T>) new ArrayList<>(causeList);
}

/**
Expand All @@ -126,7 +127,7 @@ public <T extends Throwable> List<T> getCauseList() {
* @return The list of causes.
*/
public <T extends Throwable> List<T> getCauseList(final Class<T> clazz) {
return (List<T>) causeList;
return (List<T>) new ArrayList<>(causeList);
}

@Override
Expand Down

0 comments on commit 4a3e4f2

Please sign in to comment.