apache / apache/netbeans

"LockForFile" locks every file with the same name

Open
#6,077 0 comments 0 reactions 0 assignees View on GitHub
kind:bug needs:triage
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 18

### What happened

I think that I found a strange behavior in org.netbeans.modules.masterfs.filebasedfs.fileobjects.LockForFile:hardLock#289. As I see, the outer Namesakes will be created for every filename and will be reused, if a file (even in another folder) has to be locked. So, if a lock gets inserted via "putInstance(File, LockForFile)", ALL files with the same name get hardLocked, if they don't exist.
That means, that, if I create fileobjects (and retrieve their outputstream by "getOutputStream()") in parallel, it may be possible that the hardLock fails, because it already registered a lock during its own creation.

Maybe a more practical thought here:
- Thread1: FileObject A gets created; Retrieve the outputStream; Write something in it; Close
- Thread2: During A-Creation it creates a new FileObject, with THE SAME NAME, but in a different path. This will cause a FileAlreadyLockedException, even if it should be possible.

What do you think about this thought? Is it possible, or am I completely wrong?

### How to reproduce

_No response_

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Mac OSX

### JDK

13

### Apache NetBeans packaging

Apache NetBeans platform

### Anything else

_No response_

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Start by reading org.netbeans.modules.masterfs.filebasedfs.fileobjects.LockForFile, especially hardLock#289 and putInstance(File, LockForFile), to trace how Namesakes are keyed and reused. Reproduce the parallel output-stream scenario with same-named files in different folders, then verify that locking one file does not cause FileAlreadyLockedException for the other.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.