RuntimeException: Stub! in 2.0-alpha-2 #426

Closed
screendriver opened this Issue Mar 1, 2013 · 24 comments

Comments

Projects
None yet

None of my tests are running since I am upgraded to the latest 2.0-alpha-2. With 2.0-alpha-1 everything worked fine. I created a Gist with the full callstack

Contributor

cowst commented Mar 1, 2013

I have exactly the same problem

sshogunn commented Mar 5, 2013

I have the same problem. Roboelectric could you share solution of this problem?

I see that implementation of Uri.parse(String uriString) has been removed from current build. I'd suggest to copy the implementation form Android sources and create yours ShadowUri for this moment.

Contributor

pgoodwin commented Mar 21, 2013

I'm in the middle of porting a project to Robolectric 2.0 and Fest. We were seeing this problem early in the process, but when we fixed a different problem related to Fest, it went away. Now I think the real problem is just masked. I'll look into it today.

Owner

xian commented Mar 25, 2013

Robolectric should be using the real SDK's implementation of Uri, no shadow should be needed. Maybe I had something in the shadowing config (Setup class) wrong?

I'm trying to reproduce this possible bug but without any success so far.
In tag robolectric-2.0-alpha-2 there is a UriTest class which constructs sample URI and tries to parse it. Test passes. Could you provide any samples, wider context to catch the problem?

Here is a thread dump which proves that Android Uri.parse() method is being used (no shadow method)

main@1, prio=5, in group 'main', status: 'RUNNING'
      at android.net.Uri.parse(Uri.java:-1)
      at org.robolectric.shadows.UriTest.shouldParseUris(UriTest.java:15)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)

Thanks for the link, but it seems to be invalid. Could you provide the valid one?
Did you mean https://groups.google.com/forum/?fromgroups=#!searchin/robolectric/stub/robolectric/Ca0s8ocVL6M/Lf-docZf8mIJ ?

Ok sorry, now it works. I'm investigating the problem...

Well, actually in Gist the problem is about creating android.net.Uri instance by static Uri.parse(String) method. It occurs not in the entire test method but in ShadowMediaStore.reset() method which tries to construct some instances of Uri classes and is called by RobolectricTestRunner

public static void reset() {
        Robolectric.Reflection.setFinalStaticField(MediaStore.Images.Media.class, "EXTERNAL_CONTENT_URI",
                Uri.parse("content://media/external/images/media"));
       [more simillar method here]
    }

Unfortunately, so far I have no clue why you encounter Stub!. Seems that Robolectric provides real Uri implementation which is copied directly from android.net.Uri class. This copied class is android.net.Uri__fromAndroid and this implementation is used when no shadow for this class exists.

I've created some sample tests of parsing Uris and the passes all the time, even on robolectric-2.0-alpha-2 tag.

I'll appreciate any other hints, circumstances under which you have the above problem.

Contributor

pgoodwin commented Mar 28, 2013

That reset() method is probably being called either outside of the
instrumenting classloader or before instrumemtation is complete. Most
likely the former.
On Mar 27, 2013 8:12 AM, "Mateusz Grzechociński" notifications@github.com
wrote:

Well, actually in Gisthttps://gist.github.com/ScreenDriver/28c7d94acc08afca64ffthe problem is about creating
android.net.Uri instance by static Uri.parse(String) method. It occurs
not in the entire test method but in ShadowMediaStore.reset() method
which tries to construct some instances of Uri classes and is called by
RobolectricTestRunner

public static void reset() {
Robolectric.Reflection.setFinalStaticField(MediaStore.Images.Media.class, "EXTERNAL_CONTENT_URI",
Uri.parse("content://media/external/images/media"));
[more simillar method here]
}

Unfortunately, so far I have no clue why you encounter Stub!. Seems that
Robolectric provides real Uri implementation which is copied directly from
android.net.Uri class. This copied class is android.net.Uri__fromAndroidand this implementation is used when no shadow for this class exists.

I've created some sample tests of parsing Uris and the passes all the
time, even on robolectric-2.0-alpha-2 tag.

I'll appreciate any other hints, circumstances under which you have the
above problem.


Reply to this email directly or view it on GitHubhttps://github.com/pivotal/robolectric/issues/426#issuecomment-15529087
.

Has anyone managed to find a workaround for this?

Contributor

esam091 commented Mar 30, 2013

I have the same issue on my Windows 7, but there's no problem using it on Mac so far. My workaround is to override useAsm method to return false, so I'm using Javassist right now.

Contributor

acc15 commented Apr 2, 2013

Overriding useAsm does the trick. Thanks to esam091. Waiting for fix.

mjurkus commented Apr 8, 2013

I have similar problem with 2.0-alpha-1 and 2.0-alpha-2

Unfortunately overriding useAsm in 2.0-alpha-2 does not help. Is there anything I can do to resolve this issue?

java.lang.RuntimeException: Stub!
    at org.apache.http.conn.scheme.SchemeRegistry.<init>(SchemeRegistry.java:4)
    at org.springframework.http.client.HttpComponentsClientHttpRequestFactory.<init>(HttpComponentsClientHttpRequestFactory.java:75)
    at org.springframework.http.client.support.HttpAccessor.<init>(HttpAccessor.java:55)
    at org.springframework.http.client.support.InterceptingHttpAccessor.<init>(InterceptingHttpAccessor.java:35)
    at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:169)
    at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:158)
    at com.application.rest.RestClient_.<init>(RestClient_.java:28)
    at com.application.services.StationServiceTest.setUp(StationServiceTest.java:32)
Contributor

esam091 commented Apr 9, 2013

Have you set the Robolectric jar loading priority above the Android SDK? Do you have problems when using other shadow classes?

mjurkus commented Apr 9, 2013

Same issue occurred when launching from console and from IDE. In IDE Robolectric jar together with JUnit jar is above Android SDK.
Other tests that do not involve org.apache.http.conn.scheme.SchemeRegistry passed just fine.

Contributor

acc15 commented Apr 9, 2013

I think that this problem is digged somewhere in AsmInstrumentingClassLoader which instruments some android classes.

I try to enable debug (set variable debug=true in AsmInstrumentingClassLoader class) and there is a classes which i get:
https://dl.dropbox.com/u/28414631/Instrumented.7z
If u decompile them, then u see "new RuntimeException("Stub!")" in almost every method.

After detailed investigation and a lot of debugging of AsmInstrumentingClassLoader i found a method getInstrumentedBytes which, as i understand, should insert method implementations from Uri_FromAndroid.
But (as you can see in generated classes) it simply creates wrapper with call to original method and calls to RobolectricInternals.

I just can't find the point where Robolectric should delegate calls from android.net.Uri to android.net.Uri__FromAndroid.
Maybe it should happen more earlier and AsmInstrumentingClassLoader isn't a class to look for this issue...

Help, please.

BTW, Robolectic is the first in classpath.

Windows 7 x64
C:\Program Files\Java\jdk1.7.0\bin>java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

Contributor

cowst commented Apr 9, 2013

perhaps it does not matter, but the only time i could build and run tests
from alpha2 i was on linux.
last time i checked, i have over 3 windows machines all failing on Stub
Parse_Uri (or something similar).

On Tue, Apr 9, 2013 at 1:50 PM, acc15 notifications@github.com wrote:

I think that this problem is digged somewhere in
AsmInstrumentingClassLoader which instruments some android classes.

I try to enable debug (set variable debug=true in
AsmInstrumentingClassLoader class) and there is a classes which i get:
https://dl.dropbox.com/u/28414631/Instrumented.7z
If u decompile them, then u see "new RuntimeException("Stub!")" in almost
every method.

After detailed investigation and a lot of debugging of
AsmInstrumentingClassLoader i found a method getInstrumentedBytes which, as
i understand, should insert method implementations from Uri_FromAndroid.
But (as you can see in generated classes) it simply creates wrapper with
call to original method and calls to RobolectricInternals.

I just can't find the point where Robolectric should delegate calls from
android.net.Uri to android.net.Uri__FromAndroid.
Maybe it should happen more earlier and AsmInstrumentingClassLoader isn't
a class to look for this issue...

Help, please.

Windows 7 x64
C:\Program Files\Java\jdk1.7.0\bin>java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)


Reply to this email directly or view it on GitHubhttps://github.com/pivotal/robolectric/issues/426#issuecomment-16108036
.

Contributor

esam091 commented Apr 9, 2013

@mjurkus the SchemeRegistry class works fine on my machine, Are you using robolectric-2.0-alpha-2.jar? Then maybe you are using the SchemeRegistry from android.jar which has the stub implementation. Try using robolectric-2.0-alpha-2-jar-with-dependencies.jar, it has the real implementation of SchemeRegistry class, or you can download separate http jars from Apache.

@cowst I only have the Uri problem only on my Windows too, it works fine on Mac and Ubuntu.

I have the same problem :-(

Contributor

cowst commented Apr 9, 2013

i suspect deep down it might be a slashes vs. backslashes problem... :)
i already pushed a patch on a couple of tests exactly on that.

On Tue, Apr 9, 2013 at 2:29 PM, esam091 notifications@github.com wrote:

@mjurkus https://github.com/mjurkus the SchemeRegistry class works fine
on my machine, Are you using robolectric-2.0-alpha-2.jar? Then maybe you
are using the SchemeRegistry from android.jar which has the stub
implementation. Try using
robolectric-2.0-alpha-2-jar-with-dependencies.jar, it has the real
implementation of SchemeRegistry class, or you can download separate http
jars from Apache.

@cowst https://github.com/cowst I only have the Uri problem only on my
Windows too, it works fine on Mac and Ubuntu.


Reply to this email directly or view it on GitHubhttps://github.com/pivotal/robolectric/issues/426#issuecomment-16109531
.

acc15 referenced this issue Apr 9, 2013

Merged

fixed Uri issue #458

Contributor

acc15 commented Apr 9, 2013

Found how-to fix for android.net.Uri:
pivotal#458

Uri class isn't taken (neither on Unix, nor on Windows) from Uri__FromAndroid, its taken from Maven repository org.robolectric:android-base: dependency.

Works on Windows now.

But didn't work on Unix... )))

Works on Unix now.

Write once. Debug everywhere.

Owner

xian commented Apr 13, 2013

Thank you @acc15!

xian closed this Apr 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment