Gradle hangs in project.exec when environment contains key as a GString


(Bronislav Gabrhelik) #1

I ran into this problem with more difficult build containing custom plugins, so I tried to narrow down the build script which is here

class ExecCommand extends DefaultTask {
 Map<String, String>
 environment = [:];
    @TaskAction
  public void action() {
          ExecResult execResult = project.exec {
            executable 'cmd.exe'
           if (this.environment != null) {
                environment this.environment;
            }
            args
"/c", "SET"
             println "command " + commandLine
         }
        println "exec result " + execResult.toString()
  }
}
  ext.arch = 'x86'
ext.jdkHome = new File('C:\Program Files\Java\jdk1.7.0_25');
  afterEvaluate {
   project.tasks.withType(ExecCommand.class).all { task ->
   task.environment = ["JDK_HOME_${arch.toUpperCase()}" : jdkHome]
  }
}
  task showEnvironment(type: ExecCommand)

I figured out that when I cast GString to String the hang disappears.

task.environment = [(("JDK_HOME_${arch.toUpperCase()}").toString()) : jdkHome]

It seems that Groovy doesn’t convert the key of class GString into String when it is added into Map<String, String> which is weird. I know Generics are de facto Objects, but groovy is weak typing language so I would expect implicit conversion.

I monitored Gradle activity by Sysinternals ProcMon and command is not executed at all. I can also repro hang on Mac OS X, so it seems it is platform independent. I guess it might be some deadlock during evaluation of GString and accessing an extension. I also don’t understand why there is a lazy evaluation of GString in effect.

Note that when I put action into “simple” task I cannot repro it.

I appreciate if someone can shed light on what’s going on.

Thanks, Bronislav Gabrhelik


(Peter Niederwieser) #2

I don’t know why this makes the task hang. However, there is no way for Groovy to figure out that the keys are supposed to be Strings, and it’s expected that you have to convert them yourself (if necessary).


(Bronislav Gabrhelik) #3

Peter,

the usage of ‘GString’ in Gradle is quite common and I am pointing out to hang of Gradle into which can any user easily get into. Shouldn’t be the conversion to String enforced by ‘ExecSpec.environment()’ methods?

I spend some time to debug this problem. Here is an information about state and location of problem.

The main thread executes the task in special thread in ‘org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl’ runnable instance. The exception ‘ClassCastException’ is thrown from the executed code so runnable instance ends its execution, but it leaves the main thread without notification it should leave the wait state.

Here is the location from which is an exception thrown

java.util.HashMap.putAll(HashMap.java:622)
org.gradle.process.internal.ProcessBuilderFactory.createProcessBuilder(ProcessBuilderFactory.java:40)
org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:65)
org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

The exception is ‘ClassCastException’ with description ‘org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String’. It shows that there is a general problem here. If the code which is outside of try block in the ‘org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:64)’ method throws an exception it causes the hang.

It is catched here, but it is not logged or handled.

org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:68)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:724)

The main thread hangs in this location sun.misc.Unsafe.park(Unsafe.java) java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) org.gradle.process.internal.DefaultExecHandle.start(DefaultExecHandle.java:236) org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:37) org.gradle.api.internal.file.DefaultFileOperations.exec(DefaultFileOperations.java:164) org.gradle.api.internal.project.AbstractProject.exec(AbstractProject.java:829) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248) org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) org.gradle.api.internal.project.DefaultProject_Decorated.invokeMethod org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ExecCommand.action(D:\Projects\externals\gradle\reprohang sun.misc.Unsafe.park(Unsafe.java) java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) org.gradle.process.internal.DefaultExecHandle.start(DefaultExecHandle.java:236) org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:37) org.gradle.api.internal.file.DefaultFileOperations.exec(DefaultFileOperations.java:164) org.gradle.api.internal.project.AbstractProject.exec(AbstractProject.java:829) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248) org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) org.gradle.api.internal.project.DefaultProject_Decorated.invokeMethod org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ExecCommand.action(D:\Projects\externals\gradle\reprohang sun.misc.Unsafe.park(Unsafe.java) java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) org.gradle.process.internal.DefaultExecHandle.start(DefaultExecHandle.java:236) org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:37) org.gradle.api.internal.file.DefaultFileOperations.exec(DefaultFileOperations.java:164) org.gradle.api.internal.project.AbstractProject.exec(AbstractProject.java:829) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248) org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) org.gradle.api.internal.project.DefaultProject_Decorated.invokeMethod org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ExecCommand.action(D:\Projects\externals\gradle\reprohang sun.misc.Unsafe.park(Unsafe.java) java.util.concurrent.locks.LockSupport.park(LockSupport.java:186) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043) org.gradle.process.internal.DefaultExecHandle.start(DefaultExecHandle.java:236) org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:37) org.gradle.api.internal.file.DefaultFileOperations.exec(DefaultFileOperations.java:164) org.gradle.api.internal.project.AbstractProject.exec(AbstractProject.java:829) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248) org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) org.gradle.api.internal.project.DefaultProject_Decorated.invokeMethod org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ExecCommand.action(D:\Projects\externals\gradle\reprohang\02\build.gradle:7) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248) org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) ExecCommand_Decorated.invokeMethod sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248) org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) ExecCommand_Decorated.invokeMethod org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23) org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:220) org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:213) org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:202) org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:530) org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:513) org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80) org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61) org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62) org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42) org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:286) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:80) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTaskWithCacheLock(AbstractTaskPlanExecutor.java:58) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:47) org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33) org.gradle.internal.Factories$1.create(Factories.java:22) org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:214) org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:276) org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142) org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78) org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31) org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89) org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29) org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23) org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67) org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54) org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166) org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113) org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81) org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64) org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33) org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24) org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35) org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26) org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50) org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171) org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201) org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174) org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170) org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139) org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33) org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22) org.gradle.launcher.Main.doAction(Main.java:48) org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) org.gradle.launcher.Main.main(Main.java:39) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50) org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32) org.gradle.launcher.GradleMain.main(GradleMain.java:26) 2\build.gradle:7) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248) org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) ExecCommand_Decorated.invokeMethod sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248) org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) ExecCommand_Decorated.invokeMethod org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23) org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:220) org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:213) org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:202) org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:530) org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:513) org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80) org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61) org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62) org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42) org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:286) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:80) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTaskWithCacheLock(AbstractTaskPlanExecutor.java:58) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:47) org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33) org.gradle.internal.Factories$1.create(Factories.java:22) org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:214) org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:276) org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142) org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78) org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31) org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89) org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29) org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23) org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67) org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54) org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166) org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113) org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81) org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64) org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33) org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24) org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35) org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26) org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50) org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171) org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201) org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174) org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170) org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139) org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33) org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22) org.gradle.launcher.Main.doAction(Main.java:48) org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) org.gradle.launcher.Main.main(Main.java:39) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50) org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32) org.gradle.launcher.GradleMain.main(GradleMain.java:26) 2\build.gradle:7) sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248) org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) ExecCommand_Decorated.invokeMethod sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248) org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136) org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) ExecCommand_Decorated.invokeMethod org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23) org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:220) org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:213) org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:202) org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:530) org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:513) org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80) org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61) org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62) org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42) org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:286) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:80) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTaskWithCacheLock(AbstractTaskPlanExecutor.java:58) org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:47) org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33) org.gradle.internal.Factories$1.create(Factories.java:22) org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:214) org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:276) org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142) org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78) org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31) org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89) org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29) org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23) org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67) org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54) org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166) org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113) org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81) org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64) org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33) org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24) org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35) org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26) org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50) org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171) org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201) org.gradle.launcher.cl


(Peter Niederwieser) #4

Why is a ‘ClassCastException’ thrown? Can you show that trace?


(Bronislav Gabrhelik) #5

Well it is thrown from method java.util.HashMap.putAll(HashMap.java:622) - see the first code listing above. I cannot provide deeper stack trace as I debug unmodified Gradle 1.7 release and logging of this exception is omitted in catch block.

} catch (Throwable throwable) {
                        if (!failure.compareAndSet(null, throwable)) {
                            LOGGER.error(String.format("Failed to execute %s.", command), throwable);
                        }
                    }

To be honest I don’t know how to gain the stack trace from the debugger. I just see an exception instance but stack trace cannot be expanded. However I try to modify and recompile Gradle sources to log this exception so we see the exact throw location.


(Bronislav Gabrhelik) #6

I have added the logging into catch block above so it is not under condition. Here is an exception stack trace.

Failed to execute org.gradle.process.internal.ExecHandleRunner@69c41ba8.
java.lang.ClassCastException: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String
 at java.lang.ProcessEnvironment$StringEnvironment.put(ProcessEnvironment.java:220)
 at java.util.AbstractMap.putAll(AbstractMap.java:273)
 at org.gradle.process.internal.ProcessBuilderFactory.createProcessBuilder(ProcessBuilderFactory.java:40)
 at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:65)
 at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at java.lang.Thread.run(Thread.java:724)

(Bronislav Gabrhelik) #7

It seems that this issue is abandoned. Can be created a JIRA issue for this? I suppose I cannot create a JIRA isuue.

The matter of the problem is that the Gradle swallows an exception here

org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run

,the Runnable exits and the main thread is in infinite wait. As Gradle doesn’t log an exception it requires big effort to figure out the root cause of problem (GString passed to java.lang.ProcessEnvironment$StringEnvironment).

The problem is very easy reproducible even on other platforms without any change of script provided because execute is not performed.

Thanks, Bronislav Gabrhelik


(Bronislav Gabrhelik) #8

The issue GRADLE-2896 has been created for this problem.