external_objects_java: fix crash on ScilabJavaEnvironment when used as a local variable
[scilab.git] / scilab / modules / external_objects_java / sci_gateway / cpp / sci_jallowClassReloading.cpp
index a644358..a8635fb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * PIMS ( http://forge.scilab.org/index.php/p/pims ) - This file is part of PIMS
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
  * Copyright (C) 2013 - Scilab Enterprises - Sylvestre Ledru
  *
  *
  */
 
-#include "ScilabJavaEnvironment.hxx"
-#include "ScilabGateway.hxx"
-
 extern "C" {
 #include "Scierror.h"
 #include "gw_external_objects_java.h"
 }
 
+#include "ScilabJavaEnvironment.hxx"
+#include "ScilabGateway.hxx"
+
 using namespace org_scilab_modules_external_objects_java;
 using namespace org_modules_external_objects;
 
@@ -27,7 +27,16 @@ int sci_jallowClassReloading(char * fname, unsigned long fname_len)
     try
     {
         const int envId = ScilabJavaEnvironment::start();
-        //        return ScilabGateway::setAllowReload(fname, envId, pvApiCtx);
+
+        ScilabJavaEnvironment *javaEnvironment = ScilabJavaEnvironment::getInstance();
+        if (!javaEnvironment)
+        {
+            Scierror(999, "%s: No Java environment available (instance is null).", fname);
+            return 0;
+        }
+
+        JavaOptionsSetter setter = javaEnvironment->getOptionsHelper().getSetter(JavaOptionsSetter::ALLOWRELOAD);
+        return ScilabGateway::getsetOptions(fname, envId, setter, pvApiCtx);
     }
     catch (std::exception & e)
     {