altoslib: Stop reflective JSON class walk at Object instead of null
authorKeith Packard <keithp@keithp.com>
Fri, 17 Jun 2016 15:54:19 +0000 (08:54 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 17 Jun 2016 15:54:19 +0000 (08:54 -0700)
Android has classes above Object which are all tied together which
cause the object walking to fail in pretty spectacular ways. As Object
has no interesting fields, that serves as a fine barrier to the super
class walk and works on both android and real java.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosJson.java

index 346144d97e07ef409f2c5d25b80b37fda1ea3856..67f3a00ad3fdc2502e7921cc962ad98b5a8e5bb1 100644 (file)
@@ -1063,7 +1063,7 @@ public class AltosJson extends JsonUtil {
                                } else {
                                        object = c.newInstance();
                                }
-                               for (; c != null; c = c.getSuperclass()) {
+                               for (; c != Object.class; c = c.getSuperclass()) {
                                        for (Field field : c.getDeclaredFields()) {
                                                String  fieldName = field.getName();
                                                Class   fieldClass = field.getType();
@@ -1208,7 +1208,7 @@ public class AltosJson extends JsonUtil {
                        }
                } else {
                        assert_hash(true);
-                       for (Class c = object.getClass(); c != null; c = c.getSuperclass()) {
+                       for (Class c = object.getClass(); c != Object.class; c = c.getSuperclass()) {
                                for (Field field : c.getDeclaredFields()) {
                                        String  fieldName = field.getName();