changeset 20028:b2c4f869ff7c

fieldnames: fix for java objects from dynamic classpath (bug #42710) * fieldnames.m: this function supports passing a java class name as input instead of a java object. org.octave.ClassHelper.getFields() is capable of accepting both a java object or a java class name. However, it would get confused if the object is a java string. I will guess this was the reason to always pass the java class name to it. However, it seems that it will only accept java class names on the static classpath, which made the whole function failing when passing objects. The function will still fail if input is the classname of a class in the dynamic classpath though, but at least will now work if an object is used.
author Carnë Draug <carandraug@octave.org>
date Sun, 22 Feb 2015 19:21:18 +0000
parents 448ca112a5af
children 0e585d3b8b9a
files scripts/general/fieldnames.m
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/fieldnames.m
+++ b/scripts/general/fieldnames.m
@@ -48,7 +48,10 @@
   elseif (isjava (obj) || ischar (obj))
     ## FIXME: Function prototype that excepts java obj exists, but doesn't
     ##        work if obj is java.lang.String.  Convert obj to classname.
-    if (! ischar (obj))
+    ## FIXME this is now working for objects whose class is in the dynamic
+    ##        classpath but will continue to fail if such classnames are used
+    ##        instead (see bug #42710)
+    if (isa (obj, "java.lang.String"))
       obj = class (obj);
     endif
     names_str = javaMethod ("getFields", "org.octave.ClassHelper", obj);
@@ -79,4 +82,12 @@
 %!testif HAVE_JAVA
 %! names = fieldnames (javaObject ("java.lang.Double", 10));
 %! assert (any (strcmp (names, "MAX_VALUE")));
+%! assert (isempty (setxor (names(:),
+%!                          {"POSITIVE_INFINITY", "NEGATIVE_INFINITY", ...
+%!                           "NaN", "MAX_VALUE", "MIN_NORMAL", "MIN_VALUE", ...
+%!                           "MAX_EXPONENT", "MIN_EXPONENT", "SIZE", "TYPE"})));
 
+%!testif HAVE_JAVA
+%! names = fieldnames (javaObject ("java.lang.String", "Hello"));
+%! assert (any (strcmp (names, "CASE_INSENSITIVE_ORDER")));
+