v0.4.3a: fixed several issues revealed by new bundle error reporting

This commit is contained in:
Evan Debenham 2016-10-22 11:20:14 -04:00 committed by Evan Debenham
parent ac3439d0e5
commit 22c1a0189c
2 changed files with 25 additions and 17 deletions

View File

@ -29,6 +29,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PushbackInputStream; import java.io.PushbackInputStream;
import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -118,7 +119,7 @@ public class Bundle {
} }
Class<?> cl = Class.forName( clName ); Class<?> cl = Class.forName( clName );
if (cl != null) { if (cl != null && (!cl.isMemberClass() || Modifier.isStatic(cl.getModifiers()))) {
Bundlable object = (Bundlable)cl.newInstance(); Bundlable object = (Bundlable)cl.newInstance();
object.restoreFromBundle( this ); object.restoreFromBundle( this );
return object; return object;
@ -367,11 +368,16 @@ public class Bundle {
public void put( String key, Collection<? extends Bundlable> collection ) { public void put( String key, Collection<? extends Bundlable> collection ) {
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
for (Bundlable object : collection) { for (Bundlable object : collection) {
//Skip none-static inner classes as they can't be instantiated through bundle restoring
//Classes which make use of none-static inner classes must manage instantiation manually
if (object != null) { if (object != null) {
Bundle bundle = new Bundle(); Class cl = object.getClass();
bundle.put(CLASS_NAME, object.getClass().getName()); if (!cl.isMemberClass() || Modifier.isStatic(cl.getModifiers())) {
object.storeInBundle(bundle); Bundle bundle = new Bundle();
array.put(bundle.data); bundle.put(CLASS_NAME, cl.getName());
object.storeInBundle(bundle);
array.put(bundle.data);
}
} }
} }
try { try {

View File

@ -88,21 +88,23 @@ public class Blob extends Actor {
super.restoreFromBundle( bundle ); super.restoreFromBundle( bundle );
if (bundle.contains(LENGTH)) { if (bundle.contains( CUR )) {
cur = new int[bundle.getInt(LENGTH)];
} else {
//compatability with pre-0.4.2
cur = new int[1024];
}
off = new int[cur.length];
int[] data = bundle.getIntArray( CUR ); if (bundle.contains(LENGTH)) {
if (data != null) { cur = new int[bundle.getInt(LENGTH)];
int start = bundle.getInt( START ); } else {
for (int i=0; i < data.length; i++) { //compatability with pre-0.4.2
cur = new int[1024];
}
off = new int[cur.length];
int[] data = bundle.getIntArray(CUR);
int start = bundle.getInt(START);
for (int i = 0; i < data.length; i++) {
cur[i + start] = data[i]; cur[i + start] = data[i];
volume += data[i]; volume += data[i];
} }
} }
} }