# HG changeset patch
# User Ernst Reissner <rei3ner@arcor.de>
# Date 1471568330 -7200
#      Fri Aug 19 02:58:50 2016 +0200
# Node ID 1523bf2eb877cf7abdeff2642dc924860dd939e4
# Parent  7ad908f8c7ab4d93290f4818b6affeda3b0811d0
return type void: methods unbox and ...call

diff -r 7ad908f8c7ab -r 1523bf2eb877 libinterp/octave-value/ov-java.cc
--- a/libinterp/octave-value/ov-java.cc	Fri Aug 19 00:23:35 2016 +0200
+++ b/libinterp/octave-value/ov-java.cc	Fri Aug 19 02:58:50 2016 +0200
@@ -139,17 +139,17 @@
 static octave_value
 box_more (JNIEnv* jni_env, void *jobj_arg, void *jcls_arg = 0);
 
-static bool
+static void
 unbox (JNIEnv* jni_env, const octave_value& val, jobject_ref& jobj,
        jclass_ref& jcls);
 
-static bool
+static void
 unbox (JNIEnv* jni_env, const octave_value_list& args,
        jobjectArray_ref& jobjs, jobjectArray_ref& jclss);
 
 extern "C"
 {
-  JNIEXPORT jboolean JNICALL
+  JNIEXPORT void JNICALL
   Java_org_octave_Octave_call (JNIEnv *, jclass, jstring, jobjectArray,
                                jobjectArray);
 
@@ -993,16 +993,15 @@
   jobject_ref rhsObj (jni_env);
   jobject_ref java_idx (jni_env, make_java_index (jni_env, idx));
 
-  if (unbox (jni_env, rhs, rhsObj, rhsCls))
-    {
-      jclass_ref helperClass (jni_env,
-                              find_octave_class (jni_env,
-                                                 "org/octave/ClassHelper"));
-      jmethodID mID = jni_env->GetStaticMethodID (helperClass, "arraySubsasgn",
-          "(Ljava/lang/Object;[[ILjava/lang/Object;)" "Ljava/lang/Object;");
-      resObj = jni_env->CallStaticObjectMethod
-        (helperClass, mID, jobj, jobject (java_idx), jobject (rhsObj));
-    }
+  unbox (jni_env, rhs, rhsObj, rhsCls);
+  jclass_ref helperClass (jni_env,
+                          find_octave_class (jni_env,
+                                             "org/octave/ClassHelper"));
+  jmethodID mID = jni_env->GetStaticMethodID 
+    (helperClass, "arraySubsasgn",
+     "(Ljava/lang/Object;[[ILjava/lang/Object;)Ljava/lang/Object;");
+  resObj = jni_env->CallStaticObjectMethod
+    (helperClass, mID, jobj, jobject (java_idx), jobject (rhsObj));
 
   if (resObj)
     retval = box (jni_env, resObj);
@@ -1485,12 +1484,10 @@
 }
 
 // conversion from octave to java 
-static bool
+static void
 unbox (JNIEnv *jni_env, const octave_value& val, jobject_ref& jobj,
        jclass_ref& jcls)
 {
-  bool found = true;
-
   if (val.is_java ())
     {
       octave_java *ovj = TO_JAVA (val);
@@ -1575,7 +1572,7 @@
 
 #undef UNBOX_PRIMITIVE_ARRAY
       // FIXME: missing else-branch 
-      // to be handled: String[] and found=false 
+      // FIXME: to be handled: String[] 
     }
   else if (val.is_real_scalar () || val.is_bool_scalar ())
     // FIXME: better: is_real_type, is_bool_type, is_scalar_type
@@ -1667,7 +1664,6 @@
          } 
        else 
          {
-           found = false;
            error ("cannot convert scalar of type '%s'", 
                   val.class_name ().c_str ());
          }
@@ -1768,7 +1764,6 @@
         }
       else
         {
-          found = false;
           error ("cannot convert matrix of type '%s'",
                  val.class_name ().c_str ());
         }
@@ -1783,16 +1778,12 @@
       jcls = rcls;
       octave_ref_map[ID] = val;
     }
-
-  return found;
 }
 
-static bool
+static void
 unbox (JNIEnv *jni_env, const octave_value_list& args,
        jobjectArray_ref& jobjs, jobjectArray_ref& jclss)
 {
-  bool found = true;
-
   jclass_ref ocls (jni_env, jni_env->FindClass ("java/lang/Object"));
   jclass_ref ccls (jni_env, jni_env->FindClass ("java/lang/Class"));
 
@@ -1806,16 +1797,11 @@
     {
       jobject_ref jobj (jni_env);
       jclass_ref  jcls (jni_env);
-
-      found = unbox (jni_env, args(i), jobj, jcls);
-      if (! found)
-        break;
+      unbox (jni_env, args(i), jobj, jcls);
 
       jni_env->SetObjectArrayElement (jobjs, i, jobj);
       jni_env->SetObjectArrayElement (jclss, i, jcls);
     }
-
-  return found;
 }
 
 static long
@@ -1888,7 +1874,7 @@
     }
 }
 
-JNIEXPORT jboolean JNICALL
+JNIEXPORT void JNICALL
 Java_org_octave_Octave_call (JNIEnv *env, jclass, jstring funcName,
                              jobjectArray argin, jobjectArray argout)
 {
@@ -1911,9 +1897,7 @@
 
   // unbox (JNIEnv *env, const octave_value_list , // input
   //        jobjectArray_ref&, jobjectArray_ref)   // output 
-  bool res = unbox (env, varargout, out_objs, out_clss);
-
-  return res;
+  unbox (env, varargout, out_objs, out_clss);
 }
 
 JNIEXPORT void JNICALL
@@ -2326,19 +2310,29 @@
   if (jni_env)
     {
       jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
-      if (unbox (jni_env, args, arg_objs, arg_types))
-        {
-          jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
-          jmethodID mID = jni_env->GetStaticMethodID (helperClass, "invokeMethod",
-                                                      "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
-          jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
-          jobjectArray_ref resObj (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallStaticObjectMethod (helperClass, mID,
-                                                                                                             to_java (), jstring (methName), jobjectArray (arg_objs), jobjectArray (arg_types))));
-          if (resObj)
-            retval = box (jni_env, resObj);
-          else
-            retval = check_exception (jni_env);
-        }
+      unbox (jni_env, args, arg_objs, arg_types);
+      jclass_ref helperClass (jni_env, 
+                              find_octave_class (jni_env, 
+                                                 "org/octave/ClassHelper"));
+      jmethodID mID = jni_env->GetStaticMethodID (helperClass,
+                                                  "invokeMethod",
+                                                  "(Ljava/lang/Object;"
+                                                  "Ljava/lang/String;"
+                                                  "[Ljava/lang/Object;"
+                                                  "[Ljava/lang/Class;)"
+                                                  "Ljava/lang/Object;");
+      jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
+      jobjectArray_ref resObj (jni_env,
+                               reinterpret_cast<jobjectArray>
+                               (jni_env->CallStaticObjectMethod
+                                (helperClass, mID,
+                                 to_java (), jstring (methName),
+                                 jobjectArray (arg_objs), 
+                                 jobjectArray (arg_types))));
+      if (resObj)
+        retval = box (jni_env, resObj);
+      else
+        retval = check_exception (jni_env);
 
       octave_set_default_fpucw ();
     }
@@ -2394,20 +2388,25 @@
   if (jni_env)
     {
       jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
-      if (unbox (jni_env, args, arg_objs, arg_types))
-        {
-          jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
-          jmethodID mID = jni_env->GetStaticMethodID (helperClass, "invokeStaticMethod",
-                                                      "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
-          jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
-          jstring_ref clsName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
-          jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod (helperClass, mID,
-                                                                        jstring (clsName), jstring (methName), jobjectArray (arg_objs), jobjectArray (arg_types)));
-          if (resObj)
-            retval = box (jni_env, resObj);
-          else
-            retval = check_exception (jni_env);
-        }
+      unbox (jni_env, args, arg_objs, arg_types);
+      jclass_ref helperClass (jni_env, 
+                              find_octave_class (jni_env, 
+                                                 "org/octave/ClassHelper"));
+      jmethodID mID = jni_env->GetStaticMethodID 
+        (helperClass, "invokeStaticMethod",
+         "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
+      jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
+      jstring_ref clsName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
+      jobject_ref resObj (jni_env, 
+                          jni_env->CallStaticObjectMethod
+                          (helperClass, mID,
+                           jstring (clsName), jstring (methName),
+                           jobjectArray (arg_objs), jobjectArray (arg_types)));
+      if (resObj)
+        retval = box (jni_env, resObj);
+      else
+        retval = check_exception (jni_env);
+
 
       octave_set_default_fpucw ();
     }
@@ -2465,21 +2464,22 @@
   if (jni_env)
     {
       jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
-
-      if (unbox (jni_env, args, arg_objs, arg_types))
-        {
-          jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
-          jmethodID mID = jni_env->GetStaticMethodID (helperClass, "invokeConstructor",
-                                                      "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
-          jstring_ref clsName (jni_env, jni_env->NewStringUTF (name.c_str ()));
-          jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod (helperClass, mID,
-                                                                        jstring (clsName), jobjectArray (arg_objs), jobjectArray (arg_types)));
-
-          if (resObj)
-            retval = octave_value (new octave_java (resObj, 0));
-          else
-            check_exception (jni_env);
-        }
+      unbox (jni_env, args, arg_objs, arg_types);
+      jclass_ref helperClass (jni_env, find_octave_class 
+                              (jni_env, "org/octave/ClassHelper"));
+      jmethodID mID = jni_env->GetStaticMethodID 
+        (helperClass, "invokeConstructor",
+         "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)" 
+         "Ljava/lang/Object;");
+      jstring_ref clsName (jni_env, jni_env->NewStringUTF (name.c_str ()));
+      jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod 
+                          (helperClass, mID,jstring (clsName), 
+                           jobjectArray (arg_objs), jobjectArray (arg_types)));
+
+      if (resObj)
+        retval = octave_value (new octave_java (resObj, 0));
+      else
+        check_exception (jni_env);
 
       octave_set_default_fpucw ();
     }
@@ -2657,16 +2657,17 @@
     {
       jobject_ref jobj (jni_env);
       jclass_ref jcls (jni_env);
-
-      if (unbox (jni_env, val, jobj, jcls))
-        {
-          jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
-          jmethodID mID = jni_env->GetStaticMethodID (helperClass, "setField",
-                                                      "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
-          jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
-          jni_env->CallStaticObjectMethod (helperClass, mID, to_java (), jstring (fName), jobject (jobj));
-          check_exception (jni_env);
-        }
+      unbox (jni_env, val, jobj, jcls);
+      jclass_ref helperClass (jni_env, 
+                              find_octave_class (jni_env, 
+                                                 "org/octave/ClassHelper"));
+      jmethodID mID = jni_env->GetStaticMethodID
+        (helperClass, "setField",
+         "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
+      jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
+      jni_env->CallStaticObjectMethod (helperClass, mID, to_java (), 
+                                       jstring (fName), jobject (jobj));
+      check_exception (jni_env);
 
       octave_set_default_fpucw ();
     }
@@ -2721,17 +2722,17 @@
     {
       jobject_ref jobj (jni_env);
       jclass_ref jcls (jni_env);
-
-      if (unbox (jni_env, val, jobj, jcls))
-        {
-          jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
-          jmethodID mID = jni_env->GetStaticMethodID (helperClass, "setStaticField",
-                                                      "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V");
-          jstring_ref cName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
-          jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
-          jni_env->CallStaticObjectMethod (helperClass, mID, jstring (cName), jstring (fName), jobject (jobj));
-          check_exception (jni_env);
-        }
+      unbox (jni_env, val, jobj, jcls);
+      jclass_ref helperClass (jni_env, find_octave_class 
+                              (jni_env, "org/octave/ClassHelper"));
+      jmethodID mID = jni_env->GetStaticMethodID 
+        (helperClass, "setStaticField",
+         "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V");
+      jstring_ref cName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
+      jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
+      jni_env->CallStaticObjectMethod 
+        (helperClass, mID, jstring (cName), jstring (fName), jobject (jobj));
+      check_exception (jni_env);
 
       octave_set_default_fpucw ();
     }
diff -r 7ad908f8c7ab -r 1523bf2eb877 scripts/java/org/octave/Octave.java
--- a/scripts/java/org/octave/Octave.java	Fri Aug 19 00:23:35 2016 +0200
+++ b/scripts/java/org/octave/Octave.java	Fri Aug 19 02:58:50 2016 +0200
@@ -116,8 +116,7 @@
   //! @return
   //!    whether conversion from output arguments of function @c name 
   //!    to Java types succeeded. 
-  public native static boolean call (String name, 
-                                     Object[] argin, Object[] argout);
+  public native static void call (String name, Object[] argin, Object[] argout);
 
 
   //! Evaluates the given command @c cmd. 
@@ -351,18 +350,12 @@
   //!    the name of the octave function to be called. 
   //!    It is assumed that it takes one input argument and one output argument 
   //!    and that the types fit after conversion. 
-  //! @throws Exception
-  //!    if back-conversion of the return value fails. 
   //! @see #call(String, Object[], Object[])
   public static Object do_test (String name, Object arg0) 
-    throws Exception
   {
     Object[] argin = new Object[] { arg0 };
     Object[] argout = new Object[1];
-    if (call (name, argin, argout))
-      {
-        return argout[0];
-      }
-    throw new Exception ("octave call failed");
+    call (name, argin, argout);
+    return argout[0];
   }
 }
