6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.

Wed, 23 Sep 2009 18:48:13 -0700

author
jjg
date
Wed, 23 Sep 2009 18:48:13 -0700
changeset 415
49359d0e6a9c
parent 414
e992e602788e
child 416
c287d51c57da

6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
6747645: ZipFileObject.getName is incorrectly deprecated
6885123: JavaFileObject getName issues
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/apt/mirror/util/SourcePositionImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/file/BaseFileObject.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/file/JavacFileManager.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/file/Old199.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/file/RegularFileObject.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/file/SymbolArchive.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/file/ZipArchive.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/Log.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java file | annotate | diff | comparison | revisions
src/share/classes/javax/tools/SimpleJavaFileObject.java file | annotate | diff | comparison | revisions
test/tools/javac/4241573/T4241573.java file | annotate | diff | comparison | revisions
test/tools/javac/6589361/T6589361.java file | annotate | diff | comparison | revisions
test/tools/javac/Diagnostics/6769027/T6769027.java file | annotate | diff | comparison | revisions
test/tools/javac/T6705935.java file | annotate | diff | comparison | revisions
test/tools/javac/api/6411310/T6411310.java file | annotate | diff | comparison | revisions
test/tools/javac/api/6411310/Test.java file | annotate | diff | comparison | revisions
test/tools/javac/api/6733837/T6733837.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/apt/mirror/util/SourcePositionImpl.java	Wed Sep 23 18:29:41 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/apt/mirror/util/SourcePositionImpl.java	Wed Sep 23 18:48:13 2009 -0700
     1.3 @@ -67,15 +67,15 @@
     1.4      public String toString() {
     1.5          int ln = line();
     1.6          return (ln == Position.NOPOS)
     1.7 -                ? sourcefile.toString()
     1.8 -                : sourcefile + ":" + ln;
     1.9 +                ? sourcefile.getName()
    1.10 +                : sourcefile.getName() + ":" + ln;
    1.11      }
    1.12  
    1.13      /**
    1.14       * {@inheritDoc}
    1.15       */
    1.16      public File file() {
    1.17 -        return new File(sourcefile.toString());
    1.18 +        return new File(sourcefile.toUri());
    1.19      }
    1.20  
    1.21      /**
     2.1 --- a/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java	Wed Sep 23 18:29:41 2009 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java	Wed Sep 23 18:48:13 2009 -0700
     2.3 @@ -34,6 +34,7 @@
     2.4  import java.nio.charset.CharsetDecoder;
     2.5  import javax.lang.model.element.Modifier;
     2.6  import javax.lang.model.element.NestingKind;
     2.7 +import javax.tools.FileObject;
     2.8  import javax.tools.JavaFileObject;
     2.9  
    2.10  import static javax.tools.JavaFileObject.Kind.*;
    2.11 @@ -49,33 +50,15 @@
    2.12          this.fileManager = fileManager;
    2.13      }
    2.14  
    2.15 -    public JavaFileObject.Kind getKind() {
    2.16 -        String n = getName();
    2.17 -        if (n.endsWith(CLASS.extension))
    2.18 -            return CLASS;
    2.19 -        else if (n.endsWith(SOURCE.extension))
    2.20 -            return SOURCE;
    2.21 -        else if (n.endsWith(HTML.extension))
    2.22 -            return HTML;
    2.23 -        else
    2.24 -            return OTHER;
    2.25 -    }
    2.26 +    /** Return a short name for the object, such as for use in raw diagnostics
    2.27 +     */
    2.28 +    public abstract String getShortName();
    2.29  
    2.30      @Override
    2.31      public String toString() {
    2.32 -        return getPath();
    2.33 +        return getClass().getSimpleName() + "[" + getName() + "]";
    2.34      }
    2.35  
    2.36 -    /** @deprecated see bug 6410637 */
    2.37 -    @Deprecated
    2.38 -    public String getPath() {
    2.39 -        return getName();
    2.40 -    }
    2.41 -
    2.42 -    /** @deprecated see bug 6410637 */
    2.43 -    @Deprecated
    2.44 -    abstract public String getName();
    2.45 -
    2.46      public NestingKind getNestingKind() { return null; }
    2.47  
    2.48      public Modifier getAccessLevel()  { return null; }
    2.49 @@ -90,6 +73,17 @@
    2.50  
    2.51      protected abstract String inferBinaryName(Iterable<? extends File> path);
    2.52  
    2.53 +    protected static JavaFileObject.Kind getKind(String filename) {
    2.54 +        if (filename.endsWith(CLASS.extension))
    2.55 +            return CLASS;
    2.56 +        else if (filename.endsWith(SOURCE.extension))
    2.57 +            return SOURCE;
    2.58 +        else if (filename.endsWith(HTML.extension))
    2.59 +            return HTML;
    2.60 +        else
    2.61 +            return OTHER;
    2.62 +    }
    2.63 +
    2.64      protected static String removeExtension(String fileName) {
    2.65          int lastDot = fileName.lastIndexOf(".");
    2.66          return (lastDot == -1 ? fileName : fileName.substring(0, lastDot));
    2.67 @@ -115,6 +109,17 @@
    2.68          }
    2.69      }
    2.70  
    2.71 +    /** Return the last component of a presumed hierarchical URI.
    2.72 +     *  From the scheme specific part of the URI, it returns the substring
    2.73 +     *  after the last "/" if any, or everything if no "/" is found.
    2.74 +     */
    2.75 +    public static String getSimpleName(FileObject fo) {
    2.76 +        URI uri = fo.toUri();
    2.77 +        String s = uri.getSchemeSpecificPart();
    2.78 +        return s.substring(s.lastIndexOf("/") + 1); // safe when / not found
    2.79 +
    2.80 +    }
    2.81 +
    2.82      /** The file manager that created this JavaFileObject. */
    2.83      protected final JavacFileManager fileManager;
    2.84  }
     3.1 --- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Wed Sep 23 18:29:41 2009 -0700
     3.2 +++ b/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Wed Sep 23 18:48:13 2009 -0700
     3.3 @@ -1116,36 +1116,6 @@
     3.4          throw new IllegalArgumentException("Invalid relative path: " + file);
     3.5      }
     3.6  
     3.7 -    @SuppressWarnings("deprecation") // bug 6410637
     3.8 -    public static String getJavacFileName(FileObject file) {
     3.9 -        if (file instanceof BaseFileObject)
    3.10 -            return ((BaseFileObject)file).getPath();
    3.11 -        URI uri = file.toUri();
    3.12 -        String scheme = uri.getScheme();
    3.13 -        if (scheme == null || scheme.equals("file") || scheme.equals("jar"))
    3.14 -            return uri.getPath();
    3.15 -        else
    3.16 -            return uri.toString();
    3.17 -    }
    3.18 -
    3.19 -    @SuppressWarnings("deprecation") // bug 6410637
    3.20 -    public static String getJavacBaseFileName(FileObject file) {
    3.21 -        if (file instanceof BaseFileObject)
    3.22 -            return ((BaseFileObject)file).getName();
    3.23 -        URI uri = file.toUri();
    3.24 -        String scheme = uri.getScheme();
    3.25 -        if (scheme == null || scheme.equals("file") || scheme.equals("jar")) {
    3.26 -            String path = uri.getPath();
    3.27 -            if (path == null)
    3.28 -                return null;
    3.29 -            if (scheme != null && scheme.equals("jar"))
    3.30 -                path = path.substring(path.lastIndexOf('!') + 1);
    3.31 -            return path.substring(path.lastIndexOf('/') + 1);
    3.32 -        } else {
    3.33 -            return uri.toString();
    3.34 -        }
    3.35 -    }
    3.36 -
    3.37      private static <T> T nullCheck(T o) {
    3.38          o.getClass(); // null check
    3.39          return o;
     4.1 --- a/src/share/classes/com/sun/tools/javac/file/Old199.java	Wed Sep 23 18:29:41 2009 -0700
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,54 +0,0 @@
     4.4 -/*
     4.5 - * Copyright 2006-2008 Sun Microsystems, Inc.  All Rights Reserved.
     4.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 - *
     4.8 - * This code is free software; you can redistribute it and/or modify it
     4.9 - * under the terms of the GNU General Public License version 2 only, as
    4.10 - * published by the Free Software Foundation.  Sun designates this
    4.11 - * particular file as subject to the "Classpath" exception as provided
    4.12 - * by Sun in the LICENSE file that accompanied this code.
    4.13 - *
    4.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    4.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.17 - * version 2 for more details (a copy is included in the LICENSE file that
    4.18 - * accompanied this code).
    4.19 - *
    4.20 - * You should have received a copy of the GNU General Public License version
    4.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    4.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.23 - *
    4.24 - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    4.25 - * CA 95054 USA or visit www.sun.com if you need additional information or
    4.26 - * have any questions.
    4.27 - */
    4.28 -
    4.29 -package com.sun.tools.javac.file;
    4.30 -
    4.31 -import javax.tools.FileObject;
    4.32 -
    4.33 -/**
    4.34 - * Provides an easy migration to JSR 199 v3.3.  The class is
    4.35 - * deprecated as we should remove it as soon as possible.
    4.36 - *
    4.37 - * <p><b>This is NOT part of any API supported by Sun Microsystems.
    4.38 - * If you write code that depends on this, you do so at your own
    4.39 - * risk.  This code and its internal interfaces are subject to change
    4.40 - * or deletion without notice.</b></p>
    4.41 - *
    4.42 - * @author Peter von der Ah\u00e9
    4.43 - */
    4.44 -@Deprecated
    4.45 -public class Old199 {
    4.46 -
    4.47 -    private Old199() {}
    4.48 -
    4.49 -    public static String getPath(FileObject jfo) {
    4.50 -        return JavacFileManager.getJavacFileName(jfo);
    4.51 -    }
    4.52 -
    4.53 -    public static String getName(FileObject jfo) {
    4.54 -        return JavacFileManager.getJavacBaseFileName(jfo);
    4.55 -    }
    4.56 -
    4.57 -}
     5.1 --- a/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java	Wed Sep 23 18:29:41 2009 -0700
     5.2 +++ b/src/share/classes/com/sun/tools/javac/file/RegularFileObject.java	Wed Sep 23 18:48:13 2009 -0700
     5.3 @@ -68,98 +68,38 @@
     5.4          this.f = f;
     5.5      }
     5.6  
     5.7 +    @Override
     5.8 +    public URI toUri() {
     5.9 +        return f.toURI().normalize();
    5.10 +    }
    5.11 +
    5.12 +    @Override
    5.13 +    public String getName() {
    5.14 +        return f.getPath();
    5.15 +    }
    5.16 +
    5.17 +    @Override
    5.18 +    public String getShortName() {
    5.19 +        return name;
    5.20 +    }
    5.21 +
    5.22 +    @Override
    5.23 +    public JavaFileObject.Kind getKind() {
    5.24 +        return getKind(name);
    5.25 +    }
    5.26 +
    5.27 +    @Override
    5.28      public InputStream openInputStream() throws IOException {
    5.29          return new FileInputStream(f);
    5.30      }
    5.31  
    5.32      @Override
    5.33 -    protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
    5.34 -        return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
    5.35 -    }
    5.36 -
    5.37      public OutputStream openOutputStream() throws IOException {
    5.38          ensureParentDirectoriesExist();
    5.39          return new FileOutputStream(f);
    5.40      }
    5.41  
    5.42 -    public Writer openWriter() throws IOException {
    5.43 -        ensureParentDirectoriesExist();
    5.44 -        return new OutputStreamWriter(new FileOutputStream(f), fileManager.getEncodingName());
    5.45 -    }
    5.46 -
    5.47      @Override
    5.48 -    protected String inferBinaryName(Iterable<? extends File> path) {
    5.49 -        String fPath = f.getPath();
    5.50 -        //System.err.println("RegularFileObject " + file + " " +r.getPath());
    5.51 -        for (File dir: path) {
    5.52 -            //System.err.println("dir: " + dir);
    5.53 -            String dPath = dir.getPath();
    5.54 -            if (dPath.length() == 0)
    5.55 -                dPath = System.getProperty("user.dir");
    5.56 -            if (!dPath.endsWith(File.separator))
    5.57 -                dPath += File.separator;
    5.58 -            if (fPath.regionMatches(true, 0, dPath, 0, dPath.length())
    5.59 -                && new File(fPath.substring(0, dPath.length())).equals(new File(dPath))) {
    5.60 -                String relativeName = fPath.substring(dPath.length());
    5.61 -                return removeExtension(relativeName).replace(File.separatorChar, '.');
    5.62 -            }
    5.63 -        }
    5.64 -        return null;
    5.65 -    }
    5.66 -
    5.67 -    private void ensureParentDirectoriesExist() throws IOException {
    5.68 -        if (!hasParents) {
    5.69 -            File parent = f.getParentFile();
    5.70 -            if (parent != null && !parent.exists()) {
    5.71 -                if (!parent.mkdirs()) {
    5.72 -                    if (!parent.exists() || !parent.isDirectory()) {
    5.73 -                        throw new IOException("could not create parent directories");
    5.74 -                    }
    5.75 -                }
    5.76 -            }
    5.77 -            hasParents = true;
    5.78 -        }
    5.79 -    }
    5.80 -
    5.81 -    @Deprecated
    5.82 -    public String getName() {
    5.83 -        return name;
    5.84 -    }
    5.85 -
    5.86 -    public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    5.87 -        cn.getClass();
    5.88 -        // null check
    5.89 -        if (kind == Kind.OTHER && getKind() != kind) {
    5.90 -            return false;
    5.91 -        }
    5.92 -        String n = cn + kind.extension;
    5.93 -        if (name.equals(n)) {
    5.94 -            return true;
    5.95 -        }
    5.96 -        if (name.equalsIgnoreCase(n)) {
    5.97 -            try {
    5.98 -                // allow for Windows
    5.99 -                return f.getCanonicalFile().getName().equals(n);
   5.100 -            } catch (IOException e) {
   5.101 -            }
   5.102 -        }
   5.103 -        return false;
   5.104 -    }
   5.105 -
   5.106 -    @Deprecated
   5.107 -    @Override
   5.108 -    public String getPath() {
   5.109 -        return f.getPath();
   5.110 -    }
   5.111 -
   5.112 -    public long getLastModified() {
   5.113 -        return f.lastModified();
   5.114 -    }
   5.115 -
   5.116 -    public boolean delete() {
   5.117 -        return f.delete();
   5.118 -    }
   5.119 -
   5.120      public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
   5.121          CharBuffer cb = fileManager.getCachedContent(this);
   5.122          if (cb == null) {
   5.123 @@ -184,6 +124,82 @@
   5.124      }
   5.125  
   5.126      @Override
   5.127 +    public Writer openWriter() throws IOException {
   5.128 +        ensureParentDirectoriesExist();
   5.129 +        return new OutputStreamWriter(new FileOutputStream(f), fileManager.getEncodingName());
   5.130 +    }
   5.131 +
   5.132 +    @Override
   5.133 +    public long getLastModified() {
   5.134 +        return f.lastModified();
   5.135 +    }
   5.136 +
   5.137 +    @Override
   5.138 +    public boolean delete() {
   5.139 +        return f.delete();
   5.140 +    }
   5.141 +
   5.142 +    @Override
   5.143 +    protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
   5.144 +        return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
   5.145 +    }
   5.146 +
   5.147 +    @Override
   5.148 +    protected String inferBinaryName(Iterable<? extends File> path) {
   5.149 +        String fPath = f.getPath();
   5.150 +        //System.err.println("RegularFileObject " + file + " " +r.getPath());
   5.151 +        for (File dir: path) {
   5.152 +            //System.err.println("dir: " + dir);
   5.153 +            String dPath = dir.getPath();
   5.154 +            if (dPath.length() == 0)
   5.155 +                dPath = System.getProperty("user.dir");
   5.156 +            if (!dPath.endsWith(File.separator))
   5.157 +                dPath += File.separator;
   5.158 +            if (fPath.regionMatches(true, 0, dPath, 0, dPath.length())
   5.159 +                && new File(fPath.substring(0, dPath.length())).equals(new File(dPath))) {
   5.160 +                String relativeName = fPath.substring(dPath.length());
   5.161 +                return removeExtension(relativeName).replace(File.separatorChar, '.');
   5.162 +            }
   5.163 +        }
   5.164 +        return null;
   5.165 +    }
   5.166 +
   5.167 +    @Override
   5.168 +    public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
   5.169 +        cn.getClass();
   5.170 +        // null check
   5.171 +        if (kind == Kind.OTHER && getKind() != kind) {
   5.172 +            return false;
   5.173 +        }
   5.174 +        String n = cn + kind.extension;
   5.175 +        if (name.equals(n)) {
   5.176 +            return true;
   5.177 +        }
   5.178 +        if (name.equalsIgnoreCase(n)) {
   5.179 +            try {
   5.180 +                // allow for Windows
   5.181 +                return f.getCanonicalFile().getName().equals(n);
   5.182 +            } catch (IOException e) {
   5.183 +            }
   5.184 +        }
   5.185 +        return false;
   5.186 +    }
   5.187 +
   5.188 +    private void ensureParentDirectoriesExist() throws IOException {
   5.189 +        if (!hasParents) {
   5.190 +            File parent = f.getParentFile();
   5.191 +            if (parent != null && !parent.exists()) {
   5.192 +                if (!parent.mkdirs()) {
   5.193 +                    if (!parent.exists() || !parent.isDirectory()) {
   5.194 +                        throw new IOException("could not create parent directories");
   5.195 +                    }
   5.196 +                }
   5.197 +            }
   5.198 +            hasParents = true;
   5.199 +        }
   5.200 +    }
   5.201 +
   5.202 +    @Override
   5.203      public boolean equals(Object other) {
   5.204          if (!(other instanceof RegularFileObject)) {
   5.205              return false;
   5.206 @@ -200,8 +216,4 @@
   5.207      public int hashCode() {
   5.208          return f.hashCode();
   5.209      }
   5.210 -
   5.211 -    public URI toUri() {
   5.212 -        return f.toURI().normalize();
   5.213 -    }
   5.214  }
     6.1 --- a/src/share/classes/com/sun/tools/javac/file/SymbolArchive.java	Wed Sep 23 18:29:41 2009 -0700
     6.2 +++ b/src/share/classes/com/sun/tools/javac/file/SymbolArchive.java	Wed Sep 23 18:48:13 2009 -0700
     6.3 @@ -95,7 +95,7 @@
     6.4  
     6.5          @Override
     6.6          protected String inferBinaryName(Iterable<? extends File> path) {
     6.7 -            String entryName = getZipEntryName();
     6.8 +            String entryName = entry.getName();
     6.9              String prefix = ((SymbolArchive) zarch).prefix.path;
    6.10              if (entryName.startsWith(prefix))
    6.11                  entryName = entryName.substring(prefix.length());
     7.1 --- a/src/share/classes/com/sun/tools/javac/file/ZipArchive.java	Wed Sep 23 18:29:41 2009 -0700
     7.2 +++ b/src/share/classes/com/sun/tools/javac/file/ZipArchive.java	Wed Sep 23 18:48:13 2009 -0700
     7.3 @@ -147,51 +147,37 @@
     7.4              this.entry = entry;
     7.5          }
     7.6  
     7.7 +        public URI toUri() {
     7.8 +            File zipFile = new File(zarch.zdir.getName());
     7.9 +            return createJarUri(zipFile, entry.getName());
    7.10 +        }
    7.11 +
    7.12 +        @Override
    7.13 +        public String getName() {
    7.14 +            return zarch.zdir.getName() + "(" + entry.getName() + ")";
    7.15 +        }
    7.16 +
    7.17 +        @Override
    7.18 +        public String getShortName() {
    7.19 +            return new File(zarch.zdir.getName()).getName() + "(" + entry + ")";
    7.20 +        }
    7.21 +
    7.22 +        @Override
    7.23 +        public JavaFileObject.Kind getKind() {
    7.24 +            return getKind(entry.getName());
    7.25 +        }
    7.26 +
    7.27 +        @Override
    7.28          public InputStream openInputStream() throws IOException {
    7.29              return zarch.zdir.getInputStream(entry);
    7.30          }
    7.31  
    7.32 +        @Override
    7.33          public OutputStream openOutputStream() throws IOException {
    7.34              throw new UnsupportedOperationException();
    7.35          }
    7.36  
    7.37          @Override
    7.38 -        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
    7.39 -            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
    7.40 -        }
    7.41 -
    7.42 -        public Writer openWriter() throws IOException {
    7.43 -            throw new UnsupportedOperationException();
    7.44 -        }
    7.45 -
    7.46 -        @Deprecated
    7.47 -        public String getName() {
    7.48 -            return name;
    7.49 -        }
    7.50 -
    7.51 -        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
    7.52 -            cn.getClass();
    7.53 -            // null check
    7.54 -            if (k == Kind.OTHER && getKind() != k) {
    7.55 -                return false;
    7.56 -            }
    7.57 -            return name.equals(cn + k.extension);
    7.58 -        }
    7.59 -
    7.60 -        @Deprecated
    7.61 -        @Override
    7.62 -        public String getPath() {
    7.63 -            return zarch.zdir.getName() + "(" + entry + ")";
    7.64 -        }
    7.65 -
    7.66 -        public long getLastModified() {
    7.67 -            return entry.getTime();
    7.68 -        }
    7.69 -
    7.70 -        public boolean delete() {
    7.71 -            throw new UnsupportedOperationException();
    7.72 -        }
    7.73 -
    7.74          public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
    7.75              CharBuffer cb = fileManager.getCachedContent(this);
    7.76              if (cb == null) {
    7.77 @@ -216,6 +202,42 @@
    7.78          }
    7.79  
    7.80          @Override
    7.81 +        public Writer openWriter() throws IOException {
    7.82 +            throw new UnsupportedOperationException();
    7.83 +        }
    7.84 +
    7.85 +        @Override
    7.86 +        public long getLastModified() {
    7.87 +            return entry.getTime();
    7.88 +        }
    7.89 +
    7.90 +        @Override
    7.91 +        public boolean delete() {
    7.92 +            throw new UnsupportedOperationException();
    7.93 +        }
    7.94 +
    7.95 +        @Override
    7.96 +        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
    7.97 +            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
    7.98 +        }
    7.99 +
   7.100 +        @Override
   7.101 +        protected String inferBinaryName(Iterable<? extends File> path) {
   7.102 +            String entryName = entry.getName();
   7.103 +            return removeExtension(entryName).replace('/', '.');
   7.104 +        }
   7.105 +
   7.106 +        @Override
   7.107 +        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
   7.108 +            cn.getClass();
   7.109 +            // null check
   7.110 +            if (k == Kind.OTHER && getKind() != k) {
   7.111 +                return false;
   7.112 +            }
   7.113 +            return name.equals(cn + k.extension);
   7.114 +        }
   7.115 +
   7.116 +        @Override
   7.117          public boolean equals(Object other) {
   7.118              if (!(other instanceof ZipFileObject)) {
   7.119                  return false;
   7.120 @@ -228,25 +250,6 @@
   7.121          public int hashCode() {
   7.122              return zarch.zdir.hashCode() + name.hashCode();
   7.123          }
   7.124 -
   7.125 -        public String getZipName() {
   7.126 -            return zarch.zdir.getName();
   7.127 -        }
   7.128 -
   7.129 -        public String getZipEntryName() {
   7.130 -            return entry.getName();
   7.131 -        }
   7.132 -
   7.133 -        public URI toUri() {
   7.134 -            File zipFile = new File(getZipName());
   7.135 -            return createJarUri(zipFile, entry.getName());
   7.136 -        }
   7.137 -
   7.138 -        @Override
   7.139 -        protected String inferBinaryName(Iterable<? extends File> path) {
   7.140 -            String entryName = getZipEntryName();
   7.141 -            return removeExtension(entryName).replace('/', '.');
   7.142 -        }
   7.143      }
   7.144  
   7.145  }
     8.1 --- a/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java	Wed Sep 23 18:29:41 2009 -0700
     8.2 +++ b/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java	Wed Sep 23 18:48:13 2009 -0700
     8.3 @@ -123,88 +123,41 @@
     8.4              this.zipName = zipFileName;
     8.5          }
     8.6  
     8.7 +        @Override
     8.8 +        public URI toUri() {
     8.9 +            return createJarUri(zipName, getPrefixedEntryName());
    8.10 +        }
    8.11 +
    8.12 +        @Override
    8.13 +        public String getName() {
    8.14 +            return zipName + "(" + getPrefixedEntryName() + ")";
    8.15 +        }
    8.16 +
    8.17 +        @Override
    8.18 +        public String getShortName() {
    8.19 +            return zipName.getName() + "(" + entry.getName() + ")";
    8.20 +        }
    8.21 +
    8.22 +        @Override
    8.23 +        public JavaFileObject.Kind getKind() {
    8.24 +            return getKind(entry.getName());
    8.25 +        }
    8.26 +
    8.27 +        @Override
    8.28          public InputStream openInputStream() throws IOException {
    8.29 -
    8.30              if (inputStream == null) {
    8.31 -                inputStream = new ByteArrayInputStream(read());
    8.32 +                assert entry != null; // see constructor
    8.33 +                inputStream = new ByteArrayInputStream(zfIndex.read(entry));
    8.34              }
    8.35              return inputStream;
    8.36          }
    8.37  
    8.38          @Override
    8.39 -        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
    8.40 -            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
    8.41 -        }
    8.42 -
    8.43          public OutputStream openOutputStream() throws IOException {
    8.44              throw new UnsupportedOperationException();
    8.45          }
    8.46  
    8.47 -        public Writer openWriter() throws IOException {
    8.48 -            throw new UnsupportedOperationException();
    8.49 -        }
    8.50 -
    8.51 -        /** @deprecated see bug 6410637 */
    8.52 -        @Deprecated
    8.53 -        public String getName() {
    8.54 -            return name;
    8.55 -        }
    8.56 -
    8.57 -        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
    8.58 -            cn.getClass(); // null check
    8.59 -            if (k == Kind.OTHER && getKind() != k)
    8.60 -                return false;
    8.61 -            return name.equals(cn + k.extension);
    8.62 -        }
    8.63 -
    8.64 -        /** @deprecated see bug 6410637 */
    8.65 -        @Deprecated
    8.66          @Override
    8.67 -        public String getPath() {
    8.68 -            return zipName + "(" + entry.getName() + ")";
    8.69 -        }
    8.70 -
    8.71 -        public long getLastModified() {
    8.72 -            return entry.getLastModified();
    8.73 -        }
    8.74 -
    8.75 -        public boolean delete() {
    8.76 -            throw new UnsupportedOperationException();
    8.77 -        }
    8.78 -
    8.79 -        @Override
    8.80 -        public boolean equals(Object other) {
    8.81 -            if (!(other instanceof ZipFileIndexFileObject))
    8.82 -                return false;
    8.83 -            ZipFileIndexFileObject o = (ZipFileIndexFileObject) other;
    8.84 -            return entry.equals(o.entry);
    8.85 -        }
    8.86 -
    8.87 -        @Override
    8.88 -        public int hashCode() {
    8.89 -            return zipName.hashCode() + (name.hashCode() << 10);
    8.90 -        }
    8.91 -
    8.92 -        public String getZipName() {
    8.93 -            return zipName.getPath();
    8.94 -        }
    8.95 -
    8.96 -        public String getZipEntryName() {
    8.97 -            return entry.getName();
    8.98 -        }
    8.99 -
   8.100 -        public URI toUri() {
   8.101 -            if (zfIndex.symbolFilePrefix != null)
   8.102 -                return createJarUri(zipName, zfIndex.symbolFilePrefix.path + entry.getName());
   8.103 -            else
   8.104 -                return createJarUri(zipName, entry.getName());
   8.105 -        }
   8.106 -
   8.107 -        private byte[] read() throws IOException {
   8.108 -            assert entry != null; // see constructor
   8.109 -            return zfIndex.read(entry);
   8.110 -        }
   8.111 -
   8.112          public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
   8.113              CharBuffer cb = fileManager.getCachedContent(this);
   8.114              if (cb == null) {
   8.115 @@ -228,8 +181,28 @@
   8.116          }
   8.117  
   8.118          @Override
   8.119 +        public Writer openWriter() throws IOException {
   8.120 +            throw new UnsupportedOperationException();
   8.121 +        }
   8.122 +
   8.123 +        @Override
   8.124 +        public long getLastModified() {
   8.125 +            return entry.getLastModified();
   8.126 +        }
   8.127 +
   8.128 +        @Override
   8.129 +        public boolean delete() {
   8.130 +            throw new UnsupportedOperationException();
   8.131 +        }
   8.132 +
   8.133 +        @Override
   8.134 +        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
   8.135 +            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
   8.136 +        }
   8.137 +
   8.138 +        @Override
   8.139          protected String inferBinaryName(Iterable<? extends File> path) {
   8.140 -            String entryName = getZipEntryName();
   8.141 +            String entryName = entry.getName();
   8.142              if (zfIndex.symbolFilePrefix != null) {
   8.143                  String prefix = zfIndex.symbolFilePrefix.path;
   8.144                  if (entryName.startsWith(prefix))
   8.145 @@ -237,6 +210,34 @@
   8.146              }
   8.147              return removeExtension(entryName).replace('/', '.');
   8.148          }
   8.149 +
   8.150 +        @Override
   8.151 +        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
   8.152 +            cn.getClass(); // null check
   8.153 +            if (k == Kind.OTHER && getKind() != k)
   8.154 +                return false;
   8.155 +            return name.equals(cn + k.extension);
   8.156 +        }
   8.157 +
   8.158 +        @Override
   8.159 +        public boolean equals(Object other) {
   8.160 +            if (!(other instanceof ZipFileIndexFileObject))
   8.161 +                return false;
   8.162 +            ZipFileIndexFileObject o = (ZipFileIndexFileObject) other;
   8.163 +            return entry.equals(o.entry);
   8.164 +        }
   8.165 +
   8.166 +        @Override
   8.167 +        public int hashCode() {
   8.168 +            return zipName.hashCode() + (name.hashCode() << 10);
   8.169 +        }
   8.170 +
   8.171 +        private String getPrefixedEntryName() {
   8.172 +            if (zfIndex.symbolFilePrefix != null)
   8.173 +                return zfIndex.symbolFilePrefix.path + entry.getName();
   8.174 +            else
   8.175 +                return entry.getName();
   8.176 +        }
   8.177      }
   8.178  
   8.179  }
     9.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Wed Sep 23 18:29:41 2009 -0700
     9.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Wed Sep 23 18:48:13 2009 -0700
     9.3 @@ -2563,38 +2563,73 @@
     9.4              this.flatname = flatname;
     9.5          }
     9.6  
     9.7 +        @Override
     9.8 +        public URI toUri() {
     9.9 +            try {
    9.10 +                return new URI(null, name.toString(), null);
    9.11 +            } catch (URISyntaxException e) {
    9.12 +                throw new CannotCreateUriError(name.toString(), e);
    9.13 +            }
    9.14 +        }
    9.15 +
    9.16 +        @Override
    9.17 +        public String getName() {
    9.18 +            return name.toString();
    9.19 +        }
    9.20 +
    9.21 +        @Override
    9.22 +        public String getShortName() {
    9.23 +            return getName();
    9.24 +        }
    9.25 +
    9.26 +        @Override
    9.27 +        public JavaFileObject.Kind getKind() {
    9.28 +            return getKind(getName());
    9.29 +        }
    9.30 +
    9.31 +        @Override
    9.32          public InputStream openInputStream() {
    9.33              throw new UnsupportedOperationException();
    9.34          }
    9.35  
    9.36 +        @Override
    9.37          public OutputStream openOutputStream() {
    9.38              throw new UnsupportedOperationException();
    9.39          }
    9.40  
    9.41 -        public Reader openReader() {
    9.42 +        @Override
    9.43 +        public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
    9.44              throw new UnsupportedOperationException();
    9.45          }
    9.46  
    9.47 +        @Override
    9.48 +        public Reader openReader(boolean ignoreEncodingErrors) {
    9.49 +            throw new UnsupportedOperationException();
    9.50 +        }
    9.51 +
    9.52 +        @Override
    9.53          public Writer openWriter() {
    9.54              throw new UnsupportedOperationException();
    9.55          }
    9.56  
    9.57 -        /** @deprecated see bug 6410637 */
    9.58 -        @Deprecated
    9.59 -        public String getName() {
    9.60 -            return name.toString();
    9.61 -        }
    9.62 -
    9.63 +        @Override
    9.64          public long getLastModified() {
    9.65              throw new UnsupportedOperationException();
    9.66          }
    9.67  
    9.68 +        @Override
    9.69          public boolean delete() {
    9.70              throw new UnsupportedOperationException();
    9.71          }
    9.72  
    9.73 -        public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
    9.74 -            throw new UnsupportedOperationException();
    9.75 +        @Override
    9.76 +        protected String inferBinaryName(Iterable<? extends File> path) {
    9.77 +            return flatname.toString();
    9.78 +        }
    9.79 +
    9.80 +        @Override
    9.81 +        public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) {
    9.82 +            return true; // fail-safe mode
    9.83          }
    9.84  
    9.85          @Override
    9.86 @@ -2609,27 +2644,5 @@
    9.87          public int hashCode() {
    9.88              return name.hashCode();
    9.89          }
    9.90 -
    9.91 -        public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) {
    9.92 -            return true; // fail-safe mode
    9.93 -        }
    9.94 -
    9.95 -        public URI toUri() {
    9.96 -            try {
    9.97 -                return new URI(null, name.toString(), null);
    9.98 -            } catch (URISyntaxException e) {
    9.99 -                throw new CannotCreateUriError(name.toString(), e);
   9.100 -            }
   9.101 -        }
   9.102 -
   9.103 -        @Override
   9.104 -        public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
   9.105 -            throw new UnsupportedOperationException();
   9.106 -        }
   9.107 -
   9.108 -        @Override
   9.109 -        protected String inferBinaryName(Iterable<? extends File> path) {
   9.110 -            return flatname.toString();
   9.111 -        }
   9.112      }
   9.113  }
    10.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Wed Sep 23 18:29:41 2009 -0700
    10.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Wed Sep 23 18:48:13 2009 -0700
    10.3 @@ -36,6 +36,7 @@
    10.4  import com.sun.tools.javac.code.*;
    10.5  import com.sun.tools.javac.code.Symbol.*;
    10.6  import com.sun.tools.javac.code.Type.*;
    10.7 +import com.sun.tools.javac.file.BaseFileObject;
    10.8  import com.sun.tools.javac.util.*;
    10.9  
   10.10  import static com.sun.tools.javac.code.BoundKind.*;
   10.11 @@ -1685,13 +1686,8 @@
   10.12              // the last possible moment because the sourcefile may be used
   10.13              // elsewhere in error diagnostics. Fixes 4241573.
   10.14              //databuf.appendChar(c.pool.put(c.sourcefile));
   10.15 -            String filename = c.sourcefile.toString();
   10.16 -            int sepIdx = filename.lastIndexOf(File.separatorChar);
   10.17 -            // Allow '/' as separator on all platforms, e.g., on Win32.
   10.18 -            int slashIdx = filename.lastIndexOf('/');
   10.19 -            if (slashIdx > sepIdx) sepIdx = slashIdx;
   10.20 -            if (sepIdx >= 0) filename = filename.substring(sepIdx + 1);
   10.21 -            databuf.appendChar(c.pool.put(names.fromString(filename)));
   10.22 +            String simpleName = BaseFileObject.getSimpleName(c.sourcefile);
   10.23 +            databuf.appendChar(c.pool.put(names.fromString(simpleName)));
   10.24              endAttr(alenIdx);
   10.25              acount++;
   10.26          }
    11.1 --- a/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java	Wed Sep 23 18:29:41 2009 -0700
    11.2 +++ b/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java	Wed Sep 23 18:48:13 2009 -0700
    11.3 @@ -42,8 +42,8 @@
    11.4  import com.sun.tools.javac.code.Symbol;
    11.5  import com.sun.tools.javac.code.Type;
    11.6  import com.sun.tools.javac.code.Type.CapturedType;
    11.7 -import com.sun.tools.javac.file.JavacFileManager;
    11.8  
    11.9 +import com.sun.tools.javac.file.BaseFileObject;
   11.10  import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
   11.11  
   11.12  /**
   11.13 @@ -133,8 +133,15 @@
   11.14      }
   11.15  
   11.16      public String formatSource(JCDiagnostic d, boolean fullname, Locale l) {
   11.17 -        assert (d.getSource() != null);
   11.18 -        return fullname ? d.getSourceName() : d.getSource().getName();
   11.19 +        JavaFileObject fo = d.getSource();
   11.20 +        if (fo == null)
   11.21 +            throw new IllegalArgumentException(); // d should have source set
   11.22 +        if (fullname)
   11.23 +            return fo.getName();
   11.24 +        else if (fo instanceof BaseFileObject)
   11.25 +            return ((BaseFileObject) fo).getShortName();
   11.26 +        else
   11.27 +            return BaseFileObject.getSimpleName(fo);
   11.28      }
   11.29  
   11.30      /**
   11.31 @@ -182,7 +189,7 @@
   11.32              return printer.visit((Symbol)arg, l);
   11.33          }
   11.34          else if (arg instanceof JavaFileObject) {
   11.35 -            return JavacFileManager.getJavacBaseFileName((JavaFileObject)arg);
   11.36 +            return ((JavaFileObject)arg).getName();
   11.37          }
   11.38          else if (arg instanceof Formattable) {
   11.39              return ((Formattable)arg).toString(l, messages);
    12.1 --- a/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java	Wed Sep 23 18:29:41 2009 -0700
    12.2 +++ b/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java	Wed Sep 23 18:48:13 2009 -0700
    12.3 @@ -69,10 +69,6 @@
    12.4          return fileObject;
    12.5      }
    12.6  
    12.7 -    public CharSequence getName()  {
    12.8 -        return JavacFileManager.getJavacBaseFileName(fileObject);
    12.9 -    }
   12.10 -
   12.11      /** Return the one-based line number associated with a given pos
   12.12       * for the current source file.  Zero is returned if no line exists
   12.13       * for the given position.
    13.1 --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Wed Sep 23 18:29:41 2009 -0700
    13.2 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Wed Sep 23 18:48:13 2009 -0700
    13.3 @@ -32,7 +32,6 @@
    13.4  import javax.tools.JavaFileObject;
    13.5  
    13.6  import com.sun.tools.javac.api.DiagnosticFormatter;
    13.7 -import com.sun.tools.javac.file.JavacFileManager;
    13.8  import com.sun.tools.javac.tree.JCTree;
    13.9  
   13.10  import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
   13.11 @@ -354,15 +353,6 @@
   13.12      }
   13.13  
   13.14      /**
   13.15 -     * Get the name of the source file referred to by this diagnostic.
   13.16 -     * @return the name of the source referred to with this diagnostic, or null if none
   13.17 -     */
   13.18 -    public String getSourceName() {
   13.19 -        JavaFileObject s = getSource();
   13.20 -        return s == null ? null : JavacFileManager.getJavacFileName(s);
   13.21 -    }
   13.22 -
   13.23 -    /**
   13.24       * Get the source referred to by this diagnostic.
   13.25       * @return the source referred to with this diagnostic, or null if none
   13.26       */
   13.27 @@ -437,6 +427,7 @@
   13.28      /**
   13.29       * Return the standard presentation of this diagnostic.
   13.30       */
   13.31 +    @Override
   13.32      public String toString() {
   13.33          return defaultFormatter.format(this,Locale.getDefault());
   13.34      }
    14.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java	Wed Sep 23 18:29:41 2009 -0700
    14.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java	Wed Sep 23 18:48:13 2009 -0700
    14.3 @@ -33,7 +33,6 @@
    14.4  import javax.tools.DiagnosticListener;
    14.5  import javax.tools.JavaFileObject;
    14.6  
    14.7 -import com.sun.tools.javac.file.JavacFileManager;
    14.8  import com.sun.tools.javac.tree.JCTree;
    14.9  import com.sun.tools.javac.api.DiagnosticFormatter;
   14.10  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
   14.11 @@ -428,7 +427,7 @@
   14.12              JavaFileObject file = source.getFile();
   14.13              if (file != null)
   14.14                  printLines(errWriter,
   14.15 -                           JavacFileManager.getJavacFileName(file) + ":" +
   14.16 +                           file.getName() + ":" +
   14.17                             line + ": " + msg);
   14.18              printErrLine(pos, errWriter);
   14.19          }
    15.1 --- a/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java	Wed Sep 23 18:29:41 2009 -0700
    15.2 +++ b/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java	Wed Sep 23 18:48:13 2009 -0700
    15.3 @@ -30,6 +30,7 @@
    15.4  
    15.5  import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.*;
    15.6  import com.sun.tools.javac.api.Formattable;
    15.7 +import com.sun.tools.javac.file.BaseFileObject;
    15.8  import com.sun.tools.javac.util.AbstractDiagnosticFormatter.SimpleConfiguration;
    15.9  
   15.10  import static com.sun.tools.javac.api.DiagnosticFormatter.PositionKind.*;
   15.11 @@ -109,6 +110,8 @@
   15.12          String s;
   15.13          if (arg instanceof Formattable)
   15.14              s = arg.toString();
   15.15 +        else if (arg instanceof BaseFileObject)
   15.16 +            s = ((BaseFileObject) arg).getShortName();
   15.17          else
   15.18              s = super.formatArgument(diag, arg, null);
   15.19          if (arg instanceof JCDiagnostic)
    16.1 --- a/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java	Wed Sep 23 18:29:41 2009 -0700
    16.2 +++ b/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java	Wed Sep 23 18:48:13 2009 -0700
    16.3 @@ -95,7 +95,7 @@
    16.4      public String toString() {
    16.5          // Backwards compatibility hack. ZipFileObjects use the format
    16.6          // zipfile(zipentry) but javadoc has been using zipfile/zipentry
    16.7 -        String fn = filename.toString();
    16.8 +        String fn = filename.getName();
    16.9          if (fn.endsWith(")")) {
   16.10              int paren = fn.lastIndexOf("(");
   16.11              if (paren != -1)
    17.1 --- a/src/share/classes/javax/tools/SimpleJavaFileObject.java	Wed Sep 23 18:29:41 2009 -0700
    17.2 +++ b/src/share/classes/javax/tools/SimpleJavaFileObject.java	Wed Sep 23 18:48:13 2009 -0700
    17.3 @@ -27,7 +27,6 @@
    17.4  
    17.5  import java.io.*;
    17.6  import java.net.URI;
    17.7 -import java.net.URISyntaxException;
    17.8  import java.nio.CharBuffer;
    17.9  import javax.lang.model.element.Modifier;
   17.10  import javax.lang.model.element.NestingKind;
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/test/tools/javac/4241573/T4241573.java	Wed Sep 23 18:48:13 2009 -0700
    18.3 @@ -0,0 +1,225 @@
    18.4 +/*
    18.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.7 + *
    18.8 + * This code is free software; you can redistribute it and/or modify it
    18.9 + * under the terms of the GNU General Public License version 2 only, as
   18.10 + * published by the Free Software Foundation.
   18.11 + *
   18.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   18.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   18.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   18.15 + * version 2 for more details (a copy is included in the LICENSE file that
   18.16 + * accompanied this code).
   18.17 + *
   18.18 + * You should have received a copy of the GNU General Public License version
   18.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   18.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18.21 + *
   18.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   18.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   18.24 + * have any questions.
   18.25 + */
   18.26 +
   18.27 +/*
   18.28 + * @test
   18.29 + * @bug 4241573
   18.30 + * @summary SourceFile attribute includes full path
   18.31 + */
   18.32 +
   18.33 +import com.sun.tools.classfile.Attribute;
   18.34 +import com.sun.tools.classfile.ClassFile;
   18.35 +import com.sun.tools.classfile.SourceFile_attribute;
   18.36 +import java.io.*;
   18.37 +import java.util.*;
   18.38 +import java.util.jar.*;
   18.39 +
   18.40 +public class T4241573 {
   18.41 +    public static void main(String... args) throws Exception {
   18.42 +        new T4241573().run();
   18.43 +    }
   18.44 +
   18.45 +    public void run() throws Exception {
   18.46 +        // Selection of files to be compiled
   18.47 +        File absJar = createJar(new File("abs.jar").getAbsoluteFile(), "j.A");
   18.48 +        File relJar = createJar(new File("rel.jar"), "j.R");
   18.49 +        File absDir = createDir(new File("abs.dir").getAbsoluteFile(), "d.A");
   18.50 +        File relDir = createDir(new File("rel.dir"), "d.R");
   18.51 +        File absTestFile = writeFile(new File("AbsTest.java").getAbsoluteFile(), "class AbsTest { class Inner { } }");
   18.52 +        File relTestFile = writeFile(new File("RelTest.java"), "class RelTest { class Inner { } }");
   18.53 +        File relTest2File = writeFile(new File("p/RelTest2.java"), "package p; class RelTest2 { class Inner { } }");
   18.54 +        // This next class references other classes that will be found on the source path
   18.55 +        // and which will therefore need to be compiled as well.
   18.56 +        File mainFile = writeFile(new File("Main.java"),
   18.57 +                "class Main { j.A ja; j.R jr; d.A da; d.R dr; }" +
   18.58 +                "");
   18.59 +
   18.60 +        String sourcePath = createPath(absJar, relJar, absDir, relDir);
   18.61 +        File outDir = new File("classes");
   18.62 +        outDir.mkdirs();
   18.63 +
   18.64 +        String[] args = {
   18.65 +            "-sourcepath", sourcePath,
   18.66 +            "-d", outDir.getPath(),
   18.67 +            absTestFile.getPath(),
   18.68 +            relTestFile.getPath(),
   18.69 +            relTest2File.getPath(),
   18.70 +            mainFile.getPath(),
   18.71 +        };
   18.72 +        System.err.println("compile: " + Arrays.asList(args));
   18.73 +        StringWriter sw = new StringWriter();
   18.74 +        PrintWriter pw = new PrintWriter(sw);
   18.75 +        int rc = com.sun.tools.javac.Main.compile(args, pw);
   18.76 +        pw.close();
   18.77 +        if (rc != 0) {
   18.78 +            System.err.println(sw.toString());
   18.79 +            throw new Exception("unexpected exit from javac: " + rc);
   18.80 +        }
   18.81 +
   18.82 +        Set<File> expect = getFiles(outDir,
   18.83 +            "d/A.class",        "d/A$Inner.class",
   18.84 +            "d/R.class",        "d/R$Inner.class",
   18.85 +            "j/A.class",        "j/A$Inner.class",
   18.86 +            "j/R.class",        "j/R$Inner.class",
   18.87 +            "AbsTest.class",    "AbsTest$Inner.class",
   18.88 +            "RelTest.class",    "RelTest$Inner.class",
   18.89 +            "p/RelTest2.class", "p/RelTest2$Inner.class",
   18.90 +            "Main.class" );
   18.91 +
   18.92 +        Set<File> found = findFiles(outDir);
   18.93 +
   18.94 +        if (!found.equals(expect)) {
   18.95 +            if (found.containsAll(expect))
   18.96 +                throw new Exception("unexpected files found: " + diff(found, expect));
   18.97 +            else if (expect.containsAll(found))
   18.98 +                throw new Exception("expected files not found: " + diff(expect, found));
   18.99 +        }
  18.100 +
  18.101 +        for (File f: found)
  18.102 +            verifySourceFileAttribute(f);
  18.103 +
  18.104 +        if (errors > 0)
  18.105 +            throw new Exception(errors + " errors occurred");
  18.106 +    }
  18.107 +
  18.108 +    /** Check the SourceFileAttribute is the simple name of the original source file. */
  18.109 +    void verifySourceFileAttribute(File f) {
  18.110 +        System.err.println("verify: " + f);
  18.111 +        try {
  18.112 +            ClassFile cf = ClassFile.read(f);
  18.113 +            SourceFile_attribute sfa = (SourceFile_attribute) cf.getAttribute(Attribute.SourceFile);
  18.114 +            String found = sfa.getSourceFile(cf.constant_pool);
  18.115 +            String expect = f.getName().replaceAll("([$.].*)?\\.class", ".java");
  18.116 +            if (!expect.equals(found)) {
  18.117 +                error("bad value found: " + found + ", expected: " + expect);
  18.118 +            }
  18.119 +        } catch (Exception e) {
  18.120 +            error("error reading " + f +": " + e);
  18.121 +        }
  18.122 +    }
  18.123 +
  18.124 +    /** Create a directory containing one or more files. */
  18.125 +    File createDir(File dir, String... entries) throws Exception {
  18.126 +        if (!dir.mkdirs())
  18.127 +            throw new Exception("cannot create directories " + dir);
  18.128 +        for (String e: entries) {
  18.129 +            writeFile(new File(dir, getPathForEntry(e)), getBodyForEntry(e));
  18.130 +        }
  18.131 +        return dir;
  18.132 +    }
  18.133 +
  18.134 +    /** Create a jar file containing one or more entries. */
  18.135 +    File createJar(File jar, String... entries) throws IOException {
  18.136 +        OutputStream out = new FileOutputStream(jar);
  18.137 +        try {
  18.138 +            JarOutputStream jos = new JarOutputStream(out);
  18.139 +            for (String e: entries) {
  18.140 +                jos.putNextEntry(new JarEntry(getPathForEntry(e)));
  18.141 +                jos.write(getBodyForEntry(e).getBytes());
  18.142 +            }
  18.143 +            jos.close();
  18.144 +        } finally {
  18.145 +            out.close();
  18.146 +        }
  18.147 +        return jar;
  18.148 +    }
  18.149 +
  18.150 +    /** Return the path for an entry given to createDir or createJar. */
  18.151 +    String getPathForEntry(String e) {
  18.152 +        return e.replace(".", File.separator) + ".java";
  18.153 +    }
  18.154 +
  18.155 +    /** Return the body text for an entry given to createDir or createJar. */
  18.156 +    String getBodyForEntry(String e) {
  18.157 +        int sep = e.lastIndexOf(".");
  18.158 +        String pkgName = e.substring(0, sep);
  18.159 +        String className = e.substring(sep + 1);
  18.160 +        return "package " + pkgName + "; public class " + className + "{ class Inner { } }";
  18.161 +    }
  18.162 +
  18.163 +    /** Write a file containing the given string. Parent directories are
  18.164 +     * created as needed. */
  18.165 +    File writeFile(File f, String s) throws IOException {
  18.166 +        if (f.getParentFile() != null)
  18.167 +            f.getParentFile().mkdirs();
  18.168 +        FileWriter out = new FileWriter(f);
  18.169 +        try {
  18.170 +            out.write(s);
  18.171 +        } finally {
  18.172 +            out.close();
  18.173 +        }
  18.174 +        return f;
  18.175 +    }
  18.176 +
  18.177 +    /** Create a path value from a list of directories and jar files. */
  18.178 +    String createPath(File... files) {
  18.179 +        StringBuilder sb = new StringBuilder();
  18.180 +        for (File f: files) {
  18.181 +            if (sb.length() > 0)
  18.182 +                sb.append(File.pathSeparatorChar);
  18.183 +            sb.append(f.getPath());
  18.184 +        }
  18.185 +        return sb.toString();
  18.186 +    }
  18.187 +
  18.188 +    /** Create a set of files from a base directory and a set of relative paths. */
  18.189 +    Set<File> getFiles(File dir, String... paths) {
  18.190 +        Set<File> files = new LinkedHashSet<File>();
  18.191 +        for (String p: paths)
  18.192 +            files.add(new File(dir, p));
  18.193 +        return files;
  18.194 +    }
  18.195 +
  18.196 +    /** Find all the files in a directory and its subdirectories. */
  18.197 +    Set<File> findFiles(File dir) {
  18.198 +        Set<File> files = new LinkedHashSet<File>();
  18.199 +        findFiles(dir, files);
  18.200 +        return files;
  18.201 +    }
  18.202 +    // where
  18.203 +    void findFiles(File dir, Set<File> files) {
  18.204 +        for (File f: dir.listFiles()) {
  18.205 +            if (f.isDirectory())
  18.206 +                findFiles(f, files);
  18.207 +            else
  18.208 +                files.add(f);
  18.209 +        }
  18.210 +    }
  18.211 +
  18.212 +    /** Return the difference of two sets, a - b. */
  18.213 +    <T> Set<T> diff(Set<T> a, Set<T> b) {
  18.214 +        if (b.isEmpty())
  18.215 +            return a;
  18.216 +        Set<T> result = new LinkedHashSet<T>(a);
  18.217 +        result.removeAll(b);
  18.218 +        return result;
  18.219 +    }
  18.220 +
  18.221 +    /** Report an error. */
  18.222 +    void error(String msg) {
  18.223 +        System.err.println(msg);
  18.224 +        errors++;
  18.225 +    }
  18.226 +
  18.227 +    int errors;
  18.228 +}
    19.1 --- a/test/tools/javac/6589361/T6589361.java	Wed Sep 23 18:29:41 2009 -0700
    19.2 +++ b/test/tools/javac/6589361/T6589361.java	Wed Sep 23 18:48:13 2009 -0700
    19.3 @@ -25,7 +25,7 @@
    19.4              for (JavaFileObject file : files) {
    19.5                  // Note: Zip/Jar entry names use '/', not File.separator, but just to be sure,
    19.6                  // we normalize the filename as well.
    19.7 -                if (file.toString().replace(File.separatorChar, '/').contains("java/lang/Object.class")) {
    19.8 +                if (file.getName().replace(File.separatorChar, '/').contains("java/lang/Object.class")) {
    19.9                      String str = fm.inferBinaryName(StandardLocation.CLASS_PATH, file);
   19.10                      if (!str.equals("java.lang.Object")) {
   19.11                          throw new AssertionError("Error in JavacFileManager.inferBinaryName method!");
    20.1 --- a/test/tools/javac/Diagnostics/6769027/T6769027.java	Wed Sep 23 18:29:41 2009 -0700
    20.2 +++ b/test/tools/javac/Diagnostics/6769027/T6769027.java	Wed Sep 23 18:48:13 2009 -0700
    20.3 @@ -261,7 +261,7 @@
    20.4  
    20.5      enum PositionKind {
    20.6          NOPOS(Position.NOPOS, "- ", "error: "),
    20.7 -        POS(5, "/Test.java:1:6: ", "myfo:/Test.java:1: ");
    20.8 +        POS(5, "Test.java:1:6: ", "/Test.java:1: ");
    20.9  
   20.10          int pos;
   20.11          String rawOutput;
    21.1 --- a/test/tools/javac/T6705935.java	Wed Sep 23 18:29:41 2009 -0700
    21.2 +++ b/test/tools/javac/T6705935.java	Wed Sep 23 18:48:13 2009 -0700
    21.3 @@ -48,7 +48,7 @@
    21.4                                          "java.lang",
    21.5                                          Collections.singleton(JavaFileObject.Kind.CLASS),
    21.6                                          false)) {
    21.7 -            String p = ((BaseFileObject)fo).getPath();
    21.8 +            String p = fo.getName();
    21.9              int bra = p.indexOf("(");
   21.10              int ket = p.indexOf(")");
   21.11              //System.err.println(bra + "," + ket + "," + p.length());
    22.1 --- a/test/tools/javac/api/6411310/T6411310.java	Wed Sep 23 18:29:41 2009 -0700
    22.2 +++ b/test/tools/javac/api/6411310/T6411310.java	Wed Sep 23 18:48:13 2009 -0700
    22.3 @@ -37,7 +37,7 @@
    22.4  import static javax.tools.StandardLocation.CLASS_PATH;
    22.5  import static javax.tools.JavaFileObject.Kind.CLASS;
    22.6  
    22.7 -// Limited test while we wait for 6419926
    22.8 +// Limited test while we wait for 6419926: 6419926 is now closed
    22.9  
   22.10  public class T6411310 extends ToolTester {
   22.11  
   22.12 @@ -45,8 +45,11 @@
   22.13          JavaFileObject file = fm.getJavaFileForInput(PLATFORM_CLASS_PATH,
   22.14                                                       "java.lang.Object",
   22.15                                                       CLASS);
   22.16 -        if (!file.getName().equals("Object.class"))
   22.17 +        String fileName = file.getName();
   22.18 +        if (!fileName.matches(".*java/lang/Object.class\\)?")) {
   22.19 +            System.err.println(fileName);
   22.20              throw new AssertionError(file);
   22.21 +        }
   22.22      }
   22.23  
   22.24      public static void main(String... args) throws IOException {
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/test/tools/javac/api/6411310/Test.java	Wed Sep 23 18:48:13 2009 -0700
    23.3 @@ -0,0 +1,254 @@
    23.4 +/*
    23.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    23.7 + *
    23.8 + * This code is free software; you can redistribute it and/or modify it
    23.9 + * under the terms of the GNU General Public License version 2 only, as
   23.10 + * published by the Free Software Foundation.
   23.11 + *
   23.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   23.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   23.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   23.15 + * version 2 for more details (a copy is included in the LICENSE file that
   23.16 + * accompanied this code).
   23.17 + *
   23.18 + * You should have received a copy of the GNU General Public License version
   23.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   23.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   23.21 + *
   23.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   23.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   23.24 + * have any questions.
   23.25 + */
   23.26 +
   23.27 +/*
   23.28 + * @test
   23.29 + * @bug 6410367 6411310
   23.30 + * @summary FileObject should support user-friendly names via getName()
   23.31 + */
   23.32 +
   23.33 +import java.io.*;
   23.34 +import java.util.*;
   23.35 +import java.util.jar.*;
   23.36 +import java.util.zip.*;
   23.37 +import javax.tools.*;
   23.38 +
   23.39 +import com.sun.tools.javac.file.JavacFileManager;
   23.40 +import com.sun.tools.javac.util.Context;
   23.41 +import com.sun.tools.javac.util.Options;
   23.42 +
   23.43 +// Test FileObject.getName returned from JavacFileManager and its support classes.
   23.44 +
   23.45 +public class Test {
   23.46 +    public static void main(String... args) throws Exception {
   23.47 +        new Test().run();
   23.48 +    }
   23.49 +
   23.50 +    Set<String> foundClasses = new TreeSet<String>();
   23.51 +    Set<String> foundJars = new TreeSet<String>();
   23.52 +
   23.53 +    void run() throws Exception {
   23.54 +        File rt_jar = findRtJar();
   23.55 +
   23.56 +        // names for entries to be created in directories and jar files
   23.57 +        String[] entries = { "p/A.java", "p/A.class", "p/resources/A-1.html" };
   23.58 +
   23.59 +        // test various combinations of directories and jar files, intended to
   23.60 +        // cover all sources of file objects within JavacFileManager's support classes
   23.61 +
   23.62 +        test(createFileManager(), createDir("dir", entries), "p", entries);
   23.63 +        test(createFileManager(), createDir("a b/dir", entries), "p", entries);
   23.64 +
   23.65 +        for (boolean useJavaUtilZip: new boolean[] { false, true }) {
   23.66 +            test(createFileManager(useJavaUtilZip), createJar("jar", entries), "p", entries);
   23.67 +            test(createFileManager(useJavaUtilZip), createJar("jar jar", entries), "p", entries);
   23.68 +
   23.69 +            for (boolean useSymbolFile: new boolean[] { false, true }) {
   23.70 +                test(createFileManager(useJavaUtilZip, useSymbolFile), rt_jar, "java.lang.ref", null);
   23.71 +            }
   23.72 +        }
   23.73 +
   23.74 +        if (errors > 0)
   23.75 +            throw new Exception(errors + " errors found");
   23.76 +
   23.77 +        // Verify that we hit all the impl classes we intended
   23.78 +        checkCoverage("classes", foundClasses,
   23.79 +                "RegularFileObject", "SymbolFileObject", "ZipFileIndexFileObject", "ZipFileObject");
   23.80 +
   23.81 +        // Verify that we hit the jar files we intended, specifically ct.sym as well as rt.jar
   23.82 +        checkCoverage("jar files", foundJars,
   23.83 +                "ct.sym", "jar", "jar jar", "rt.jar");
   23.84 +    }
   23.85 +
   23.86 +    // use a new file manager for each test
   23.87 +    void test(StandardJavaFileManager fm, File f, String pkg, String[] entries) throws Exception {
   23.88 +        System.err.println("Test " + f);
   23.89 +        try {
   23.90 +            if (f.isDirectory()) {
   23.91 +                for (File dir: new File[] { f, f.getAbsoluteFile() }) {
   23.92 +                    for (String e: entries) {
   23.93 +                        JavaFileObject fo = fm.getJavaFileObjects(new File(dir, e)).iterator().next();
   23.94 +                        test(fo, dir, e);
   23.95 +                    }
   23.96 +                }
   23.97 +            }
   23.98 +
   23.99 +            fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(f));
  23.100 +            fm.setLocation(StandardLocation.SOURCE_PATH, Collections.singleton(f.getAbsoluteFile()));
  23.101 +            for (StandardLocation l: EnumSet.of(StandardLocation.CLASS_PATH, StandardLocation.SOURCE_PATH)) {
  23.102 +                for (JavaFileObject fo: fm.list(l, pkg, EnumSet.allOf(JavaFileObject.Kind.class), true)) {
  23.103 +                    // we could use fm.getLocation but the following guarantees we preserve the original filename
  23.104 +                    File dir = (l == StandardLocation.CLASS_PATH ? f : f.getAbsoluteFile());
  23.105 +                    char sep = (dir.isDirectory() ? File.separatorChar : '/');
  23.106 +                    String b = fm.inferBinaryName(l, fo);
  23.107 +                    String e = fo.getKind().extension;
  23.108 +                    test(fo, dir, b.replace('.', sep) + e);
  23.109 +                }
  23.110 +            }
  23.111 +        } finally {
  23.112 +            fm.close();
  23.113 +        }
  23.114 +    }
  23.115 +
  23.116 +    void test(JavaFileObject fo, File dir, String p) {
  23.117 +        System.err.println("Test: " + fo);
  23.118 +        String expect = dir.isDirectory() ? new File(dir, p).getPath() : (dir.getPath() + "(" + p + ")");
  23.119 +        String found = fo.getName();
  23.120 +        // if ct.sym is found, replace it with the equivalent rt.jar
  23.121 +        String found2 = found.replaceAll("lib([\\\\/])ct.sym\\(META-INF/sym/rt.jar/", "jre$1lib$1rt.jar(");
  23.122 +        if (!expect.equals(found2)) {
  23.123 +            System.err.println("expected: " + expect);
  23.124 +            System.err.println("   found: " + found);
  23.125 +            if (!found.equals(found2))
  23.126 +                System.err.println("  found2: " + found2);
  23.127 +            error("Failed: " + fo);
  23.128 +        }
  23.129 +
  23.130 +        // record the file object class name for coverage checks later
  23.131 +        foundClasses.add(fo.getClass().getSimpleName());
  23.132 +
  23.133 +        if (found.contains("(")) {
  23.134 +            // record access to the jar file for coverage checks later
  23.135 +            foundJars.add(new File(found.substring(0, found.indexOf("("))).getName());
  23.136 +        }
  23.137 +    }
  23.138 +
  23.139 +    void checkCoverage(String label, Set<String> found, String... expect) throws Exception {
  23.140 +        Set<String> e = new TreeSet<String>(Arrays.asList(expect));
  23.141 +        if (!found.equals(e)) {
  23.142 +            e.removeAll(found);
  23.143 +            throw new Exception("expected " + label + " not used: " + e);
  23.144 +        }
  23.145 +    }
  23.146 +
  23.147 +    JavacFileManager createFileManager() {
  23.148 +        return createFileManager(false, false);
  23.149 +    }
  23.150 +
  23.151 +    JavacFileManager createFileManager(boolean useJavaUtilZip) {
  23.152 +        return createFileManager(useJavaUtilZip, false);
  23.153 +    }
  23.154 +
  23.155 +    JavacFileManager createFileManager(boolean useJavaUtilZip, boolean useSymbolFile) {
  23.156 +        // javac should really not be using system properties like this
  23.157 +        // -- it should really be using (hidden) options -- but until then
  23.158 +        // take care to leave system properties as we find them, so as not
  23.159 +        // to adversely affect other tests that might follow.
  23.160 +        String prev = System.getProperty("useJavaUtilZip");
  23.161 +        boolean resetProperties = false;
  23.162 +        try {
  23.163 +            if (useJavaUtilZip) {
  23.164 +                System.setProperty("useJavaUtilZip", "true");
  23.165 +                resetProperties = true;
  23.166 +            } else if (System.getProperty("useJavaUtilZip") != null) {
  23.167 +                System.getProperties().remove("useJavaUtilZip");
  23.168 +                resetProperties = true;
  23.169 +            }
  23.170 +
  23.171 +            Context c = new Context();
  23.172 +            if (!useSymbolFile) {
  23.173 +                Options options = Options.instance(c);
  23.174 +                options.put("ignore.symbol.file", "true");
  23.175 +            }
  23.176 +
  23.177 +            return new JavacFileManager(c, false, null);
  23.178 +        } finally {
  23.179 +            if (resetProperties) {
  23.180 +                if (prev == null) {
  23.181 +                    System.getProperties().remove("useJavaUtilZip");
  23.182 +                } else {
  23.183 +                    System.setProperty("useJavaUtilZip", prev);
  23.184 +                }
  23.185 +            }
  23.186 +        }
  23.187 +    }
  23.188 +
  23.189 +    File createDir(String name, String... entries) throws Exception {
  23.190 +        File dir = new File(name);
  23.191 +        if (!dir.mkdirs())
  23.192 +            throw new Exception("cannot create directories " + dir);
  23.193 +        for (String e: entries) {
  23.194 +            writeFile(new File(dir, e), e);
  23.195 +        }
  23.196 +        return dir;
  23.197 +    }
  23.198 +
  23.199 +    File createJar(String name, String... entries) throws IOException {
  23.200 +        File jar = new File(name);
  23.201 +        OutputStream out = new FileOutputStream(jar);
  23.202 +        try {
  23.203 +            JarOutputStream jos = new JarOutputStream(out);
  23.204 +            for (String e: entries) {
  23.205 +                jos.putNextEntry(new ZipEntry(e));
  23.206 +                jos.write(e.getBytes());
  23.207 +            }
  23.208 +            jos.close();
  23.209 +        } finally {
  23.210 +            out.close();
  23.211 +        }
  23.212 +        return jar;
  23.213 +    }
  23.214 +
  23.215 +    File findRtJar() throws Exception {
  23.216 +        File java_home = new File(System.getProperty("java.home"));
  23.217 +        if (java_home.getName().equals("jre"))
  23.218 +            java_home = java_home.getParentFile();
  23.219 +        File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar");
  23.220 +        if (!rt_jar.exists())
  23.221 +            throw new Exception("can't find rt.jar");
  23.222 +        return rt_jar;
  23.223 +    }
  23.224 +
  23.225 +    byte[] read(InputStream in) throws IOException {
  23.226 +        byte[] data = new byte[1024];
  23.227 +        int offset = 0;
  23.228 +        try {
  23.229 +            int n;
  23.230 +            while ((n = in.read(data, offset, data.length - offset)) != -1) {
  23.231 +                offset += n;
  23.232 +                if (offset == data.length)
  23.233 +                    data = Arrays.copyOf(data, 2 * data.length);
  23.234 +            }
  23.235 +        } finally {
  23.236 +            in.close();
  23.237 +        }
  23.238 +        return Arrays.copyOf(data, offset);
  23.239 +    }
  23.240 +
  23.241 +    void writeFile(File f, String s) throws IOException {
  23.242 +        f.getParentFile().mkdirs();
  23.243 +        FileWriter out = new FileWriter(f);
  23.244 +        try {
  23.245 +            out.write(s);
  23.246 +        } finally {
  23.247 +            out.close();
  23.248 +        }
  23.249 +    }
  23.250 +
  23.251 +    void error(String msg) {
  23.252 +        System.err.println(msg);
  23.253 +        errors++;
  23.254 +    }
  23.255 +
  23.256 +    int errors;
  23.257 +}
    24.1 --- a/test/tools/javac/api/6733837/T6733837.java	Wed Sep 23 18:29:41 2009 -0700
    24.2 +++ b/test/tools/javac/api/6733837/T6733837.java	Wed Sep 23 18:48:13 2009 -0700
    24.3 @@ -46,14 +46,10 @@
    24.4      }
    24.5  
    24.6      public void exec() {
    24.7 -        JavaFileObject sfo = new SimpleJavaFileObject(URI.create(""),Kind.SOURCE) {
    24.8 +        JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"),Kind.SOURCE) {
    24.9              public CharSequence getCharContent(boolean ignoreEncodingErrors) {
   24.10                  return "\tclass ErroneousWithTab";
   24.11              }
   24.12 -            @Override
   24.13 -            public String getName() {
   24.14 -                return "RELATIVEPATH";
   24.15 -            }
   24.16          };
   24.17          StringWriter sw = new StringWriter();
   24.18          PrintWriter out = new PrintWriter(sw);
   24.19 @@ -66,7 +62,7 @@
   24.20              throw new Error("Compiler threw an exception");
   24.21          }
   24.22          System.err.println(sw.toString());
   24.23 -        if (sw.toString().contains("RELATIVEPATH"))
   24.24 +        if (!sw.toString().contains("/Test.java"))
   24.25              throw new Error("Bad source name in diagnostic");
   24.26      }
   24.27  }

mercurial