RFR: 6244047: impossible to specify directories to logging FileHandler unless they exist

Jim Gish jim.gish at oracle.com
Tue Nov 13 18:25:27 UTC 2012


On 11/13/2012 07:08 AM, Alan Bateman wrote:
> On 12/11/2012 23:22, Jim Gish wrote:
>> Which file(s) are you concerned about truncating/damaging?  The code 
>> I'm impacting is for creating a new lock file.  Where is the 
>> potential for truncating/damaging that you both are referring to?
>>
>> Is this sufficient (plus the proper exception handling of course) ?
>>
>>                     //lockStream = new FileOutputStream(lockFileName);
>>                     fc = FileChannel.open(new 
>> File(lockFileName).toPath(), CREATE_NEW, WRITE);
>>                     //fc = lockStream.getChannel();
> CREATE rather than CREATE_NEW so that it doesn't fail if the lock file 
> already exists. Although it's just a lock file then I think it would 
> be impolite to truncate it.
>
> You could use Paths.get(lockFileName)rather than new 
> File(lockFileName).toPath() here but either is fine.
>
> -Alan.
I think we want it to fail if the lock file already exists.  That's why 
I used CREATE_NEW.  At least the way the logic is now, is that it 
attempts to create a new file and if it fails it tries again until it 
can create a new one.  It may be the case that the lockFileName is not 
in the locks map, and thus we don't own it, but it's possible that 
another JVM/app is logging in the same location. It, of course, would be 
bad practice, but not disallowed.  We shouldn't be grabbing a lock file 
that might otherwise be in use.

Jim

-- 
Jim Gish | Consulting Member of Technical Staff | +1.781.442.0304
Oracle Java Platform Group | Core Libraries Team
35 Network Drive
Burlington, MA 01803
jim.gish at oracle.com




More information about the core-libs-dev mailing list