Merge remote-tracking branch 'origin/master' into feature/RAT-369
diff --git a/apache-rat-core/spotbugs_ignore.xml b/apache-rat-core/spotbugs_ignore.xml
new file mode 100644
index 0000000..f6a55af
--- /dev/null
+++ b/apache-rat-core/spotbugs_ignore.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<FindBugsFilter>
+  <Match>
+    <!-- Uses tryWithResources, thus closes resource properly:
+    [ERROR] Medium: org.apache.rat.configuration.builders.ChildContainerBuilder.setResource(String) may fail to close stream
+    [org.apache.rat.configuration.builders.ChildContainerBuilder] At ChildContainerBuilder.java:[line 62] OS_OPEN_STREAM
+  -->
+    <Class name="org.apache.rat.configuration.builders.ChildContainerBuilder"/>
+    <Bug pattern="OS_OPEN_STREAM"/>
+  </Match>
+</FindBugsFilter>
diff --git a/apache-rat-core/src/main/java/org/apache/rat/Report.java b/apache-rat-core/src/main/java/org/apache/rat/Report.java
index 6f49556..c69b3f2 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/Report.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/Report.java
@@ -277,7 +277,7 @@
                 if (url == null) {
                     ioSupplier = () -> Files.newInputStream(Paths.get(style[0]));
                 } else {
-                    ioSupplier = () -> url.openStream();
+                    ioSupplier = url::openStream;
                 }
                 configuration.setStyleSheet(ioSupplier);
             }
@@ -332,8 +332,7 @@
     }
 
     static Options buildOptions() {
-        String licFilterValues = String.join(", ", 
-                Arrays.stream(LicenseFilter.values()).map(LicenseFilter::name).collect(Collectors.toList()));
+        String licFilterValues = Arrays.stream(LicenseFilter.values()).map(LicenseFilter::name).collect(Collectors.joining(", "));
 
         Options opts = new Options()
         .addOption(Option.builder().longOpt(DRY_RUN)
diff --git a/apache-rat-core/src/main/java/org/apache/rat/annotation/AbstractLicenseAppender.java b/apache-rat-core/src/main/java/org/apache/rat/annotation/AbstractLicenseAppender.java
index c1c7af9..0d21264 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/annotation/AbstractLicenseAppender.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/annotation/AbstractLicenseAppender.java
@@ -30,6 +30,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Writer;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
@@ -287,7 +288,7 @@
         BufferedReader br = null;
         try {
             fis = new FileInputStream(document);
-            br = new BufferedReader(new InputStreamReader(new BOMInputStream(fis)));
+            br = new BufferedReader(new InputStreamReader(new BOMInputStream(fis), StandardCharsets.UTF_8));
 
             if (!expectsHashPling
                     && !expectsAtEcho
diff --git a/apache-rat-core/src/main/java/org/apache/rat/api/ContentType.java b/apache-rat-core/src/main/java/org/apache/rat/api/ContentType.java
index d5a2a0c..d0e8991 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/api/ContentType.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/api/ContentType.java
@@ -18,6 +18,7 @@
  */
 package org.apache.rat.api;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -72,6 +73,6 @@
      * @return not null
      */
     public Map<String, String> getParameters() {
-        return parameters;
+        return Collections.unmodifiableMap(parameters);
     }
 }
diff --git a/apache-rat-core/src/main/java/org/apache/rat/document/impl/ArchiveEntryDocument.java b/apache-rat-core/src/main/java/org/apache/rat/document/impl/ArchiveEntryDocument.java
index f316fe6..f9b7f17 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/document/impl/ArchiveEntryDocument.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/document/impl/ArchiveEntryDocument.java
@@ -25,6 +25,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.rat.api.Document;
 import org.apache.rat.api.MetaData;
@@ -60,7 +61,7 @@
     }
 
     public Reader reader() throws IOException {
-        return new InputStreamReader(new ByteArrayInputStream(contents));
+        return new InputStreamReader(new ByteArrayInputStream(contents), StandardCharsets.UTF_8);
     }
 
 
diff --git a/apache-rat-core/src/main/java/org/apache/rat/document/impl/FileDocument.java b/apache-rat-core/src/main/java/org/apache/rat/document/impl/FileDocument.java
index d8d3232..d6509bc 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/document/impl/FileDocument.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/document/impl/FileDocument.java
@@ -24,6 +24,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 
 import org.apache.rat.api.Document;
 import org.apache.rat.api.MetaData;
@@ -61,7 +63,7 @@
     }    
     
     public InputStream inputStream() throws IOException {
-        return new FileInputStream(file);
+        return Files.newInputStream(file.toPath());
     }
 
     /**
diff --git a/apache-rat-core/src/main/java/org/apache/rat/document/impl/MonolithicFileDocument.java b/apache-rat-core/src/main/java/org/apache/rat/document/impl/MonolithicFileDocument.java
index dca7a53..e19c509 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/document/impl/MonolithicFileDocument.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/document/impl/MonolithicFileDocument.java
@@ -27,6 +27,7 @@
 import java.io.Reader;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 
 import org.apache.rat.api.Document;
 
@@ -67,6 +68,6 @@
     }
 
      public InputStream inputStream() throws IOException {
-        return new FileInputStream(file);
+        return Files.newInputStream(file.toPath());
     }
 }
diff --git a/apache-rat-plugin/spotbugs_ignore.xml b/apache-rat-plugin/spotbugs_ignore.xml
new file mode 100644
index 0000000..f6a55af
--- /dev/null
+++ b/apache-rat-plugin/spotbugs_ignore.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<FindBugsFilter>
+  <Match>
+    <!-- Uses tryWithResources, thus closes resource properly:
+    [ERROR] Medium: org.apache.rat.configuration.builders.ChildContainerBuilder.setResource(String) may fail to close stream
+    [org.apache.rat.configuration.builders.ChildContainerBuilder] At ChildContainerBuilder.java:[line 62] OS_OPEN_STREAM
+  -->
+    <Class name="org.apache.rat.configuration.builders.ChildContainerBuilder"/>
+    <Bug pattern="OS_OPEN_STREAM"/>
+  </Match>
+</FindBugsFilter>
diff --git a/apache-rat-plugin/src/main/java/org/apache/rat/mp/util/ignore/GlobIgnoreMatcher.java b/apache-rat-plugin/src/main/java/org/apache/rat/mp/util/ignore/GlobIgnoreMatcher.java
index de9061b..19ecc43 100644
--- a/apache-rat-plugin/src/main/java/org/apache/rat/mp/util/ignore/GlobIgnoreMatcher.java
+++ b/apache-rat-plugin/src/main/java/org/apache/rat/mp/util/ignore/GlobIgnoreMatcher.java
@@ -25,6 +25,7 @@
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
diff --git a/apache-rat-tasks/spotbugs_ignore.xml b/apache-rat-tasks/spotbugs_ignore.xml
new file mode 100644
index 0000000..f6a55af
--- /dev/null
+++ b/apache-rat-tasks/spotbugs_ignore.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<FindBugsFilter>
+  <Match>
+    <!-- Uses tryWithResources, thus closes resource properly:
+    [ERROR] Medium: org.apache.rat.configuration.builders.ChildContainerBuilder.setResource(String) may fail to close stream
+    [org.apache.rat.configuration.builders.ChildContainerBuilder] At ChildContainerBuilder.java:[line 62] OS_OPEN_STREAM
+  -->
+    <Class name="org.apache.rat.configuration.builders.ChildContainerBuilder"/>
+    <Bug pattern="OS_OPEN_STREAM"/>
+  </Match>
+</FindBugsFilter>
diff --git a/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java b/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
index 289b04c..359bc52 100644
--- a/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
+++ b/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
@@ -23,6 +23,7 @@
 import java.io.PrintWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -319,10 +320,9 @@
             case ERROR:
                 write(Project.MSG_ERR, msg);
                 break;
-			case OFF:
-				break;
-			default:
-				break;
+            case OFF:
+            default:
+                break;
             }
         }
         
diff --git a/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/ResourceCollectionContainer.java b/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/ResourceCollectionContainer.java
index f487eb3..ca474b9 100644
--- a/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/ResourceCollectionContainer.java
+++ b/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/ResourceCollectionContainer.java
@@ -23,6 +23,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.rat.api.Document;
 import org.apache.rat.api.MetaData;
@@ -69,7 +70,7 @@
         @Override
         public Reader reader() throws IOException {
             final InputStream in = resource.getInputStream();
-            return new InputStreamReader(in);
+            return new InputStreamReader(in, StandardCharsets.UTF_8);
         }
 
         @Override
diff --git a/apache-rat/spotbugs_ignore.xml b/apache-rat/spotbugs_ignore.xml
new file mode 100644
index 0000000..f6a55af
--- /dev/null
+++ b/apache-rat/spotbugs_ignore.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<FindBugsFilter>
+  <Match>
+    <!-- Uses tryWithResources, thus closes resource properly:
+    [ERROR] Medium: org.apache.rat.configuration.builders.ChildContainerBuilder.setResource(String) may fail to close stream
+    [org.apache.rat.configuration.builders.ChildContainerBuilder] At ChildContainerBuilder.java:[line 62] OS_OPEN_STREAM
+  -->
+    <Class name="org.apache.rat.configuration.builders.ChildContainerBuilder"/>
+    <Bug pattern="OS_OPEN_STREAM"/>
+  </Match>
+</FindBugsFilter>
diff --git a/pom.xml b/pom.xml
index f295021..aa45fef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -285,6 +285,10 @@
         <groupId>org.apache.rat</groupId>
         <artifactId>apache-rat-plugin</artifactId>
       </plugin>
+      <plugin>
+        <groupId>com.github.spotbugs</groupId>
+        <artifactId>spotbugs-maven-plugin</artifactId>
+      </plugin>
     </plugins>
   </reporting>
   <build>
@@ -298,6 +302,32 @@
       -->
       <plugins>
         <plugin>
+          <groupId>com.github.spotbugs</groupId>
+          <artifactId>spotbugs-maven-plugin</artifactId>
+          <version>4.8.4.0</version>
+          <configuration>
+            <!-- TODO remove after RAT-369 is done -->
+            <failOnError>false</failOnError>
+            <!-- we only want to see our own problems and in all subpackages -->
+            <onlyAnalyze>org.apache.rat.-</onlyAnalyze>
+            <excludeFilterFile>${basedir}/spotbugs_ignore.xml</excludeFilterFile>
+            <plugins>
+              <plugin>
+                <groupId>com.h3xstream.findsecbugs</groupId>
+                <artifactId>findsecbugs-plugin</artifactId>
+                <version>1.13.0</version>
+              </plugin>
+            </plugins>
+          </configuration>
+          <executions>
+            <execution>
+              <goals>
+                <goal>check</goal>
+              </goals>
+            </execution>
+          </executions>
+        </plugin>
+        <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-antrun-plugin</artifactId>
           <version>3.1.0</version>
@@ -441,6 +471,10 @@
     </pluginManagement>
     <plugins>
       <plugin>
+        <groupId>com.github.spotbugs</groupId>
+        <artifactId>spotbugs-maven-plugin</artifactId>
+      </plugin>
+      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-antrun-plugin</artifactId>
         <executions>
diff --git a/spotbugs_ignore.xml b/spotbugs_ignore.xml
new file mode 100644
index 0000000..f6a55af
--- /dev/null
+++ b/spotbugs_ignore.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<FindBugsFilter>
+  <Match>
+    <!-- Uses tryWithResources, thus closes resource properly:
+    [ERROR] Medium: org.apache.rat.configuration.builders.ChildContainerBuilder.setResource(String) may fail to close stream
+    [org.apache.rat.configuration.builders.ChildContainerBuilder] At ChildContainerBuilder.java:[line 62] OS_OPEN_STREAM
+  -->
+    <Class name="org.apache.rat.configuration.builders.ChildContainerBuilder"/>
+    <Bug pattern="OS_OPEN_STREAM"/>
+  </Match>
+</FindBugsFilter>