Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4990650
Votes 0
Synopsis REG: File.getCanonicalPath returns incorrect results after a case-only rename
Category java:classes_io
Reported Against 1.4.2_04 , tiger-beta2
Release Fixed 1.5(tiger-b40)
State 10-Fix Delivered, bug
Priority: 2-High
Related Bugs 4895132
Submit Date 07-FEB-2004
Description
description: FULL PRODUCT VERSION :
The bug occurs on:
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

and

java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

It does NOT occur under
java version "1.4.1_05"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.1_05-b01)
Java HotSpot(TM) Client VM (build 1.4.1_05-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
 customer  Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
File.getCanonicalPath() seems to be caching the result in a way
that
gives incorrect results after the file has been renamed to a
different
case on Windows.

This is happening in 1.4.2_03 and 1.5.0beta, but did not occur
under
1.4.1_05.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
if there is a file Foo on the disk, the following code shows the
error:

File f = new File("Foo");
System.out.println("before: " + f.getCanonicalPath());
f.renameTo(new File("foo"));
System.out.println("after: " + f.getCanonicalPath());

Or, run the attached program as "java -cp . test.RenameTest Foo
foo".


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
before: c:\test\Foo
after: c:\test\foo
ACTUAL -
before: c:\test\Foo
after: c:\test\Foo

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package test;

import java.io.File;
import java.io.IOException;

public class RenameTest
{ 
    public static void main(String[] args)
    {
        if (!(args.length == 2))
        {
            System.out.println("must specify from and to
filenames.");
            return;
        }
        
        File f1 = new File(args[0]);
        File f2 = new File(args[1]);

        try
        {
            System.out.println("old canonical: " +
f1.getCanonicalPath());
            System.out.println("old1 canonical: " + new
File(args[0]).getCanonicalPath());
            System.out.println("old2 canonical: " + new
File(args[1]).getCanonicalPath());
            if (!f1.renameTo(f2))
            {
                System.out.println("failed to rename " + args[0] +
" to
" + args[1]);
                return;
            }
            System.out.println("new canonical: " +
f1.getCanonicalPath());
            System.out.println("new1 canonical: " + new
File(args[0]).getCanonicalPath());
            System.out.println("new2 canonical: " + new
File(args[1]).getCanonicalPath());
            
        }
        catch (IOException ioe)
        {
            assert false: ioe;
        }
    }
} 
Work Around
-Dsun.io.useCanonCaches=false
Evaluation
This is a bug in java.io.WinNTFileSystem. The intent was to clear out the
canonicalization caches upon rename or deletion operations; this is done
correctly in Win32FileSystem. WinNTFileSystem overrides the wrong methods from
Win32FileSystem, causing the canonicalization cache cleanup to be skipped.

  xxxxx@xxxxx   2004-02-10


Fixed in 1.5.0 b40.

  xxxxx@xxxxx   2004-02-13
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang