langtools/test/tools/javac/T6705935.java
author jjg
Thu, 22 May 2008 17:40:53 -0700
changeset 657 99cc2b9325f2
child 731 1dd22bdb9ca5
permissions -rw-r--r--
6705935: javac reports path name of entry in ZipFileIndex incorectly Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
657
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     1
/*
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     4
 *
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     8
 *
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    13
 * accompanied this code).
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    14
 *
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    18
 *
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    21
 * have any questions.
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    22
 */
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    23
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    24
/*
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    25
 * @test
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    26
 * @bug 6705935
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    27
 * @summary javac reports path name of entry in ZipFileIndex incorectly
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    28
 */
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    29
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    30
import java.io.*;
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    31
import java.util.*;
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    32
import javax.tools.*;
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    33
import com.sun.tools.javac.util.*;
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    34
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    35
public class T6705935 {
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    36
    public static void main(String... args) throws Exception {
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    37
        new T6705935().run();
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    38
    }
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    39
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    40
    public void run() throws Exception {
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    41
        File java_home = new File(System.getProperty("java.home"));
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    42
        if (java_home.getName().equals("jre"))
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    43
            java_home = java_home.getParentFile();
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    44
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    45
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    46
        JavaFileManager fm = c.getStandardFileManager(null, null, null);
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    47
        for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    48
                                        "java.lang",
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    49
                                        Collections.singleton(JavaFileObject.Kind.CLASS),
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    50
                                        false)) {
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    51
            String p = ((BaseFileObject)fo).getPath();
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    52
            int bra = p.indexOf("(");
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    53
            int ket = p.indexOf(")");
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    54
            //System.err.println(bra + "," + ket + "," + p.length());
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    55
            if (bra == -1 || ket != p.length() -1)
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    56
                throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length());
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    57
            String part1 = p.substring(0, bra);
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    58
            String part2 = p.substring(bra + 1, ket);
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    59
            //System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    60
            if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    61
                throw new Exception("bad path: " + p);
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    62
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    63
        }
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    64
    }
99cc2b9325f2 6705935: javac reports path name of entry in ZipFileIndex incorectly
jjg
parents:
diff changeset
    65
}