# HG changeset patch # User Carnë Draug # Date 1424632878 0 # Node ID b2c4f869ff7cdb56ed93f74931158ed46919956b # Parent 448ca112a5afb5d690cd51f8f3b62d017207b12a 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. diff --git a/scripts/general/fieldnames.m b/scripts/general/fieldnames.m --- 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"))); +