From f1f838cf2030bdc057ef08ebafce08221bd306cb Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Sat, 9 Aug 2014 05:32:50 +0000 Subject: [PATCH] Favor post-Gingerbread instantiation mechanism. pre-Gingerbread is now a small subset of the Android OS distribution and is constantly shrinking toward zero. --- .../google/gson/internal/UnsafeAllocator.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/gson/src/main/java/com/google/gson/internal/UnsafeAllocator.java b/gson/src/main/java/com/google/gson/internal/UnsafeAllocator.java index d69e3dc2..fce0be37 100644 --- a/gson/src/main/java/com/google/gson/internal/UnsafeAllocator.java +++ b/gson/src/main/java/com/google/gson/internal/UnsafeAllocator.java @@ -51,25 +51,6 @@ public abstract class UnsafeAllocator { } catch (Exception ignored) { } - // try dalvikvm, pre-gingerbread - // public class ObjectInputStream { - // private static native Object newInstance( - // Class instantiationClass, Class constructorClass); - // } - try { - final Method newInstance = ObjectInputStream.class - .getDeclaredMethod("newInstance", Class.class, Class.class); - newInstance.setAccessible(true); - return new UnsafeAllocator() { - @Override - @SuppressWarnings("unchecked") - public T newInstance(Class c) throws Exception { - return (T) newInstance.invoke(null, c, Object.class); - } - }; - } catch (Exception ignored) { - } - // try dalvikvm, post-gingerbread // public class ObjectStreamClass { // private static native int getConstructorId(Class c); @@ -93,6 +74,25 @@ public abstract class UnsafeAllocator { } catch (Exception ignored) { } + // try dalvikvm, pre-gingerbread + // public class ObjectInputStream { + // private static native Object newInstance( + // Class instantiationClass, Class constructorClass); + // } + try { + final Method newInstance = ObjectInputStream.class + .getDeclaredMethod("newInstance", Class.class, Class.class); + newInstance.setAccessible(true); + return new UnsafeAllocator() { + @Override + @SuppressWarnings("unchecked") + public T newInstance(Class c) throws Exception { + return (T) newInstance.invoke(null, c, Object.class); + } + }; + } catch (Exception ignored) { + } + // give up return new UnsafeAllocator() { @Override