You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by "Vladimir Ivanov (JIRA)" <ji...@apache.org> on 2006/02/13 10:32:46 UTC

[jira] Commented: (HARMONY-53) java.io.File.hashCode() returns incorrect value

    [ http://issues.apache.org/jira/browse/HARMONY-53?page=comments#action_12366168 ] 

Vladimir Ivanov commented on HARMONY-53:
----------------------------------------

At revision 377324 it is look OK. 

> java.io.File.hashCode() returns incorrect value
> -----------------------------------------------
>
>          Key: HARMONY-53
>          URL: http://issues.apache.org/jira/browse/HARMONY-53
>      Project: Harmony
>         Type: Bug
>   Components: Classlib
>  Environment: windows
>     Reporter: Vladimir Ivanov
>     Assignee: Tim Ellison

>
> java.io.File.hashCode() returns incorrect value
> j2se 1.4.2 and 1.5.0 says for the java.io.File.hashCode() method: 
> 'On Microsoft Windows systems, the hash code is equal to the exclusive or of its pathname string, convered to lower case, and the decimal value 1234321.' 
> Seems, that conversion to the lower case is missed. 
> Code to reproduce:
> import java.io.*; 
>   
> public class test29 { 
>     public static void main(String[] args)  {
> 	String fname = "Test file name.tst"; 
> 	File ifile = new File(fname); 
> 	int hash = 0; 
> 	System.out.println("fname.hashCode() ^ 1234321 = " + (fname.hashCode() ^ 1234321)); 
> 	if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { 
> 		hash = fname.toLowerCase().hashCode() ^ 1234321; 
> 	} else { 
> 		hash = fname.hashCode() ^ 1234321; 
> 	} 
> 	if (ifile.hashCode() != hash) { 
> 		System.out.println("FAILED, hashCode is " + ifile.hashCode() + ", expected " + hash); 
> 	} else { 
> 		System.out.println("PASSED, hashCode is " + ifile.hashCode() + ", expected " + hash); 
> 	} 
>    } 
> }  
> Steps to Reproduce: 
> 1. Build Harmony (check-out on 2006-01-25) j2se subset as described in README.txt. 
> 2. Compile test29.java using BEA 1.4 javac 
> > javac -d . test29.java 
> 3. Run java using compatible VM (J9) 
> > java -showversion test29
> Output:
> C:\tmp\tmp17>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test29
> java version "1.4.2_04"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM  (build ari-31788-20040616-1132-win-ia32,
> Native Threads, GC strategy: parallel)
> fname.hashCode() ^ 1234321 = -229253447
> PASSED, hashCode is -2070832487, expected -2070832487
> C:\tmp\tmp17>C:\harmony\trunk\deploy\jre\bin\java -showversion test29
> java version 1.4.2 (subset)
> (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as app
> licable.
> fname.hashCode() ^ 1234321 = -229253447
> FAILED, hashCode is -229253447, expected -2070832487
> C:\tmp\tmp17>
> junit test:
> ------------------------ FileTest.java -------------------------------------------------
> import java.io.*; 
> import junit.framework.*; 
>   
> public class FileTest extends TestCase { 
>     public static void main(String[] args) { 
>         junit.textui.TestRunner.run(FileTest.class); 
>     } 
>     public void testHashCode() { 
> 	String fname = "Test file name.tst"; 
> 	File ifile = new File(fname); 
> 	int hash = 0; 
> 	if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { 
> 		hash = fname.toLowerCase().hashCode() ^ 1234321; 
> 	} else { 
> 		hash = fname.hashCode() ^ 1234321; 
> 	}
> 	assertTrue("FAILED, hashCode is " + ifile.hashCode() + ", expected " + hash, ifile.hashCode() == hash);
>     }
> } 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira