asfgit closed pull request #5725: IGNITE-10732 Force -Dfile.encoding=UTF-8 
URL: https://github.com/apache/ignite/pull/5725
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bin/include/parseargs.sh b/bin/include/parseargs.sh
index 3ab255eae165..1efb48edd079 100755
--- a/bin/include/parseargs.sh
+++ b/bin/include/parseargs.sh
@@ -51,3 +51,13 @@ do
     esac
     shift
 done
+
+#
+# Set 'file.encoding' to UTF-8 default if not specified otherwise
+#
+case "${JVM_OPTS}" in
+    *-Dfile.encoding=*)
+        ;;
+    *)
+        JVM_OPTS="${JVM_OPTS} -Dfile.encoding=UTF-8";;
+esac
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java 
b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 3a3af8e72e15..9633f896741a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -29,6 +29,7 @@
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
 import java.lang.reflect.Constructor;
+import java.nio.charset.Charset;
 import java.text.DateFormat;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
@@ -40,6 +41,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -1077,6 +1079,9 @@ public void start(
                 gw.writeUnlock();
             }
 
+            // Check whether UTF-8 is the default character encoding.
+            checkFileEncoding();
+
             // Check whether physical RAM is not exceeded.
             checkPhysicalRam();
 
@@ -1405,6 +1410,20 @@ private void validateCommon(IgniteConfiguration cfg) {
         A.ensure(cfg.getNetworkSendRetryCount() > 0, 
"cfg.getNetworkSendRetryCount() > 0");
     }
 
+    /**
+     * Check whether UTF-8 is the default character encoding.
+     * Differing character encodings across cluster may lead to erratic 
behavior.
+     */
+    private void checkFileEncoding() {
+        String encodingDisplayName = 
Charset.defaultCharset().displayName(Locale.ENGLISH);
+
+        if (!"UTF-8".equals(encodingDisplayName)) {
+            U.quietAndWarn(log, "Default character encoding is " + 
encodingDisplayName +
+                ". Specify UTF-8 character encoding by setting 
-Dfile.encoding=UTF-8 JVM parameter. " +
+                "Differing character encodings across cluster may lead to 
erratic behavior.");
+        }
+    }
+
     /**
      * Checks whether physical RAM is not exceeded.
      */
diff --git 
a/modules/core/src/main/java/org/apache/ignite/startup/cmdline/CommandLineTransformer.java
 
b/modules/core/src/main/java/org/apache/ignite/startup/cmdline/CommandLineTransformer.java
index f4aad172b05b..e449bfa3a607 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/startup/cmdline/CommandLineTransformer.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/startup/cmdline/CommandLineTransformer.java
@@ -204,10 +204,15 @@ private void addArgWithValue(StringBuilder sb, String 
arg, Object val) {
      * @param args Collection of unknown (from JCommander point of view) 
arguments.
      */
     private void parseJvmOptionsAndSpringConfig(Iterable<String> args) {
+        boolean hadFileEncoding = false;
+
         for (String arg : args) {
             if (arg.startsWith(JVM_OPTION_PREFIX)) {
                 String jvmOpt = arg.substring(JVM_OPTION_PREFIX.length());
 
+                if (jvmOpt.startsWith("-Dfile.encoding="))
+                    hadFileEncoding = true;
+
                 if (!checkJVMOptionIsSupported(jvmOpt))
                     throw new RuntimeException(JVM_OPTION_PREFIX + " JVM 
parameters for Ignite batch scripts " +
                         "with double quotes are not supported. " +
@@ -222,6 +227,9 @@ private void 
parseJvmOptionsAndSpringConfig(Iterable<String> args) {
                     throw new RuntimeException("Unrecognised parameter has 
been found: " + arg);
             }
         }
+
+        if (!hadFileEncoding)
+            jvmOptions = (jvmOptions.isEmpty() ? "" : (jvmOptions + " ")) + 
"-Dfile.encoding=UTF-8";
     }
 
     /**
@@ -234,4 +242,4 @@ private void 
parseJvmOptionsAndSpringConfig(Iterable<String> args) {
     private boolean checkJVMOptionIsSupported(String jvmOpt) {
         return !(jvmOpt.contains("-XX:OnError") || 
jvmOpt.contains("-XX:OnOutOfMemoryError"));
     }
-}
\ No newline at end of file
+}
diff --git 
a/modules/core/src/test/java/org/apache/ignite/startup/cmdline/GridCommandLineTransformerSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/startup/cmdline/GridCommandLineTransformerSelfTest.java
index d08ed6bdb236..fbcb547d96fb 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/startup/cmdline/GridCommandLineTransformerSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/startup/cmdline/GridCommandLineTransformerSelfTest.java
@@ -36,7 +36,7 @@
     public void testTransformIfNoArguments() throws Exception {
         assertEquals(
             "\"INTERACTIVE=0\" \"QUIET=-DIGNITE_QUIET=true\" \"NO_PAUSE=0\" " +
-                "\"NO_JMX=0\" \"JVM_XOPTS=\" \"CONFIG=\"",
+                "\"NO_JMX=0\" \"JVM_XOPTS=-Dfile.encoding=UTF-8\" \"CONFIG=\"",
             CommandLineTransformer.transform());
     }
 
@@ -111,7 +111,7 @@ public void 
testTransformIfSeveralArgumentsWithoutDashPrefix() throws Exception
     public void testTransformIfOnlyPathToConfigSpecified() throws Exception {
         assertEquals(
             "\"INTERACTIVE=0\" \"QUIET=-DIGNITE_QUIET=true\" \"NO_PAUSE=0\" 
\"NO_JMX=0\" " +
-            "\"JVM_XOPTS=\" \"CONFIG=c:\\qw.xml\"",
+            "\"JVM_XOPTS=-Dfile.encoding=UTF-8\" \"CONFIG=c:\\qw.xml\"",
             CommandLineTransformer.transform("c:\\qw.xml"));
     }
 
@@ -122,7 +122,7 @@ public void testTransformIfOnlyPathToConfigSpecified() 
throws Exception {
     public void testTransformIfAllSupportedArguments() throws Exception {
         assertEquals(
             "\"INTERACTIVE=1\" \"QUIET=-DIGNITE_QUIET=false\" \"NO_PAUSE=1\" 
\"NO_JMX=1\" " +
-                "\"JVM_XOPTS=-Xmx1g -Xms1m\" " +
+                "\"JVM_XOPTS=-Xmx1g -Xms1m -Dfile.encoding=UTF-8\" " +
                 "\"CONFIG=\"c:\\path to\\русский каталог\"\"",
             CommandLineTransformer.transform("-i", "-np", "-v", "-J-Xmx1g", 
"-J-Xms1m", "-nojmx",
                 "\"c:\\path to\\русский каталог\""));
diff --git a/modules/platforms/cpp/core/src/ignition.cpp 
b/modules/platforms/cpp/core/src/ignition.cpp
index 7d90a52c7768..3891be1e586f 100644
--- a/modules/platforms/cpp/core/src/ignition.cpp
+++ b/modules/platforms/cpp/core/src/ignition.cpp
@@ -111,6 +111,10 @@ namespace ignite
 
             int idx = 0;
 
+            std::string fileEncParam = "-Dfile.encoding=";
+
+            bool hadFileEnc = false;
+
             // 1. Set classpath.
             std::string cpFull = "-Djava.class.path=" + cp;
 
@@ -131,8 +135,19 @@ namespace ignite
             opts[idx++] = CopyChars(xmxStr.c_str());
 
             // 4. Set the rest options.
-            for (std::list<std::string>::const_iterator i = 
cfg.jvmOpts.begin(); i != cfg.jvmOpts.end(); ++i)
+            for (std::list<std::string>::const_iterator i = 
cfg.jvmOpts.begin(); i != cfg.jvmOpts.end(); ++i) {
+                if (i->find(fileEncParam) != std::string::npos)
+                    hadFileEnc = true;
+
                 opts[idx++] = CopyChars(i->c_str());
+            }
+
+            // 5. Set file.encoding.
+            if (!hadFileEnc) {
+                std::string fileEncFull = fileEncParam + "UTF-8";
+
+                opts[idx++] = CopyChars(fileEncFull.c_str());
+            }
         }
 
         /**
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs 
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
index 47260a75b146..e2a4b9f99bc8 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
@@ -40,6 +40,9 @@ internal static class IgniteManager
         /** Java Command line argument: Xmx. Case sensitive. */
         private const string CmdJvmMaxMemJava = "-Xmx";
 
+        /** Java Command line argument: file.encoding. Case sensitive. */
+        private const string CmdJvmFileEncoding = "-Dfile.encoding=";
+
         /** Monitor for DLL load synchronization. */
         private static readonly object SyncRoot = new object();
 
@@ -93,7 +96,7 @@ internal static UnmanagedCallbacks 
CreateJvmContext(IgniteConfiguration cfg, ILo
                 return cbs;
             }
         }
-        
+
         /// <summary>
         /// Memory manager attached to currently running JVM.
         /// </summary>
@@ -141,6 +144,9 @@ private static IList<string> 
GetMergedJvmOptions(IgniteConfiguration cfg)
                 cfg.JvmMaxMemoryMb != IgniteConfiguration.DefaultJvmMaxMem)
                 jvmOpts.Add(string.Format(CultureInfo.InvariantCulture, 
"{0}{1}m", CmdJvmMaxMemJava, cfg.JvmMaxMemoryMb));
 
+            if (!jvmOpts.Any(opt => opt.StartsWith(CmdJvmFileEncoding, 
StringComparison.Ordinal)))
+                jvmOpts.Add(string.Format(CultureInfo.InvariantCulture, 
"{0}UTF-8", CmdJvmFileEncoding));
+
             return jvmOpts;
         }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to