test/jdk/java/io/File/UserDirChangedTest.java
author tschatzl
Wed, 24 Jul 2019 11:49:39 +0200
changeset 57508 28ab01c06755
parent 48927 847a988152b8
permissions -rw-r--r--
8228388: Add information about dirty/skipped card for Merge HCC in G1 log Summary: Collect and print informatio about the number of processed cards during the Merge HCC phase to improve log output. Reviewed-by: kbarrett, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48927
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
     1
/*
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
     4
 *
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
     8
 *
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    13
 * accompanied this code).
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    14
 *
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    18
 *
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    21
 * questions.
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    22
 */
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    23
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    24
/* @test
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    25
   @bug 8194154
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    26
   @summary Test changing property user.dir on impacting getCanonicalPath
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    27
   @run main/othervm UserDirChangedTest
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    28
 */
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    29
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    30
import java.io.File;
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    31
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    32
public class UserDirChangedTest {
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    33
    public static void main(String[] args) throws Exception {
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    34
        String keyUserDir = "user.dir";
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    35
        String userDirNew = "/home/a/b/c/";
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    36
        String fileName = "./a";
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    37
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    38
        String userDir = System.getProperty(keyUserDir);
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    39
        File file = new File(fileName);
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    40
        String canFilePath = file.getCanonicalPath();
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    41
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    42
        // now reset user.dir, this will cause crash on linux without bug 8194154 fixed.
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    43
        System.setProperty(keyUserDir,  userDirNew);
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    44
        String newCanFilePath = file.getCanonicalPath();
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    45
        System.out.format("%24s %48s%n", "Canonical Path = ", canFilePath);
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    46
        System.out.format("%24s %48s%n", "new Canonical Path = ", newCanFilePath);
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    47
        if (!canFilePath.equals(newCanFilePath)) {
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    48
            throw new RuntimeException("Changing property user.dir should have no effect on getCanonicalPath");
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    49
        }
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    50
    }
847a988152b8 8194154: System property user.dir should not be changed
minqi
parents:
diff changeset
    51
}