2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
5506
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
2
|
22 |
*/
|
|
23 |
|
|
24 |
/* @test
|
|
25 |
@bug 4141318
|
|
26 |
@summary Check that equal File instances have identical hash codes
|
|
27 |
*/
|
|
28 |
|
|
29 |
import java.io.File;
|
|
30 |
|
|
31 |
|
|
32 |
public class HashCodeEquals {
|
|
33 |
|
|
34 |
static void test(String fn1, String fn2) throws Exception {
|
|
35 |
File f1 = new File(fn1);
|
|
36 |
File f2 = new File(fn2);
|
|
37 |
if (!f1.equals(f2))
|
|
38 |
throw new Exception("Instances with equal paths are not equal");
|
|
39 |
int h1 = f1.hashCode();
|
|
40 |
int h2 = f2.hashCode();
|
|
41 |
if (h1 != h2)
|
|
42 |
throw new Exception("Hashcodes of equal instances are not equal");
|
|
43 |
}
|
|
44 |
|
|
45 |
static void testWin32() throws Exception {
|
|
46 |
test("a:/foo/bar/baz", "a:/foo/bar/baz");
|
|
47 |
test("A:/Foo/Bar/BAZ", "a:/foo/bar/baz");
|
|
48 |
}
|
|
49 |
|
|
50 |
static void testUnix() throws Exception {
|
|
51 |
test("foo/bar/baz", "foo/bar/baz");
|
|
52 |
}
|
|
53 |
|
|
54 |
public static void main(String[] args) throws Exception {
|
|
55 |
if (File.separatorChar == '\\') testWin32();
|
|
56 |
if (File.separatorChar == '/') testUnix();
|
|
57 |
}
|
|
58 |
|
|
59 |
}
|