Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
partially address a bug in Java initialization
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 21 Mar 2017 12:03:38 +0000 (13:03 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 21 Mar 2017 12:03:38 +0000 (13:03 +0100)
SimGrid flag on command line were consumed at C level but stayed in the
original Java String[] args. This could mess users' args[i] if SG flags
were not put at the end of the command line.

This patch removes the SG flags from the Java arguments. However, the
number of arguments REMAINS UNCHANGED.

It is then UNSAFE to test if args.length is greater than the number of
YOUR OWN ARGUMENTS. It might be if you have --log or --cfg flags in
the command line. BTW, it already was ...

src/bindings/java/jmsg.cpp

index b6c1701..7ffbb23 100644 (file)
@@ -115,7 +115,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j
   setlocale(LC_NUMERIC,"C");
 
   if (jargs)
-    argc = (int) env->GetArrayLength(jargs);
+    argc = static_cast<int>(env->GetArrayLength(jargs));
 
   argc++;
   argv = xbt_new(char *, argc + 1);
@@ -134,9 +134,11 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j
   JAVA_HOST_LEVEL = simgrid::s4u::Host::extension_create(__JAVA_host_priv_free);
   JAVA_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, __JAVA_storage_priv_free);
 
-  for (index = 0; index < argc; index++)
+  for (index = 0; index < argc - 1; index++) {
+    env->SetObjectArrayElement(jargs, index, (jstring)env->NewStringUTF(argv[index + 1]));
     free(argv[index]);
-
+  }
+  free(argv[argc]);
   free(argv);
 }