6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
authorjjg
Wed, 23 Sep 2009 18:48:13 -0700
changeset 3995 73af8b6fb8bc
parent 3994 7df1ecd5eadb
child 3996 dc676a9093b3
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject. 6747645: ZipFileObject.getName is incorrectly deprecated 6885123: JavaFileObject getName issues Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/tools/apt/mirror/util/SourcePositionImpl.java
langtools/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java
langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java
langtools/src/share/classes/com/sun/tools/javac/file/Old199.java
langtools/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java
langtools/src/share/classes/com/sun/tools/javac/file/SymbolArchive.java
langtools/src/share/classes/com/sun/tools/javac/file/ZipArchive.java
langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java
langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java
langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java
langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
langtools/src/share/classes/com/sun/tools/javac/util/Log.java
langtools/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java
langtools/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java
langtools/src/share/classes/javax/tools/SimpleJavaFileObject.java
langtools/test/tools/javac/4241573/T4241573.java
langtools/test/tools/javac/6589361/T6589361.java
langtools/test/tools/javac/Diagnostics/6769027/T6769027.java
langtools/test/tools/javac/T6705935.java
langtools/test/tools/javac/api/6411310/T6411310.java
langtools/test/tools/javac/api/6411310/Test.java
langtools/test/tools/javac/api/6733837/T6733837.java
--- a/langtools/src/share/classes/com/sun/tools/apt/mirror/util/SourcePositionImpl.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/apt/mirror/util/SourcePositionImpl.java	Wed Sep 23 18:48:13 2009 -0700
@@ -67,15 +67,15 @@
     public String toString() {
         int ln = line();
         return (ln == Position.NOPOS)
-                ? sourcefile.toString()
-                : sourcefile + ":" + ln;
+                ? sourcefile.getName()
+                : sourcefile.getName() + ":" + ln;
     }
 
     /**
      * {@inheritDoc}
      */
     public File file() {
-        return new File(sourcefile.toString());
+        return new File(sourcefile.toUri());
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java	Wed Sep 23 18:48:13 2009 -0700
@@ -34,6 +34,7 @@
 import java.nio.charset.CharsetDecoder;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.NestingKind;
+import javax.tools.FileObject;
 import javax.tools.JavaFileObject;
 
 import static javax.tools.JavaFileObject.Kind.*;
@@ -49,33 +50,15 @@
         this.fileManager = fileManager;
     }
 
-    public JavaFileObject.Kind getKind() {
-        String n = getName();
-        if (n.endsWith(CLASS.extension))
-            return CLASS;
-        else if (n.endsWith(SOURCE.extension))
-            return SOURCE;
-        else if (n.endsWith(HTML.extension))
-            return HTML;
-        else
-            return OTHER;
-    }
+    /** Return a short name for the object, such as for use in raw diagnostics
+     */
+    public abstract String getShortName();
 
     @Override
     public String toString() {
-        return getPath();
+        return getClass().getSimpleName() + "[" + getName() + "]";
     }
 
-    /** @deprecated see bug 6410637 */
-    @Deprecated
-    public String getPath() {
-        return getName();
-    }
-
-    /** @deprecated see bug 6410637 */
-    @Deprecated
-    abstract public String getName();
-
     public NestingKind getNestingKind() { return null; }
 
     public Modifier getAccessLevel()  { return null; }
@@ -90,6 +73,17 @@
 
     protected abstract String inferBinaryName(Iterable<? extends File> path);
 
+    protected static JavaFileObject.Kind getKind(String filename) {
+        if (filename.endsWith(CLASS.extension))
+            return CLASS;
+        else if (filename.endsWith(SOURCE.extension))
+            return SOURCE;
+        else if (filename.endsWith(HTML.extension))
+            return HTML;
+        else
+            return OTHER;
+    }
+
     protected static String removeExtension(String fileName) {
         int lastDot = fileName.lastIndexOf(".");
         return (lastDot == -1 ? fileName : fileName.substring(0, lastDot));
@@ -115,6 +109,17 @@
         }
     }
 
+    /** Return the last component of a presumed hierarchical URI.
+     *  From the scheme specific part of the URI, it returns the substring
+     *  after the last "/" if any, or everything if no "/" is found.
+     */
+    public static String getSimpleName(FileObject fo) {
+        URI uri = fo.toUri();
+        String s = uri.getSchemeSpecificPart();
+        return s.substring(s.lastIndexOf("/") + 1); // safe when / not found
+
+    }
+
     /** The file manager that created this JavaFileObject. */
     protected final JavacFileManager fileManager;
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Wed Sep 23 18:48:13 2009 -0700
@@ -1116,36 +1116,6 @@
         throw new IllegalArgumentException("Invalid relative path: " + file);
     }
 
-    @SuppressWarnings("deprecation") // bug 6410637
-    public static String getJavacFileName(FileObject file) {
-        if (file instanceof BaseFileObject)
-            return ((BaseFileObject)file).getPath();
-        URI uri = file.toUri();
-        String scheme = uri.getScheme();
-        if (scheme == null || scheme.equals("file") || scheme.equals("jar"))
-            return uri.getPath();
-        else
-            return uri.toString();
-    }
-
-    @SuppressWarnings("deprecation") // bug 6410637
-    public static String getJavacBaseFileName(FileObject file) {
-        if (file instanceof BaseFileObject)
-            return ((BaseFileObject)file).getName();
-        URI uri = file.toUri();
-        String scheme = uri.getScheme();
-        if (scheme == null || scheme.equals("file") || scheme.equals("jar")) {
-            String path = uri.getPath();
-            if (path == null)
-                return null;
-            if (scheme != null && scheme.equals("jar"))
-                path = path.substring(path.lastIndexOf('!') + 1);
-            return path.substring(path.lastIndexOf('/') + 1);
-        } else {
-            return uri.toString();
-        }
-    }
-
     private static <T> T nullCheck(T o) {
         o.getClass(); // null check
         return o;
--- a/langtools/src/share/classes/com/sun/tools/javac/file/Old199.java	Wed Sep 23 18:29:41 2009 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
- * Copyright 2006-2008 Sun Microsystems, Inc.  All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package com.sun.tools.javac.file;
-
-import javax.tools.FileObject;
-
-/**
- * Provides an easy migration to JSR 199 v3.3.  The class is
- * deprecated as we should remove it as soon as possible.
- *
- * <p><b>This is NOT part of any API supported by Sun Microsystems.
- * If you write code that depends on this, you do so at your own
- * risk.  This code and its internal interfaces are subject to change
- * or deletion without notice.</b></p>
- *
- * @author Peter von der Ah\u00e9
- */
-@Deprecated
-public class Old199 {
-
-    private Old199() {}
-
-    public static String getPath(FileObject jfo) {
-        return JavacFileManager.getJavacFileName(jfo);
-    }
-
-    public static String getName(FileObject jfo) {
-        return JavacFileManager.getJavacBaseFileName(jfo);
-    }
-
-}
--- a/langtools/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java	Wed Sep 23 18:48:13 2009 -0700
@@ -68,98 +68,38 @@
         this.f = f;
     }
 
+    @Override
+    public URI toUri() {
+        return f.toURI().normalize();
+    }
+
+    @Override
+    public String getName() {
+        return f.getPath();
+    }
+
+    @Override
+    public String getShortName() {
+        return name;
+    }
+
+    @Override
+    public JavaFileObject.Kind getKind() {
+        return getKind(name);
+    }
+
+    @Override
     public InputStream openInputStream() throws IOException {
         return new FileInputStream(f);
     }
 
     @Override
-    protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
-        return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
-    }
-
     public OutputStream openOutputStream() throws IOException {
         ensureParentDirectoriesExist();
         return new FileOutputStream(f);
     }
 
-    public Writer openWriter() throws IOException {
-        ensureParentDirectoriesExist();
-        return new OutputStreamWriter(new FileOutputStream(f), fileManager.getEncodingName());
-    }
-
     @Override
-    protected String inferBinaryName(Iterable<? extends File> path) {
-        String fPath = f.getPath();
-        //System.err.println("RegularFileObject " + file + " " +r.getPath());
-        for (File dir: path) {
-            //System.err.println("dir: " + dir);
-            String dPath = dir.getPath();
-            if (dPath.length() == 0)
-                dPath = System.getProperty("user.dir");
-            if (!dPath.endsWith(File.separator))
-                dPath += File.separator;
-            if (fPath.regionMatches(true, 0, dPath, 0, dPath.length())
-                && new File(fPath.substring(0, dPath.length())).equals(new File(dPath))) {
-                String relativeName = fPath.substring(dPath.length());
-                return removeExtension(relativeName).replace(File.separatorChar, '.');
-            }
-        }
-        return null;
-    }
-
-    private void ensureParentDirectoriesExist() throws IOException {
-        if (!hasParents) {
-            File parent = f.getParentFile();
-            if (parent != null && !parent.exists()) {
-                if (!parent.mkdirs()) {
-                    if (!parent.exists() || !parent.isDirectory()) {
-                        throw new IOException("could not create parent directories");
-                    }
-                }
-            }
-            hasParents = true;
-        }
-    }
-
-    @Deprecated
-    public String getName() {
-        return name;
-    }
-
-    public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
-        cn.getClass();
-        // null check
-        if (kind == Kind.OTHER && getKind() != kind) {
-            return false;
-        }
-        String n = cn + kind.extension;
-        if (name.equals(n)) {
-            return true;
-        }
-        if (name.equalsIgnoreCase(n)) {
-            try {
-                // allow for Windows
-                return f.getCanonicalFile().getName().equals(n);
-            } catch (IOException e) {
-            }
-        }
-        return false;
-    }
-
-    @Deprecated
-    @Override
-    public String getPath() {
-        return f.getPath();
-    }
-
-    public long getLastModified() {
-        return f.lastModified();
-    }
-
-    public boolean delete() {
-        return f.delete();
-    }
-
     public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
         CharBuffer cb = fileManager.getCachedContent(this);
         if (cb == null) {
@@ -184,6 +124,82 @@
     }
 
     @Override
+    public Writer openWriter() throws IOException {
+        ensureParentDirectoriesExist();
+        return new OutputStreamWriter(new FileOutputStream(f), fileManager.getEncodingName());
+    }
+
+    @Override
+    public long getLastModified() {
+        return f.lastModified();
+    }
+
+    @Override
+    public boolean delete() {
+        return f.delete();
+    }
+
+    @Override
+    protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
+        return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
+    }
+
+    @Override
+    protected String inferBinaryName(Iterable<? extends File> path) {
+        String fPath = f.getPath();
+        //System.err.println("RegularFileObject " + file + " " +r.getPath());
+        for (File dir: path) {
+            //System.err.println("dir: " + dir);
+            String dPath = dir.getPath();
+            if (dPath.length() == 0)
+                dPath = System.getProperty("user.dir");
+            if (!dPath.endsWith(File.separator))
+                dPath += File.separator;
+            if (fPath.regionMatches(true, 0, dPath, 0, dPath.length())
+                && new File(fPath.substring(0, dPath.length())).equals(new File(dPath))) {
+                String relativeName = fPath.substring(dPath.length());
+                return removeExtension(relativeName).replace(File.separatorChar, '.');
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
+        cn.getClass();
+        // null check
+        if (kind == Kind.OTHER && getKind() != kind) {
+            return false;
+        }
+        String n = cn + kind.extension;
+        if (name.equals(n)) {
+            return true;
+        }
+        if (name.equalsIgnoreCase(n)) {
+            try {
+                // allow for Windows
+                return f.getCanonicalFile().getName().equals(n);
+            } catch (IOException e) {
+            }
+        }
+        return false;
+    }
+
+    private void ensureParentDirectoriesExist() throws IOException {
+        if (!hasParents) {
+            File parent = f.getParentFile();
+            if (parent != null && !parent.exists()) {
+                if (!parent.mkdirs()) {
+                    if (!parent.exists() || !parent.isDirectory()) {
+                        throw new IOException("could not create parent directories");
+                    }
+                }
+            }
+            hasParents = true;
+        }
+    }
+
+    @Override
     public boolean equals(Object other) {
         if (!(other instanceof RegularFileObject)) {
             return false;
@@ -200,8 +216,4 @@
     public int hashCode() {
         return f.hashCode();
     }
-
-    public URI toUri() {
-        return f.toURI().normalize();
-    }
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/file/SymbolArchive.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/SymbolArchive.java	Wed Sep 23 18:48:13 2009 -0700
@@ -95,7 +95,7 @@
 
         @Override
         protected String inferBinaryName(Iterable<? extends File> path) {
-            String entryName = getZipEntryName();
+            String entryName = entry.getName();
             String prefix = ((SymbolArchive) zarch).prefix.path;
             if (entryName.startsWith(prefix))
                 entryName = entryName.substring(prefix.length());
--- a/langtools/src/share/classes/com/sun/tools/javac/file/ZipArchive.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/ZipArchive.java	Wed Sep 23 18:48:13 2009 -0700
@@ -147,51 +147,37 @@
             this.entry = entry;
         }
 
+        public URI toUri() {
+            File zipFile = new File(zarch.zdir.getName());
+            return createJarUri(zipFile, entry.getName());
+        }
+
+        @Override
+        public String getName() {
+            return zarch.zdir.getName() + "(" + entry.getName() + ")";
+        }
+
+        @Override
+        public String getShortName() {
+            return new File(zarch.zdir.getName()).getName() + "(" + entry + ")";
+        }
+
+        @Override
+        public JavaFileObject.Kind getKind() {
+            return getKind(entry.getName());
+        }
+
+        @Override
         public InputStream openInputStream() throws IOException {
             return zarch.zdir.getInputStream(entry);
         }
 
+        @Override
         public OutputStream openOutputStream() throws IOException {
             throw new UnsupportedOperationException();
         }
 
         @Override
-        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
-            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
-        }
-
-        public Writer openWriter() throws IOException {
-            throw new UnsupportedOperationException();
-        }
-
-        @Deprecated
-        public String getName() {
-            return name;
-        }
-
-        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
-            cn.getClass();
-            // null check
-            if (k == Kind.OTHER && getKind() != k) {
-                return false;
-            }
-            return name.equals(cn + k.extension);
-        }
-
-        @Deprecated
-        @Override
-        public String getPath() {
-            return zarch.zdir.getName() + "(" + entry + ")";
-        }
-
-        public long getLastModified() {
-            return entry.getTime();
-        }
-
-        public boolean delete() {
-            throw new UnsupportedOperationException();
-        }
-
         public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
             CharBuffer cb = fileManager.getCachedContent(this);
             if (cb == null) {
@@ -216,6 +202,42 @@
         }
 
         @Override
+        public Writer openWriter() throws IOException {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public long getLastModified() {
+            return entry.getTime();
+        }
+
+        @Override
+        public boolean delete() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
+            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
+        }
+
+        @Override
+        protected String inferBinaryName(Iterable<? extends File> path) {
+            String entryName = entry.getName();
+            return removeExtension(entryName).replace('/', '.');
+        }
+
+        @Override
+        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
+            cn.getClass();
+            // null check
+            if (k == Kind.OTHER && getKind() != k) {
+                return false;
+            }
+            return name.equals(cn + k.extension);
+        }
+
+        @Override
         public boolean equals(Object other) {
             if (!(other instanceof ZipFileObject)) {
                 return false;
@@ -228,25 +250,6 @@
         public int hashCode() {
             return zarch.zdir.hashCode() + name.hashCode();
         }
-
-        public String getZipName() {
-            return zarch.zdir.getName();
-        }
-
-        public String getZipEntryName() {
-            return entry.getName();
-        }
-
-        public URI toUri() {
-            File zipFile = new File(getZipName());
-            return createJarUri(zipFile, entry.getName());
-        }
-
-        @Override
-        protected String inferBinaryName(Iterable<? extends File> path) {
-            String entryName = getZipEntryName();
-            return removeExtension(entryName).replace('/', '.');
-        }
     }
 
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java	Wed Sep 23 18:48:13 2009 -0700
@@ -123,88 +123,41 @@
             this.zipName = zipFileName;
         }
 
-        public InputStream openInputStream() throws IOException {
+        @Override
+        public URI toUri() {
+            return createJarUri(zipName, getPrefixedEntryName());
+        }
+
+        @Override
+        public String getName() {
+            return zipName + "(" + getPrefixedEntryName() + ")";
+        }
 
+        @Override
+        public String getShortName() {
+            return zipName.getName() + "(" + entry.getName() + ")";
+        }
+
+        @Override
+        public JavaFileObject.Kind getKind() {
+            return getKind(entry.getName());
+        }
+
+        @Override
+        public InputStream openInputStream() throws IOException {
             if (inputStream == null) {
-                inputStream = new ByteArrayInputStream(read());
+                assert entry != null; // see constructor
+                inputStream = new ByteArrayInputStream(zfIndex.read(entry));
             }
             return inputStream;
         }
 
         @Override
-        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
-            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
-        }
-
         public OutputStream openOutputStream() throws IOException {
             throw new UnsupportedOperationException();
         }
 
-        public Writer openWriter() throws IOException {
-            throw new UnsupportedOperationException();
-        }
-
-        /** @deprecated see bug 6410637 */
-        @Deprecated
-        public String getName() {
-            return name;
-        }
-
-        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
-            cn.getClass(); // null check
-            if (k == Kind.OTHER && getKind() != k)
-                return false;
-            return name.equals(cn + k.extension);
-        }
-
-        /** @deprecated see bug 6410637 */
-        @Deprecated
         @Override
-        public String getPath() {
-            return zipName + "(" + entry.getName() + ")";
-        }
-
-        public long getLastModified() {
-            return entry.getLastModified();
-        }
-
-        public boolean delete() {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public boolean equals(Object other) {
-            if (!(other instanceof ZipFileIndexFileObject))
-                return false;
-            ZipFileIndexFileObject o = (ZipFileIndexFileObject) other;
-            return entry.equals(o.entry);
-        }
-
-        @Override
-        public int hashCode() {
-            return zipName.hashCode() + (name.hashCode() << 10);
-        }
-
-        public String getZipName() {
-            return zipName.getPath();
-        }
-
-        public String getZipEntryName() {
-            return entry.getName();
-        }
-
-        public URI toUri() {
-            if (zfIndex.symbolFilePrefix != null)
-                return createJarUri(zipName, zfIndex.symbolFilePrefix.path + entry.getName());
-            else
-                return createJarUri(zipName, entry.getName());
-        }
-
-        private byte[] read() throws IOException {
-            assert entry != null; // see constructor
-            return zfIndex.read(entry);
-        }
-
         public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
             CharBuffer cb = fileManager.getCachedContent(this);
             if (cb == null) {
@@ -228,8 +181,28 @@
         }
 
         @Override
+        public Writer openWriter() throws IOException {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public long getLastModified() {
+            return entry.getLastModified();
+        }
+
+        @Override
+        public boolean delete() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
+            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
+        }
+
+        @Override
         protected String inferBinaryName(Iterable<? extends File> path) {
-            String entryName = getZipEntryName();
+            String entryName = entry.getName();
             if (zfIndex.symbolFilePrefix != null) {
                 String prefix = zfIndex.symbolFilePrefix.path;
                 if (entryName.startsWith(prefix))
@@ -237,6 +210,34 @@
             }
             return removeExtension(entryName).replace('/', '.');
         }
+
+        @Override
+        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
+            cn.getClass(); // null check
+            if (k == Kind.OTHER && getKind() != k)
+                return false;
+            return name.equals(cn + k.extension);
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            if (!(other instanceof ZipFileIndexFileObject))
+                return false;
+            ZipFileIndexFileObject o = (ZipFileIndexFileObject) other;
+            return entry.equals(o.entry);
+        }
+
+        @Override
+        public int hashCode() {
+            return zipName.hashCode() + (name.hashCode() << 10);
+        }
+
+        private String getPrefixedEntryName() {
+            if (zfIndex.symbolFilePrefix != null)
+                return zfIndex.symbolFilePrefix.path + entry.getName();
+            else
+                return entry.getName();
+        }
     }
 
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Wed Sep 23 18:48:13 2009 -0700
@@ -2563,38 +2563,73 @@
             this.flatname = flatname;
         }
 
+        @Override
+        public URI toUri() {
+            try {
+                return new URI(null, name.toString(), null);
+            } catch (URISyntaxException e) {
+                throw new CannotCreateUriError(name.toString(), e);
+            }
+        }
+
+        @Override
+        public String getName() {
+            return name.toString();
+        }
+
+        @Override
+        public String getShortName() {
+            return getName();
+        }
+
+        @Override
+        public JavaFileObject.Kind getKind() {
+            return getKind(getName());
+        }
+
+        @Override
         public InputStream openInputStream() {
             throw new UnsupportedOperationException();
         }
 
+        @Override
         public OutputStream openOutputStream() {
             throw new UnsupportedOperationException();
         }
 
-        public Reader openReader() {
+        @Override
+        public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
             throw new UnsupportedOperationException();
         }
 
+        @Override
+        public Reader openReader(boolean ignoreEncodingErrors) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
         public Writer openWriter() {
             throw new UnsupportedOperationException();
         }
 
-        /** @deprecated see bug 6410637 */
-        @Deprecated
-        public String getName() {
-            return name.toString();
-        }
-
+        @Override
         public long getLastModified() {
             throw new UnsupportedOperationException();
         }
 
+        @Override
         public boolean delete() {
             throw new UnsupportedOperationException();
         }
 
-        public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
-            throw new UnsupportedOperationException();
+        @Override
+        protected String inferBinaryName(Iterable<? extends File> path) {
+            return flatname.toString();
+        }
+
+        @Override
+        public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) {
+            return true; // fail-safe mode
         }
 
         @Override
@@ -2609,27 +2644,5 @@
         public int hashCode() {
             return name.hashCode();
         }
-
-        public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) {
-            return true; // fail-safe mode
-        }
-
-        public URI toUri() {
-            try {
-                return new URI(null, name.toString(), null);
-            } catch (URISyntaxException e) {
-                throw new CannotCreateUriError(name.toString(), e);
-            }
-        }
-
-        @Override
-        public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        protected String inferBinaryName(Iterable<? extends File> path) {
-            return flatname.toString();
-        }
     }
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Wed Sep 23 18:48:13 2009 -0700
@@ -36,6 +36,7 @@
 import com.sun.tools.javac.code.*;
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.code.Type.*;
+import com.sun.tools.javac.file.BaseFileObject;
 import com.sun.tools.javac.util.*;
 
 import static com.sun.tools.javac.code.BoundKind.*;
@@ -1685,13 +1686,8 @@
             // the last possible moment because the sourcefile may be used
             // elsewhere in error diagnostics. Fixes 4241573.
             //databuf.appendChar(c.pool.put(c.sourcefile));
-            String filename = c.sourcefile.toString();
-            int sepIdx = filename.lastIndexOf(File.separatorChar);
-            // Allow '/' as separator on all platforms, e.g., on Win32.
-            int slashIdx = filename.lastIndexOf('/');
-            if (slashIdx > sepIdx) sepIdx = slashIdx;
-            if (sepIdx >= 0) filename = filename.substring(sepIdx + 1);
-            databuf.appendChar(c.pool.put(names.fromString(filename)));
+            String simpleName = BaseFileObject.getSimpleName(c.sourcefile);
+            databuf.appendChar(c.pool.put(names.fromString(simpleName)));
             endAttr(alenIdx);
             acount++;
         }
--- a/langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java	Wed Sep 23 18:48:13 2009 -0700
@@ -42,8 +42,8 @@
 import com.sun.tools.javac.code.Symbol;
 import com.sun.tools.javac.code.Type;
 import com.sun.tools.javac.code.Type.CapturedType;
-import com.sun.tools.javac.file.JavacFileManager;
 
+import com.sun.tools.javac.file.BaseFileObject;
 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
 
 /**
@@ -133,8 +133,15 @@
     }
 
     public String formatSource(JCDiagnostic d, boolean fullname, Locale l) {
-        assert (d.getSource() != null);
-        return fullname ? d.getSourceName() : d.getSource().getName();
+        JavaFileObject fo = d.getSource();
+        if (fo == null)
+            throw new IllegalArgumentException(); // d should have source set
+        if (fullname)
+            return fo.getName();
+        else if (fo instanceof BaseFileObject)
+            return ((BaseFileObject) fo).getShortName();
+        else
+            return BaseFileObject.getSimpleName(fo);
     }
 
     /**
@@ -182,7 +189,7 @@
             return printer.visit((Symbol)arg, l);
         }
         else if (arg instanceof JavaFileObject) {
-            return JavacFileManager.getJavacBaseFileName((JavaFileObject)arg);
+            return ((JavaFileObject)arg).getName();
         }
         else if (arg instanceof Formattable) {
             return ((Formattable)arg).toString(l, messages);
--- a/langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java	Wed Sep 23 18:48:13 2009 -0700
@@ -69,10 +69,6 @@
         return fileObject;
     }
 
-    public CharSequence getName()  {
-        return JavacFileManager.getJavacBaseFileName(fileObject);
-    }
-
     /** Return the one-based line number associated with a given pos
      * for the current source file.  Zero is returned if no line exists
      * for the given position.
--- a/langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Wed Sep 23 18:48:13 2009 -0700
@@ -32,7 +32,6 @@
 import javax.tools.JavaFileObject;
 
 import com.sun.tools.javac.api.DiagnosticFormatter;
-import com.sun.tools.javac.file.JavacFileManager;
 import com.sun.tools.javac.tree.JCTree;
 
 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
@@ -354,15 +353,6 @@
     }
 
     /**
-     * Get the name of the source file referred to by this diagnostic.
-     * @return the name of the source referred to with this diagnostic, or null if none
-     */
-    public String getSourceName() {
-        JavaFileObject s = getSource();
-        return s == null ? null : JavacFileManager.getJavacFileName(s);
-    }
-
-    /**
      * Get the source referred to by this diagnostic.
      * @return the source referred to with this diagnostic, or null if none
      */
@@ -437,6 +427,7 @@
     /**
      * Return the standard presentation of this diagnostic.
      */
+    @Override
     public String toString() {
         return defaultFormatter.format(this,Locale.getDefault());
     }
--- a/langtools/src/share/classes/com/sun/tools/javac/util/Log.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/Log.java	Wed Sep 23 18:48:13 2009 -0700
@@ -33,7 +33,6 @@
 import javax.tools.DiagnosticListener;
 import javax.tools.JavaFileObject;
 
-import com.sun.tools.javac.file.JavacFileManager;
 import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.api.DiagnosticFormatter;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
@@ -428,7 +427,7 @@
             JavaFileObject file = source.getFile();
             if (file != null)
                 printLines(errWriter,
-                           JavacFileManager.getJavacFileName(file) + ":" +
+                           file.getName() + ":" +
                            line + ": " + msg);
             printErrLine(pos, errWriter);
         }
--- a/langtools/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java	Wed Sep 23 18:48:13 2009 -0700
@@ -30,6 +30,7 @@
 
 import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.*;
 import com.sun.tools.javac.api.Formattable;
+import com.sun.tools.javac.file.BaseFileObject;
 import com.sun.tools.javac.util.AbstractDiagnosticFormatter.SimpleConfiguration;
 
 import static com.sun.tools.javac.api.DiagnosticFormatter.PositionKind.*;
@@ -109,6 +110,8 @@
         String s;
         if (arg instanceof Formattable)
             s = arg.toString();
+        else if (arg instanceof BaseFileObject)
+            s = ((BaseFileObject) arg).getShortName();
         else
             s = super.formatArgument(diag, arg, null);
         if (arg instanceof JCDiagnostic)
--- a/langtools/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java	Wed Sep 23 18:48:13 2009 -0700
@@ -95,7 +95,7 @@
     public String toString() {
         // Backwards compatibility hack. ZipFileObjects use the format
         // zipfile(zipentry) but javadoc has been using zipfile/zipentry
-        String fn = filename.toString();
+        String fn = filename.getName();
         if (fn.endsWith(")")) {
             int paren = fn.lastIndexOf("(");
             if (paren != -1)
--- a/langtools/src/share/classes/javax/tools/SimpleJavaFileObject.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/src/share/classes/javax/tools/SimpleJavaFileObject.java	Wed Sep 23 18:48:13 2009 -0700
@@ -27,7 +27,6 @@
 
 import java.io.*;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.nio.CharBuffer;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.NestingKind;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/4241573/T4241573.java	Wed Sep 23 18:48:13 2009 -0700
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4241573
+ * @summary SourceFile attribute includes full path
+ */
+
+import com.sun.tools.classfile.Attribute;
+import com.sun.tools.classfile.ClassFile;
+import com.sun.tools.classfile.SourceFile_attribute;
+import java.io.*;
+import java.util.*;
+import java.util.jar.*;
+
+public class T4241573 {
+    public static void main(String... args) throws Exception {
+        new T4241573().run();
+    }
+
+    public void run() throws Exception {
+        // Selection of files to be compiled
+        File absJar = createJar(new File("abs.jar").getAbsoluteFile(), "j.A");
+        File relJar = createJar(new File("rel.jar"), "j.R");
+        File absDir = createDir(new File("abs.dir").getAbsoluteFile(), "d.A");
+        File relDir = createDir(new File("rel.dir"), "d.R");
+        File absTestFile = writeFile(new File("AbsTest.java").getAbsoluteFile(), "class AbsTest { class Inner { } }");
+        File relTestFile = writeFile(new File("RelTest.java"), "class RelTest { class Inner { } }");
+        File relTest2File = writeFile(new File("p/RelTest2.java"), "package p; class RelTest2 { class Inner { } }");
+        // This next class references other classes that will be found on the source path
+        // and which will therefore need to be compiled as well.
+        File mainFile = writeFile(new File("Main.java"),
+                "class Main { j.A ja; j.R jr; d.A da; d.R dr; }" +
+                "");
+
+        String sourcePath = createPath(absJar, relJar, absDir, relDir);
+        File outDir = new File("classes");
+        outDir.mkdirs();
+
+        String[] args = {
+            "-sourcepath", sourcePath,
+            "-d", outDir.getPath(),
+            absTestFile.getPath(),
+            relTestFile.getPath(),
+            relTest2File.getPath(),
+            mainFile.getPath(),
+        };
+        System.err.println("compile: " + Arrays.asList(args));
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        int rc = com.sun.tools.javac.Main.compile(args, pw);
+        pw.close();
+        if (rc != 0) {
+            System.err.println(sw.toString());
+            throw new Exception("unexpected exit from javac: " + rc);
+        }
+
+        Set<File> expect = getFiles(outDir,
+            "d/A.class",        "d/A$Inner.class",
+            "d/R.class",        "d/R$Inner.class",
+            "j/A.class",        "j/A$Inner.class",
+            "j/R.class",        "j/R$Inner.class",
+            "AbsTest.class",    "AbsTest$Inner.class",
+            "RelTest.class",    "RelTest$Inner.class",
+            "p/RelTest2.class", "p/RelTest2$Inner.class",
+            "Main.class" );
+
+        Set<File> found = findFiles(outDir);
+
+        if (!found.equals(expect)) {
+            if (found.containsAll(expect))
+                throw new Exception("unexpected files found: " + diff(found, expect));
+            else if (expect.containsAll(found))
+                throw new Exception("expected files not found: " + diff(expect, found));
+        }
+
+        for (File f: found)
+            verifySourceFileAttribute(f);
+
+        if (errors > 0)
+            throw new Exception(errors + " errors occurred");
+    }
+
+    /** Check the SourceFileAttribute is the simple name of the original source file. */
+    void verifySourceFileAttribute(File f) {
+        System.err.println("verify: " + f);
+        try {
+            ClassFile cf = ClassFile.read(f);
+            SourceFile_attribute sfa = (SourceFile_attribute) cf.getAttribute(Attribute.SourceFile);
+            String found = sfa.getSourceFile(cf.constant_pool);
+            String expect = f.getName().replaceAll("([$.].*)?\\.class", ".java");
+            if (!expect.equals(found)) {
+                error("bad value found: " + found + ", expected: " + expect);
+            }
+        } catch (Exception e) {
+            error("error reading " + f +": " + e);
+        }
+    }
+
+    /** Create a directory containing one or more files. */
+    File createDir(File dir, String... entries) throws Exception {
+        if (!dir.mkdirs())
+            throw new Exception("cannot create directories " + dir);
+        for (String e: entries) {
+            writeFile(new File(dir, getPathForEntry(e)), getBodyForEntry(e));
+        }
+        return dir;
+    }
+
+    /** Create a jar file containing one or more entries. */
+    File createJar(File jar, String... entries) throws IOException {
+        OutputStream out = new FileOutputStream(jar);
+        try {
+            JarOutputStream jos = new JarOutputStream(out);
+            for (String e: entries) {
+                jos.putNextEntry(new JarEntry(getPathForEntry(e)));
+                jos.write(getBodyForEntry(e).getBytes());
+            }
+            jos.close();
+        } finally {
+            out.close();
+        }
+        return jar;
+    }
+
+    /** Return the path for an entry given to createDir or createJar. */
+    String getPathForEntry(String e) {
+        return e.replace(".", File.separator) + ".java";
+    }
+
+    /** Return the body text for an entry given to createDir or createJar. */
+    String getBodyForEntry(String e) {
+        int sep = e.lastIndexOf(".");
+        String pkgName = e.substring(0, sep);
+        String className = e.substring(sep + 1);
+        return "package " + pkgName + "; public class " + className + "{ class Inner { } }";
+    }
+
+    /** Write a file containing the given string. Parent directories are
+     * created as needed. */
+    File writeFile(File f, String s) throws IOException {
+        if (f.getParentFile() != null)
+            f.getParentFile().mkdirs();
+        FileWriter out = new FileWriter(f);
+        try {
+            out.write(s);
+        } finally {
+            out.close();
+        }
+        return f;
+    }
+
+    /** Create a path value from a list of directories and jar files. */
+    String createPath(File... files) {
+        StringBuilder sb = new StringBuilder();
+        for (File f: files) {
+            if (sb.length() > 0)
+                sb.append(File.pathSeparatorChar);
+            sb.append(f.getPath());
+        }
+        return sb.toString();
+    }
+
+    /** Create a set of files from a base directory and a set of relative paths. */
+    Set<File> getFiles(File dir, String... paths) {
+        Set<File> files = new LinkedHashSet<File>();
+        for (String p: paths)
+            files.add(new File(dir, p));
+        return files;
+    }
+
+    /** Find all the files in a directory and its subdirectories. */
+    Set<File> findFiles(File dir) {
+        Set<File> files = new LinkedHashSet<File>();
+        findFiles(dir, files);
+        return files;
+    }
+    // where
+    void findFiles(File dir, Set<File> files) {
+        for (File f: dir.listFiles()) {
+            if (f.isDirectory())
+                findFiles(f, files);
+            else
+                files.add(f);
+        }
+    }
+
+    /** Return the difference of two sets, a - b. */
+    <T> Set<T> diff(Set<T> a, Set<T> b) {
+        if (b.isEmpty())
+            return a;
+        Set<T> result = new LinkedHashSet<T>(a);
+        result.removeAll(b);
+        return result;
+    }
+
+    /** Report an error. */
+    void error(String msg) {
+        System.err.println(msg);
+        errors++;
+    }
+
+    int errors;
+}
--- a/langtools/test/tools/javac/6589361/T6589361.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/test/tools/javac/6589361/T6589361.java	Wed Sep 23 18:48:13 2009 -0700
@@ -25,7 +25,7 @@
             for (JavaFileObject file : files) {
                 // Note: Zip/Jar entry names use '/', not File.separator, but just to be sure,
                 // we normalize the filename as well.
-                if (file.toString().replace(File.separatorChar, '/').contains("java/lang/Object.class")) {
+                if (file.getName().replace(File.separatorChar, '/').contains("java/lang/Object.class")) {
                     String str = fm.inferBinaryName(StandardLocation.CLASS_PATH, file);
                     if (!str.equals("java.lang.Object")) {
                         throw new AssertionError("Error in JavacFileManager.inferBinaryName method!");
--- a/langtools/test/tools/javac/Diagnostics/6769027/T6769027.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/test/tools/javac/Diagnostics/6769027/T6769027.java	Wed Sep 23 18:48:13 2009 -0700
@@ -261,7 +261,7 @@
 
     enum PositionKind {
         NOPOS(Position.NOPOS, "- ", "error: "),
-        POS(5, "/Test.java:1:6: ", "myfo:/Test.java:1: ");
+        POS(5, "Test.java:1:6: ", "/Test.java:1: ");
 
         int pos;
         String rawOutput;
--- a/langtools/test/tools/javac/T6705935.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/test/tools/javac/T6705935.java	Wed Sep 23 18:48:13 2009 -0700
@@ -48,7 +48,7 @@
                                         "java.lang",
                                         Collections.singleton(JavaFileObject.Kind.CLASS),
                                         false)) {
-            String p = ((BaseFileObject)fo).getPath();
+            String p = fo.getName();
             int bra = p.indexOf("(");
             int ket = p.indexOf(")");
             //System.err.println(bra + "," + ket + "," + p.length());
--- a/langtools/test/tools/javac/api/6411310/T6411310.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/test/tools/javac/api/6411310/T6411310.java	Wed Sep 23 18:48:13 2009 -0700
@@ -37,7 +37,7 @@
 import static javax.tools.StandardLocation.CLASS_PATH;
 import static javax.tools.JavaFileObject.Kind.CLASS;
 
-// Limited test while we wait for 6419926
+// Limited test while we wait for 6419926: 6419926 is now closed
 
 public class T6411310 extends ToolTester {
 
@@ -45,8 +45,11 @@
         JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
                                                      "java.lang.Object",
                                                      CLASS);
-        if (!file.getName().equals("Object.class"))
+        String fileName = file.getName();
+        if (!fileName.matches(".*java/lang/Object.class\\)?")) {
+            System.err.println(fileName);
             throw new AssertionError(file);
+        }
     }
 
     public static void main(String... args) throws IOException {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/api/6411310/Test.java	Wed Sep 23 18:48:13 2009 -0700
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6410367 6411310
+ * @summary FileObject should support user-friendly names via getName()
+ */
+
+import java.io.*;
+import java.util.*;
+import java.util.jar.*;
+import java.util.zip.*;
+import javax.tools.*;
+
+import com.sun.tools.javac.file.JavacFileManager;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.Options;
+
+// Test FileObject.getName returned from JavacFileManager and its support classes.
+
+public class Test {
+    public static void main(String... args) throws Exception {
+        new Test().run();
+    }
+
+    Set<String> foundClasses = new TreeSet<String>();
+    Set<String> foundJars = new TreeSet<String>();
+
+    void run() throws Exception {
+        File rt_jar = findRtJar();
+
+        // names for entries to be created in directories and jar files
+        String[] entries = { "p/A.java", "p/A.class", "p/resources/A-1.html" };
+
+        // test various combinations of directories and jar files, intended to
+        // cover all sources of file objects within JavacFileManager's support classes
+
+        test(createFileManager(), createDir("dir", entries), "p", entries);
+        test(createFileManager(), createDir("a b/dir", entries), "p", entries);
+
+        for (boolean useJavaUtilZip: new boolean[] { false, true }) {
+            test(createFileManager(useJavaUtilZip), createJar("jar", entries), "p", entries);
+            test(createFileManager(useJavaUtilZip), createJar("jar jar", entries), "p", entries);
+
+            for (boolean useSymbolFile: new boolean[] { false, true }) {
+                test(createFileManager(useJavaUtilZip, useSymbolFile), rt_jar, "java.lang.ref", null);
+            }
+        }
+
+        if (errors > 0)
+            throw new Exception(errors + " errors found");
+
+        // Verify that we hit all the impl classes we intended
+        checkCoverage("classes", foundClasses,
+                "RegularFileObject", "SymbolFileObject", "ZipFileIndexFileObject", "ZipFileObject");
+
+        // Verify that we hit the jar files we intended, specifically ct.sym as well as rt.jar
+        checkCoverage("jar files", foundJars,
+                "ct.sym", "jar", "jar jar", "rt.jar");
+    }
+
+    // use a new file manager for each test
+    void test(StandardJavaFileManager fm, File f, String pkg, String[] entries) throws Exception {
+        System.err.println("Test " + f);
+        try {
+            if (f.isDirectory()) {
+                for (File dir: new File[] { f, f.getAbsoluteFile() }) {
+                    for (String e: entries) {
+                        JavaFileObject fo = fm.getJavaFileObjects(new File(dir, e)).iterator().next();
+                        test(fo, dir, e);
+                    }
+                }
+            }
+
+            fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(f));
+            fm.setLocation(StandardLocation.SOURCE_PATH, Collections.singleton(f.getAbsoluteFile()));
+            for (StandardLocation l: EnumSet.of(StandardLocation.CLASS_PATH, StandardLocation.SOURCE_PATH)) {
+                for (JavaFileObject fo: fm.list(l, pkg, EnumSet.allOf(JavaFileObject.Kind.class), true)) {
+                    // we could use fm.getLocation but the following guarantees we preserve the original filename
+                    File dir = (l == StandardLocation.CLASS_PATH ? f : f.getAbsoluteFile());
+                    char sep = (dir.isDirectory() ? File.separatorChar : '/');
+                    String b = fm.inferBinaryName(l, fo);
+                    String e = fo.getKind().extension;
+                    test(fo, dir, b.replace('.', sep) + e);
+                }
+            }
+        } finally {
+            fm.close();
+        }
+    }
+
+    void test(JavaFileObject fo, File dir, String p) {
+        System.err.println("Test: " + fo);
+        String expect = dir.isDirectory() ? new File(dir, p).getPath() : (dir.getPath() + "(" + p + ")");
+        String found = fo.getName();
+        // if ct.sym is found, replace it with the equivalent rt.jar
+        String found2 = found.replaceAll("lib([\\\\/])ct.sym\\(META-INF/sym/rt.jar/", "jre$1lib$1rt.jar(");
+        if (!expect.equals(found2)) {
+            System.err.println("expected: " + expect);
+            System.err.println("   found: " + found);
+            if (!found.equals(found2))
+                System.err.println("  found2: " + found2);
+            error("Failed: " + fo);
+        }
+
+        // record the file object class name for coverage checks later
+        foundClasses.add(fo.getClass().getSimpleName());
+
+        if (found.contains("(")) {
+            // record access to the jar file for coverage checks later
+            foundJars.add(new File(found.substring(0, found.indexOf("("))).getName());
+        }
+    }
+
+    void checkCoverage(String label, Set<String> found, String... expect) throws Exception {
+        Set<String> e = new TreeSet<String>(Arrays.asList(expect));
+        if (!found.equals(e)) {
+            e.removeAll(found);
+            throw new Exception("expected " + label + " not used: " + e);
+        }
+    }
+
+    JavacFileManager createFileManager() {
+        return createFileManager(false, false);
+    }
+
+    JavacFileManager createFileManager(boolean useJavaUtilZip) {
+        return createFileManager(useJavaUtilZip, false);
+    }
+
+    JavacFileManager createFileManager(boolean useJavaUtilZip, boolean useSymbolFile) {
+        // javac should really not be using system properties like this
+        // -- it should really be using (hidden) options -- but until then
+        // take care to leave system properties as we find them, so as not
+        // to adversely affect other tests that might follow.
+        String prev = System.getProperty("useJavaUtilZip");
+        boolean resetProperties = false;
+        try {
+            if (useJavaUtilZip) {
+                System.setProperty("useJavaUtilZip", "true");
+                resetProperties = true;
+            } else if (System.getProperty("useJavaUtilZip") != null) {
+                System.getProperties().remove("useJavaUtilZip");
+                resetProperties = true;
+            }
+
+            Context c = new Context();
+            if (!useSymbolFile) {
+                Options options = Options.instance(c);
+                options.put("ignore.symbol.file", "true");
+            }
+
+            return new JavacFileManager(c, false, null);
+        } finally {
+            if (resetProperties) {
+                if (prev == null) {
+                    System.getProperties().remove("useJavaUtilZip");
+                } else {
+                    System.setProperty("useJavaUtilZip", prev);
+                }
+            }
+        }
+    }
+
+    File createDir(String name, String... entries) throws Exception {
+        File dir = new File(name);
+        if (!dir.mkdirs())
+            throw new Exception("cannot create directories " + dir);
+        for (String e: entries) {
+            writeFile(new File(dir, e), e);
+        }
+        return dir;
+    }
+
+    File createJar(String name, String... entries) throws IOException {
+        File jar = new File(name);
+        OutputStream out = new FileOutputStream(jar);
+        try {
+            JarOutputStream jos = new JarOutputStream(out);
+            for (String e: entries) {
+                jos.putNextEntry(new ZipEntry(e));
+                jos.write(e.getBytes());
+            }
+            jos.close();
+        } finally {
+            out.close();
+        }
+        return jar;
+    }
+
+    File findRtJar() throws Exception {
+        File java_home = new File(System.getProperty("java.home"));
+        if (java_home.getName().equals("jre"))
+            java_home = java_home.getParentFile();
+        File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar");
+        if (!rt_jar.exists())
+            throw new Exception("can't find rt.jar");
+        return rt_jar;
+    }
+
+    byte[] read(InputStream in) throws IOException {
+        byte[] data = new byte[1024];
+        int offset = 0;
+        try {
+            int n;
+            while ((n = in.read(data, offset, data.length - offset)) != -1) {
+                offset += n;
+                if (offset == data.length)
+                    data = Arrays.copyOf(data, 2 * data.length);
+            }
+        } finally {
+            in.close();
+        }
+        return Arrays.copyOf(data, offset);
+    }
+
+    void writeFile(File f, String s) throws IOException {
+        f.getParentFile().mkdirs();
+        FileWriter out = new FileWriter(f);
+        try {
+            out.write(s);
+        } finally {
+            out.close();
+        }
+    }
+
+    void error(String msg) {
+        System.err.println(msg);
+        errors++;
+    }
+
+    int errors;
+}
--- a/langtools/test/tools/javac/api/6733837/T6733837.java	Wed Sep 23 18:29:41 2009 -0700
+++ b/langtools/test/tools/javac/api/6733837/T6733837.java	Wed Sep 23 18:48:13 2009 -0700
@@ -46,14 +46,10 @@
     }
 
     public void exec() {
-        JavaFileObject sfo = new SimpleJavaFileObject(URI.create(""),Kind.SOURCE) {
+        JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"),Kind.SOURCE) {
             public CharSequence getCharContent(boolean ignoreEncodingErrors) {
                 return "\tclass ErroneousWithTab";
             }
-            @Override
-            public String getName() {
-                return "RELATIVEPATH";
-            }
         };
         StringWriter sw = new StringWriter();
         PrintWriter out = new PrintWriter(sw);
@@ -66,7 +62,7 @@
             throw new Error("Compiler threw an exception");
         }
         System.err.println(sw.toString());
-        if (sw.toString().contains("RELATIVEPATH"))
+        if (!sw.toString().contains("/Test.java"))
             throw new Error("Bad source name in diagnostic");
     }
 }