Corrupt cache using Gradle 1.7-rc-1?

The Groovy build just moved to Gradle 1.7-rc-1. While a first compilation worked, now if I run this:

./gradlew test installGroovy

I’m getting this error:

* Exception is:
org.gradle.api.UncheckedIOException: Could not read entry '/home/cchampeau/DEV/PROJECTS/GITHUB/groovy-core/target/classes/main/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.class' from cache fileHashes.bin (/home/cchampeau/DEV/PROJECTS/GITHUB/groovy-core/.gradle/1.7-rc-1/taskArtifacts/fileHashes.bin).
 at org.gradle.cache.internal.btree.BTreePersistentIndexedCache.get(BTreePersistentIndexedCache.java:127)
 at org.gradle.cache.internal.MultiProcessSafePersistentIndexedCache$1.create(MultiProcessSafePersistentIndexedCache.java:39)
 at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.readFile(DefaultFileLockManager.java:178)
 at org.gradle.cache.internal.DefaultCacheAccess$UnitOfWorkFileAccess.readFile(DefaultCacheAccess.java:357)
 at org.gradle.cache.internal.MultiProcessSafePersistentIndexedCache.get(MultiProcessSafePersistentIndexedCache.java:37)
 at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:601)
 at org.gradle.listener.LazyCreationProxy$LazyInvocationHandler.invoke(LazyCreationProxy.java:49)
 at $Proxy23.get(Unknown Source)
 at org.gradle.api.internal.changedetection.state.CachingHasher.hash(CachingHasher.java:34)
 at org.gradle.api.internal.changedetection.state.DefaultFileSnapshotter$1.run(DefaultFileSnapshotter.java:48)
 at org.gradle.internal.Factories$1.create(Factories.java:22)
 at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:143)
 at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:131)
 at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
 at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:74)
 at org.gradle.api.internal.changedetection.state.DefaultFileSnapshotter.snapshot(DefaultFileSnapshotter.java:44)
 at org.gradle.api.internal.changedetection.state.OutputFilesSnapshotter.snapshot(OutputFilesSnapshotter.java:81)
 at org.gradle.api.internal.changedetection.state.OutputFilesSnapshotter.snapshot(OutputFilesSnapshotter.java:41)
 at org.gradle.api.internal.changedetection.rules.OutputFilesStateChangeRule.create(OutputFilesStateChangeRule.java:34)
 at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.<init>(TaskUpToDateState.java:45)
 at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.java:127)
 at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStateRepository.java:69)
 at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:50)
 at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
 at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
 at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
 at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
 at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
 at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:286)
 at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:86)
 at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:72)
 at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTaskWithCacheLock(AbstractTaskPlanExecutor.java:64)
 at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:54)
 at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:34)
 at org.gradle.internal.Factories$1.create(Factories.java:22)
 at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:214)
 at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:276)
 at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
 at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78)
 at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
 at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89)
 at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
 at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
 at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
 at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
 at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
 at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
 at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
 at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
 at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
 at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
 at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
 at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
 at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
 at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
 at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45)
 at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:42)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:70)
 at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:68)
 at org.gradle.util.Swapper.swap(Swapper.java:38)
 at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:68)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
 at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:59)
 at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:45)
 at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(DaemonStateCoordinator.java:186)
 at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:49)
 at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:36)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
 at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:48)
 at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.handleCommand(DefaultIncomingConnectionHandler.java:155)
 at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.receiveAndHandleCommand(DefaultIncomingConnectionHandler.java:128)
 at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.run(DefaultIncomingConnectionHandler.java:116)
 at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
 at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassCastException: Cannot cast org.gradle.cache.internal.btree.BTreePersistentIndexedCache$IndexBlock to org.gradle.cache.internal.btree.BTreePersistentIndexedCache$DataBlock
 at java.lang.Class.cast(Class.java:3005)
 at org.gradle.cache.internal.btree.CachingBlockStore.read(CachingBlockStore.java:80)
 at org.gradle.cache.internal.btree.FreeListBlockStore.read(FreeListBlockStore.java:78)
 at org.gradle.cache.internal.btree.StateCheckBlockStore.read(StateCheckBlockStore.java:61)
 at org.gradle.cache.internal.btree.BTreePersistentIndexedCache$IndexBlock.get(BTreePersistentIndexedCache.java:445)
 at org.gradle.cache.internal.btree.BTreePersistentIndexedCache.get(BTreePersistentIndexedCache.java:117)
 ... 95 more

Looks like my cache is corrupt. Any idea of what’s happening?

If you blow away the cache, does it happen again?

I didn’t mention it, but removing .gradle/1.7-rc-1 of course fixed the problem.

Oh, this makes sense. We should detect that cache format has changed and invalidate it.

Hey,

Is the problem reproducible or it happened just once?

Until now, happened only once.

Did this happen on machine where you run multiple builds in parallel (e.g. a CI server) or where you use the --parallel option or where you use the Gradle daemon?

Hi Adam,

It happened on my laptop and as far as I can remember, I wasn’t running --parallel, nor daemon.

Hi!

I am resurecting this thread because I have a very similar problem again. I am setting up a new CI server for Groovy (TeamCity) and I am seeing lots of builds failing with:

‘’’ FAILURE: Build failed with an exception.

  • What went wrong: org.gradle.api.internal.changedetection.state.DefaultFileSnapshotter$FileCollectionSnapshotImpl cannot be cast to org.gradle.api.internal.changedetection.state.OutputFilesSnapshotter$OutputFilesSnapshot

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. ‘’’

At this point, I’m convinced this has something to do with the fact that I have multiple build agents running different JDK versions. Especially, one is running JDK 8. Each agent has a different build directory, but could it be possible that Gradle stores some cache outside of the working directory, for example in the user directory (which is shared, this time, between agents) ?

If yes, can this be avoided? Is there a command line switch that would prevent this from happening or can I clear the cache through a command line switch?

If you want to see by yourself: http://148.251.23.208:8111/project.html?projectId=Groovy&branch_Groovy=all_branches

(login: guest)

I’ll appreciate some help, because build are failing randomly because of that…

Is this with 1.7-rc-1 or with a more recent version?

It is using 1.10 (and the Gradle wrapper)

Can you point me to a build instance that failed?

This one failed, for example: http://ci.groovy-lang.org:8111/viewLog.html?buildId=23&tab=buildResultsDiv&buildTypeId=Groovy_Jdk7Build

Could you add --stacktrace so we can get the trace with 1.10 code and let us know when it happens again?

Ok, but for this to happen again, I need to remove the workaround (clean checkout for each build). Would be nice if Gradle stored the exception in a log file, because in general, you don’t want to re-run a build just to get the full stack trace.

Here you go! http://ci.groovy-lang.org:8111/viewLog.html?buildId=259&tab=buildResultsDiv&buildTypeId=Groovy_Jdk7Build

Thanks, I’m looking into it.

Another failure related to cache, yet not the same exception: http://ci.groovy-lang.org/viewLog.html?buildId=347&buildTypeId=Groovy_Jdk7Build

We’ve got a reasonable idea on what this might be. There’s some work planned for 1.2 that will address this. I’ll let you know as soon as it’s in a nightly, which should be pretty soon.

Thanks. I guess you meant 1.12?