You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
InstrumentingClassLoader does not work properly as a parent class loader, due to missing loadClass(String, boolean) overload which is called by ClassLoader.loadClass(String, boolean). Instead of overriding loadClass(String), InstrumentingClassLoader should override loadClass(String, boolean).
This can produce very weird behavior since multiple class definitions for the same class will exist, including ServiceLoader throwing java.util.ServiceConfigurationError "Provider X not a subtype" since the extending class and its ancestors were loaded from the normal class loader but the class doing the call is loaded from InstrumentingClassLoader
Steps to Reproduce
These two lines return different classes, but they shouldn't:
My previous test didn't quite precise enough, because it depended a lot on the environment and order of operations happening outside of the code snippet. This unit test should work:
classOnlyUsedByChildClassLoaderTest {}
@TestpublicvoidtestChildClassLoaderReturnsSameInstanceAsParent() throwsException {
// Must not use .class. This class must be loaded from the child firstStringname = getClass().getName() + "$OnlyUsedByChildClassLoaderTest";
// Note that reversing this line and the next line produces different resultsClass<?> fromChild = Class.forName(name, false,
newClassLoader(getClass().getClassLoader()) {});
Class<?> fromIntrumented = Class.forName(name, false,
getClass().getClassLoader());
// Just a sanity testassertThat(fromIntrumented).isSameAs(OnlyUsedByChildClassLoaderTest.class);
// The real verificationassertThat(fromChild).isSameAs(fromIntrumented);
}
Description
InstrumentingClassLoader
does not work properly as a parent class loader, due to missingloadClass(String, boolean)
overload which is called byClassLoader.loadClass(String, boolean)
. Instead of overridingloadClass(String)
,InstrumentingClassLoader
should overrideloadClass(String, boolean)
.This can produce very weird behavior since multiple class definitions for the same class will exist, including
ServiceLoader
throwingjava.util.ServiceConfigurationError
"Provider X not a subtype" since the extending class and its ancestors were loaded from the normal class loader but the class doing the call is loaded fromInstrumentingClassLoader
Steps to Reproduce
These two lines return different classes, but they shouldn't:
Robolectric & Android Version
3.1 SNAPSHOT, commit 78ef7fa
The text was updated successfully, but these errors were encountered: