Skip to content

Commit

Permalink
Fixed an issue with Android N's OpenJDK where invalid instantiator is…
Browse files Browse the repository at this point in the history
… used
  • Loading branch information
taivokasper committed Apr 20, 2016
1 parent a2df0f3 commit 107892d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public final class PlatformDescription {
/** Android version. Will be 0 for none android platform */
public static final int ANDROID_VERSION = getAndroidVersion();

/** Boot classpath for detecting OpenJDK on Android */
public static final String BOOT_CLASSPATH = System.getProperty("java.boot.class.path");

/** Google App Engine version or null is we are not on GAE */
public static final String GAE_VERSION = getGaeRuntimeVersion();

Expand Down Expand Up @@ -112,6 +115,10 @@ public static boolean isThisJVM(String name) {
return JVM_NAME.startsWith(name);
}

public static boolean isAndroidOpenJDK() {
return BOOT_CLASSPATH != null && BOOT_CLASSPATH.toLowerCase().contains("core-oj.jar");
}

public static boolean isGoogleAppEngine() {
return getGaeRuntimeVersion() != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public <T> ObjectInstantiator<T> newInstantiatorOf(Class<T> type) {
return new ObjectStreamClassInstantiator<T>(type);
}
else if(JVM_NAME.startsWith(DALVIK)) {
if(PlatformDescription.isAndroidOpenJDK()) {
return new ObjectStreamClassInstantiator<T>(type);
}
return new AndroidSerializationInstantiator<T>(type);
}
else if(JVM_NAME.startsWith(GNU)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.objenesis.instantiator.android.Android18Instantiator;
import org.objenesis.instantiator.basic.AccessibleInstantiator;
import org.objenesis.instantiator.basic.ObjectInputStreamInstantiator;
import org.objenesis.instantiator.basic.ObjectStreamClassInstantiator;
import org.objenesis.instantiator.gcj.GCJInstantiator;
import org.objenesis.instantiator.jrockit.JRockitLegacyInstantiator;
import org.objenesis.instantiator.perc.PercInstantiator;
Expand Down Expand Up @@ -84,6 +85,9 @@ else if(PlatformDescription.isThisJVM(JROCKIT)) {
return new SunReflectionFactoryInstantiator<T>(type);
}
else if(PlatformDescription.isThisJVM(DALVIK)) {
if(PlatformDescription.isAndroidOpenJDK()) {
return new ObjectStreamClassInstantiator<T>(type);
}
if(ANDROID_VERSION <= 10) {
// Android 2.3 Gingerbread and lower
return new Android10Instantiator<T>(type);
Expand Down

0 comments on commit 107892d

Please sign in to comment.