CoverityFix CID:1350858,1350857 Dubious method used 97/20397/3
Nimish Kapoor [Tue, 31 Jul 2018 16:16:56 +0000 (21:16 +0530)]
Found a call to a method which will perform a byte to String (or String to
byte) conversion, and will assume that the default platform encoding is
suitable. This will cause the application behaviour to vary between
platforms. Use an alternative API and specify a charset name or Charset
object explicitly.
https://stackoverflow.com/questions/696626/java-filereader-encoding-issue

Change-Id: I07aa110c55950bea465c1c9c96f97fae86a2ad4c

scilab/modules/helptools/src/java/org/scilab/modules/helptools/source/ScilabSourceBrowser.java

index 15f95c7..e08675b 100644 (file)
@@ -22,6 +22,8 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
+import java.io.InputStreamReader;
+import java.io.FileInputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -61,7 +63,7 @@ public class ScilabSourceBrowser extends HTMLScilabCodeHandler {
             try {
                 File f = new File(file);
                 System.out.println(f);
-                Reader input = new BufferedReader(new FileReader(f));
+                Reader input = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
                 currentCommand = f.getName().split("\\.")[0];
                 buffer = new FileWriter(outputDirectory + File.separator + currentCommand + ".html");
                 buffer.append(entete);
@@ -135,7 +137,7 @@ public class ScilabSourceBrowser extends HTMLScilabCodeHandler {
         files = new ArrayList<String>();
         mapId = new HashMap<String, String>();
         try {
-            input = new BufferedReader(new FileReader(filename));
+            input = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "UTF-8"));
             String line = null;
             while ((line = input.readLine()) != null) {
                 files.add(line);
@@ -162,7 +164,7 @@ public class ScilabSourceBrowser extends HTMLScilabCodeHandler {
             for (String file : files) {
                 try {
                     File f = new File(file);
-                    Reader input = new BufferedReader(new FileReader(f));
+                    Reader input = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
                     currentCommand = f.getName().split("\\.")[0];
                     scilabLexer.convert(this, input, false);
                 } catch (IOException e) {