From 4c41b11fce30bdabf8d276b934d4161d0e186db4 Mon Sep 17 00:00:00 2001 From: Joel Leitch Date: Mon, 14 Feb 2011 22:26:17 +0000 Subject: [PATCH] Comments from r723. --- .../google/gson/MappedObjectConstructor.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/gson/src/main/java/com/google/gson/MappedObjectConstructor.java b/gson/src/main/java/com/google/gson/MappedObjectConstructor.java index a34be7c0..a5fc6389 100644 --- a/gson/src/main/java/com/google/gson/MappedObjectConstructor.java +++ b/gson/src/main/java/com/google/gson/MappedObjectConstructor.java @@ -40,20 +40,7 @@ import java.util.logging.Logger; */ final class MappedObjectConstructor implements ObjectConstructor { private static final Logger log = Logger.getLogger(MappedObjectConstructor.class.getName()); - private static final Unsafe THE_UNSAFE = AccessController.doPrivileged( - new PrivilegedAction() { - public Unsafe run() { - try { - Field f = Unsafe.class.getDeclaredField("theUnsafe"); - f.setAccessible(true); - return (Unsafe) f.get(null); - } catch (NoSuchFieldException e) { - throw new Error(); - } catch (IllegalAccessException e) { - throw new Error(); - } - } - }); + private static final Unsafe THE_UNSAFE = getUnsafe(); private final ParameterizedTypeHandlerMap> instanceCreatorMap; @@ -70,6 +57,18 @@ final class MappedObjectConstructor implements ObjectConstructor { } return (T) constructWithNoArgConstructor(typeOfT); } + + private static Unsafe getUnsafe() { + try { + Field f = Unsafe.class.getDeclaredField("theUnsafe"); + f.setAccessible(true); + return (Unsafe) f.get(null); + } catch (NoSuchFieldException e) { + throw new Error(); + } catch (IllegalAccessException e) { + throw new Error(); + } + } public Object constructArray(Type type, int length) { return Array.newInstance(Types.getRawType(type), length);