CoverityFix CID:1350846 Dubious method used 01/20401/3
Nimish Kapoor [Tue, 31 Jul 2018 17:19:15 +0000 (22:19 +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: I0bb5a3ab6e5701b0d7d089c3f5aa7443eae823cf

scilab/modules/helptools/src/java/org/scilab/modules/helptools/TemplateHandler.java

index a739ff2..b103ccd 100644 (file)
@@ -22,6 +22,8 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.BufferedReader;
 import java.io.FileReader;
+import java.io.InputStreamReader;
+import java.io.FileInputStream;
 import java.nio.charset.Charset;
 
 /**
@@ -104,7 +106,7 @@ public class TemplateHandler {
     private void parseFile(File f) {
         BufferedReader reader = null;
         try {
-            reader = new BufferedReader(new FileReader(f));
+            reader = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
             String line = null;
             StringBuilder stringBuilder = new StringBuilder();
             while ((line = reader.readLine()) != null ) {