Skip to content

FileChannelCache.tryLockFor creates empty files #3076

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

Closed
EmmanuelRoux opened this issue Oct 10, 2019 · 0 comments · Fixed by #3077
Closed

FileChannelCache.tryLockFor creates empty files #3076

EmmanuelRoux opened this issue Oct 10, 2019 · 0 comments · Fixed by #3077
Milestone

Comments

@EmmanuelRoux
Copy link
Contributor

EmmanuelRoux commented Oct 10, 2019

Hi all

FileChannelCache.tryLockFor(File) actually creates an empty file when trying to get a lock on a non-existent file.

It seems to be caused by line 56 FileChannel newChannel = new RandomAccessFile(fileToLock, "rw").getChannel(); which opens the file using "rw" mode (create the file if it does not exist)

Tested on v5.1.5.RELEASE, seems to still be the same on v5.2.0.RELEASE.

It may be better to either :

  • throw an exception to indicate the file does not exist
  • return a specific value to indicate the file does not exist
  • or just document that behavior

To reproduce, just call :

FileChannelCache.tryLockFor(new File("/a/file/that/does/not/exists.txt"));

Thanks!

@garyrussell garyrussell added this to the 5.2.1 milestone Oct 10, 2019
EmmanuelRoux added a commit to EmmanuelRoux/spring-integration that referenced this issue Oct 11, 2019
EmmanuelRoux added a commit to EmmanuelRoux/spring-integration that referenced this issue Oct 17, 2019
EmmanuelRoux added a commit to EmmanuelRoux/spring-integration that referenced this issue Oct 17, 2019
EmmanuelRoux added a commit to EmmanuelRoux/spring-integration that referenced this issue Oct 17, 2019
EmmanuelRoux added a commit to EmmanuelRoux/spring-integration that referenced this issue Oct 17, 2019
artembilan pushed a commit that referenced this issue Oct 17, 2019
Fixes #3076

* Return `null` instead of throwing an exception

* Fix license header

* Add missing `@since`

* Avoid over-engineered test logic

* Fix code style

* Test non-existent file does not get created

* Fix: remove unused import
artembilan pushed a commit that referenced this issue Oct 17, 2019
Fixes #3076

* Return `null` instead of throwing an exception

* Fix license header

* Add missing `@since`

* Avoid over-engineered test logic

* Fix code style

* Test non-existent file does not get created

* Fix: remove unused import
artembilan pushed a commit that referenced this issue Oct 17, 2019
Fixes #3076

* Return `null` instead of throwing an exception

* Fix license header

* Add missing `@since`

* Avoid over-engineered test logic

* Fix code style

* Test non-existent file does not get created

* Fix: remove unused import

* Remove Java 8 constructions; revert AssertJ to regular JUnit assertions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants