CoverityFix CID:1350867 Dubious method used 04/20404/3
Nimish Kapoor [Tue, 31 Jul 2018 18:35:09 +0000 (23:35 +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: I129d5b85fced6dcec543426c0e146cc9a487506c

scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/dialog/SetContextDialog.java

index 9938abf..b11ade4 100644 (file)
@@ -29,6 +29,9 @@ import java.beans.PropertyVetoException;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.io.FileOutputStream;
 import java.util.logging.Logger;
 
 import javax.swing.BorderFactory;
@@ -213,7 +216,7 @@ public class SetContextDialog extends JDialog {
                  */
                 try {
                     File f = File.createTempFile(ScilabDirectHandler.CONTEXT, ".sce");
-                    try (FileWriter writer = new FileWriter(f)) {
+                    try (Writer writer =  new OutputStreamWriter(new FileOutputStream(f), "UTF-8")) {
                         writer.write(context, 0, context.length());
                     }