Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't remove file(which was read in reader) in afterStep listener on Windows [BATCH-2842] #772

spring-issuemaster opened this issue Sep 10, 2019 · 0 comments


Copy link

@spring-issuemaster spring-issuemaster commented Sep 10, 2019

Nikolay Tkachev opened BATCH-2842 and commented

When I run application on Windows mashine I experience following errror: 

2019-09-09 12:08:13.752 WARN 4028 --- [ main] c.b.m.b.RemovingListener : Failed to remove chunk 0b9a2623-b4c3-42b2-9acf-373a2d81007c.csv java.nio.file.FileSystemException: D:\chunk\1.csv: The process cannot access the file because it is being used by another process. at java.base/sun.nio.fs.WindowsException.translateToIOException( at java.base/sun.nio.fs.WindowsException.rethrowAsIOException( at java.base/sun.nio.fs.WindowsException.rethrowAsIOException( at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete( at java.base/sun.nio.fs.AbstractFileSystemProvider.deleteIfExists( at java.base/java.nio.file.Files.deleteIfExists( at my.super.project.batch.RemovingListener.afterStep( at my.super.project.batch.RemovingListener$$FastClassBySpringCGLIB$$e695a1e2.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke( at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint( at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed( at at at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed( at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept( at my.super.project.batch.RemovingListener$$EnhancerBySpringCGLIB$$10d47ff9.afterStep(<generated>)

please take a look SO topic for more details:


Source code to reproduce:



I found that it happens because of IO stream close(

) happens after listener invocation(
exitStatus = exitStatus.and(getCompositeListener().afterStep(stepExecution));
) so file can't be removed until the IO stream is not closed.

Affects: 4.2.0.RC1

Issue Links:

  • BATCH-2098 FileItemReader should close the underlying reader before the step listener
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.