diff --git a/src/com/tofvesson/async/Async.java b/src/com/tofvesson/async/Async.java index f286b6f..c70744b 100644 --- a/src/com/tofvesson/async/Async.java +++ b/src/com/tofvesson/async/Async.java @@ -197,19 +197,22 @@ public class Async implements Awaitable{ public static Async current(){ try{ Object holder; - Field f = Thread.class.getDeclaredField("threadLocals"); + Field f; + boolean android = false; + try{ + f = Thread.class.getDeclaredField("threadLocals"); + }catch(Exception ignored){ f = Thread.class.getDeclaredField("localValues"); android = true; } f.setAccessible(true); f = (holder=f.get(Thread.currentThread())).getClass().getDeclaredField("table"); f.setAccessible(true); - boolean containsData = false; for(Object o : (Object[]) f.get(holder)) if(o != null) { - if (!containsData) { + if(android) holder = o; + else { f = o.getClass().getDeclaredField("value"); f.setAccessible(true); - containsData = true; } - if((holder=f.get(o)) instanceof Async) return (Async) holder; + if((android?holder:(holder=f.get(o))) instanceof Async) return (Async) holder; } }catch(Exception e){} return null; diff --git a/src/com/tofvesson/reflection/SafeReflection.java b/src/com/tofvesson/reflection/SafeReflection.java index 106bc3b..f02041d 100644 --- a/src/com/tofvesson/reflection/SafeReflection.java +++ b/src/com/tofvesson/reflection/SafeReflection.java @@ -36,11 +36,13 @@ public final class SafeReflection { f = Unsafe.class.getDeclaredField("theUnsafe"); f.setAccessible(true); u = (Unsafe) f.get(null); - f = Field.class.getDeclaredField("modifiers"); - f.setAccessible(true); try { + f = Field.class.getDeclaredField("modifiers"); + f.setAccessible(true); l = u.objectFieldOffset(AccessibleObject.class.getDeclaredField("override")); // Most desktop versions of Java }catch(Exception e){ + f = Field.class.getDeclaredField("accessFlags"); + f.setAccessible(true); l = u.objectFieldOffset(AccessibleObject.class.getDeclaredField("flag")); // God-damned Android } try {