On 07/08/2013, at 2:06, Xavier Ducrohet <x...@google.com> wrote:
> I'm looking at JavaMethod.invoke and it seems to do that if the thrown > exception is not a RuntimeException. > > This code is fairly old though. Did something else change in the way > decorated groovy classes invoke their methods? Yes, we had to take over more method dispatch logic. The net result is that we've lost some of Groovy's behaviour when calling private methods but I'm not exactly sure what. It would help to see the method params and what it is being called with. > > I tried to move my code out of the task classes into a Java class but ran > into other problems (see my next email). So I moved the code to a different > Groovy class and it's working now, so it seems to be really something that > impact decorated methods only. > > > On Tue, Aug 6, 2013 at 5:51 PM, Xavier Ducrohet <x...@google.com> wrote: >> I just encountered something very very strange in 1.7. >> >> I rarely run this code, but I ran it on 1.6 with no issue. I'm trying to run >> it with 1.7 (to update some of our local prebuilts to update to 1.7) and >> it's failing with something that makes no sense. >> >> I have a Groovy class that extends DefaultTask and looks something like this: >> >> class DownloadArtifactsTask extends DefaultTask { >> @TaskAction >> void something() { >> pullArtifact(...); >> } >> >> private void pullArtifact(...) { >> try { >> downloadFile(...) >> } catch (IOException e2) { >> // ignore >> } >> } >> >> private File downloadFile(...) throws IOException { >> if (...) { >> throw new IOException(...); >> } >> } >> } >> >> >> What happens is that when downloadFile throws an IOException, it's not >> caught in pullArtifact. I was really confused at first. So I put a catch on >> Throwable, and noticed that my original exception was encapsulated in a >> GradleException. >> >> Nothing in my code does this obviously. The stack trace looks like this: >> >> org.gradle.api.GradleException: Could not call >> DownloadArtifactsTask.downloadFile() on task ':downloadArtifacts' >> at org.gradle.util.JavaMethod.invoke(JavaMethod.java:69) >> at >> org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:295) >> at >> org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) >> at >> org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) >> at >> com.android.build.gradle.buildsrc.DownloadArtifactsTask_Decorated.invokeMethod(Unknown >> Source) >> at >> org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) >> at >> org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55) >> at >> com.android.build.gradle.buildsrc.DownloadArtifactsTask.pullArtifact(DownloadArtifactsTask.groovy:204) >> .... >> Caused by: java.io.FileNotFoundException: http://xxx >> at >> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1434) >> at java.net.URL.openStream(URL.java:1010) >> at org.apache.commons.io.FileUtils.copyURLToFile(FileUtils.java:844) >> at org.apache.commons.io.FileUtils$copyURLToFile.call(Unknown Source) >> at >> com.android.build.gradle.buildsrc.DownloadArtifactsTask.downloadFile(DownloadArtifactsTask.groovy:256) >> >> >> DownloadArtifactsTask.groovy:204 is where downloadFile() is called. >> >> Anyone has a clue? >