8060056: replace java.io.File with java.nio.file.Path
Reviewed-by: ksrini, jlahoda
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileObject.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileObject.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, Oracle and/or its affiliates. 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
@@ -25,20 +25,19 @@
package com.sun.tools.javac.file;
-import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.CharsetDecoder;
+import java.nio.file.Path;
+
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.*;
-
import com.sun.tools.javac.util.BaseFileManager;
import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api;
@@ -78,7 +77,7 @@
throw new UnsupportedOperationException();
}
- protected abstract String inferBinaryName(Iterable<? extends File> path);
+ protected abstract String inferBinaryName(Iterable<? extends Path> path);
protected static JavaFileObject.Kind getKind(String filename) {
return BaseFileManager.getKind(filename);
@@ -89,8 +88,8 @@
return (lastDot == -1 ? fileName : fileName.substring(0, lastDot));
}
- protected static URI createJarUri(File jarFile, String entryName) {
- URI jarURI = jarFile.toURI().normalize();
+ protected static URI createJarUri(Path jarFile, String entryName) {
+ URI jarURI = jarFile.toUri().normalize();
String separator = entryName.startsWith("/") ? "!" : "!/";
try {
// The jar URI convention appears to be not to re-encode the jarURI
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/CacheFSInfo.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/CacheFSInfo.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, Oracle and/or its affiliates. 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
@@ -25,8 +25,8 @@
package com.sun.tools.javac.file;
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -61,31 +61,31 @@
}
@Override
- public File getCanonicalFile(File file) {
+ public Path getCanonicalFile(Path file) {
Entry e = getEntry(file);
return e.canonicalFile;
}
@Override
- public boolean exists(File file) {
+ public boolean exists(Path file) {
Entry e = getEntry(file);
return e.exists;
}
@Override
- public boolean isDirectory(File file) {
+ public boolean isDirectory(Path file) {
Entry e = getEntry(file);
return e.isDirectory;
}
@Override
- public boolean isFile(File file) {
+ public boolean isFile(Path file) {
Entry e = getEntry(file);
return e.isFile;
}
@Override
- public List<File> getJarClassPath(File file) throws IOException {
+ public List<Path> getJarClassPath(Path file) throws IOException {
// don't bother to lock the cache, because it is thread-safe, and
// because the worst that can happen would be to create two identical
// jar class paths together and have one overwrite the other.
@@ -95,7 +95,7 @@
return e.jarClassPath;
}
- private Entry getEntry(File file) {
+ private Entry getEntry(Path file) {
// don't bother to lock the cache, because it is thread-safe, and
// because the worst that can happen would be to create two identical
// entries together and have one overwrite the other.
@@ -112,13 +112,13 @@
}
// could also be a Map<File,SoftReference<Entry>> ?
- private Map<File,Entry> cache = new ConcurrentHashMap<>();
+ private final Map<Path,Entry> cache = new ConcurrentHashMap<>();
private static class Entry {
- File canonicalFile;
+ Path canonicalFile;
boolean exists;
boolean isFile;
boolean isDirectory;
- List<File> jarClassPath;
+ List<Path> jarClassPath;
}
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/FSInfo.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/FSInfo.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,8 +1,10 @@
package com.sun.tools.javac.file;
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -42,29 +44,29 @@
context.put(FSInfo.class, this);
}
- public File getCanonicalFile(File file) {
+ public Path getCanonicalFile(Path file) {
try {
- return file.getCanonicalFile();
+ return file.toRealPath();
} catch (IOException e) {
- return file.getAbsoluteFile();
+ return file.toAbsolutePath();
}
}
- public boolean exists(File file) {
- return file.exists();
+ public boolean exists(Path file) {
+ return Files.exists(file);
}
- public boolean isDirectory(File file) {
- return file.isDirectory();
+ public boolean isDirectory(Path file) {
+ return Files.isDirectory(file);
}
- public boolean isFile(File file) {
- return file.isFile();
+ public boolean isFile(Path file) {
+ return Files.isRegularFile(file);
}
- public List<File> getJarClassPath(File file) throws IOException {
- String parent = file.getParent();
- try (JarFile jarFile = new JarFile(file)) {
+ public List<Path> getJarClassPath(Path file) throws IOException {
+ Path parent = file.getParent();
+ try (JarFile jarFile = new JarFile(file.toFile())) {
Manifest man = jarFile.getManifest();
if (man == null)
return Collections.emptyList();
@@ -77,14 +79,14 @@
if (path == null)
return Collections.emptyList();
- List<File> list = new ArrayList<>();
+ List<Path> list = new ArrayList<>();
for (StringTokenizer st = new StringTokenizer(path);
st.hasMoreTokens(); ) {
String elt = st.nextToken();
- File f = new File(elt);
+ Path f = Paths.get(elt);
if (!f.isAbsolute() && parent != null)
- f = new File(parent,elt).getAbsoluteFile();
+ f = parent.resolve(f).toAbsolutePath();
list.add(f);
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java Tue Oct 21 13:08:20 2014 -0700
@@ -25,17 +25,19 @@
package com.sun.tools.javac.file;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -46,6 +48,8 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import java.util.zip.ZipFile;
import javax.lang.model.SourceVersion;
@@ -54,8 +58,8 @@
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
+import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
import com.sun.tools.javac.file.RelativePath.RelativeFile;
-import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
import com.sun.tools.javac.util.BaseFileManager;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.DefinedBy;
@@ -94,15 +98,15 @@
protected boolean mmappedIO;
protected boolean symbolFileEnabled;
- protected enum SortFiles implements Comparator<File> {
+ protected enum SortFiles implements Comparator<Path> {
FORWARD {
- public int compare(File f1, File f2) {
- return f1.getName().compareTo(f2.getName());
+ public int compare(Path f1, Path f2) {
+ return f1.getFileName().compareTo(f2.getFileName());
}
},
REVERSE {
- public int compare(File f1, File f2) {
- return -f1.getName().compareTo(f2.getName());
+ public int compare(Path f1, Path f2) {
+ return -f1.getFileName().compareTo(f2.getFileName());
}
}
}
@@ -161,10 +165,10 @@
}
public JavaFileObject getFileForInput(String name) {
- return getRegularFile(new File(name));
+ return getRegularFile(Paths.get(name));
}
- public JavaFileObject getRegularFile(File file) {
+ public JavaFileObject getRegularFile(Path file) {
return new RegularFileObject(this, file);
}
@@ -254,25 +258,26 @@
* Insert all files in subdirectory subdirectory of directory directory
* which match fileKinds into resultList
*/
- private void listDirectory(File directory,
+ private void listDirectory(Path directory,
RelativeDirectory subdirectory,
Set<JavaFileObject.Kind> fileKinds,
boolean recurse,
ListBuffer<JavaFileObject> resultList) {
- File d = subdirectory.getFile(directory);
+ Path d = subdirectory.getFile(directory);
if (!caseMapCheck(d, subdirectory))
return;
- File[] files = d.listFiles();
- if (files == null)
- return;
- if (sortFiles != null)
- Arrays.sort(files, sortFiles);
+ java.util.List<Path> files;
+ try (Stream<Path> s = Files.list(d)) {
+ files = (sortFiles == null ? s : s.sorted(sortFiles)).collect(Collectors.toList());
+ } catch (IOException ignore) {
+ return;
+ }
- for (File f: files) {
- String fname = f.getName();
- if (f.isDirectory()) {
+ for (Path f: files) {
+ String fname = f.getFileName().toString();
+ if (Files.isDirectory(f)) {
if (recurse && SourceVersion.isIdentifier(fname)) {
listDirectory(directory,
new RelativeDirectory(subdirectory, fname),
@@ -283,7 +288,7 @@
} else {
if (isValidFile(fname, fileKinds)) {
JavaFileObject fe =
- new RegularFileObject(this, fname, new File(d, fname));
+ new RegularFileObject(this, fname, d.resolve(fname));
resultList.append(fe);
}
}
@@ -326,7 +331,7 @@
* Insert all files in subdirectory subdirectory of container which
* match fileKinds into resultList
*/
- private void listContainer(File container,
+ private void listContainer(Path container,
RelativeDirectory subdirectory,
Set<JavaFileObject.Kind> fileKinds,
boolean recurse,
@@ -371,13 +376,13 @@
* ends in a string of characters with the same case as given name.
* Ignore file separators in both path and name.
*/
- private boolean caseMapCheck(File f, RelativePath name) {
+ private boolean caseMapCheck(Path f, RelativePath name) {
if (fileSystemIsCaseSensitive) return true;
// Note that getCanonicalPath() returns the case-sensitive
// spelled file name.
String path;
try {
- path = f.getCanonicalPath();
+ path = f.toRealPath().toString();
} catch (IOException ex) {
return false;
}
@@ -414,8 +419,8 @@
}
public class MissingArchive implements Archive {
- final File zipFileName;
- public MissingArchive(File name) {
+ final Path zipFileName;
+ public MissingArchive(Path name) {
zipFileName = name;
}
public boolean contains(RelativePath name) {
@@ -445,7 +450,7 @@
/** A directory of zip files already opened.
*/
- Map<File, Archive> archives = new HashMap<>();
+ Map<Path, Archive> archives = new HashMap<>();
private static final String[] symbolFileLocation = { "lib", "ct.sym" };
private static final RelativeDirectory symbolFilePrefix
@@ -457,7 +462,7 @@
* fail over to the platform zip, and allow it to deal with a potentially
* non compliant zip file.
*/
- protected Archive openArchive(File zipFilename) throws IOException {
+ protected Archive openArchive(Path zipFilename) throws IOException {
try {
return openArchive(zipFilename, contextUseOptimizedZip);
} catch (IOException ioe) {
@@ -471,17 +476,17 @@
/** Open a new zip file directory, and cache it.
*/
- private Archive openArchive(File zipFileName, boolean useOptimizedZip) throws IOException {
- File origZipFileName = zipFileName;
+ private Archive openArchive(Path zipFileName, boolean useOptimizedZip) throws IOException {
+ Path origZipFileName = zipFileName;
if (symbolFileEnabled && locations.isDefaultBootClassPathRtJar(zipFileName)) {
- File file = zipFileName.getParentFile().getParentFile(); // ${java.home}
- if (new File(file.getName()).equals(new File("jre")))
- file = file.getParentFile();
+ Path file = zipFileName.getParent().getParent(); // ${java.home}
+ if (file.getFileName().equals(Paths.get("jre")))
+ file = file.getParent();
// file == ${jdk.home}
for (String name : symbolFileLocation)
- file = new File(file, name);
+ file = file.resolve(name);
// file == ${jdk.home}/lib/ct.sym
- if (file.exists())
+ if (Files.exists(file))
zipFileName = file;
}
@@ -494,7 +499,7 @@
String preindexCacheLocation = null;
if (!useOptimizedZip) {
- zdir = new ZipFile(zipFileName);
+ zdir = new ZipFile(zipFileName.toFile());
} else {
usePreindexedCache = options.isSet("usezipindex");
preindexCacheLocation = options.get("java.io.tmpdir");
@@ -544,12 +549,12 @@
options.isSet("writezipindexfiles")));
}
}
- } catch (FileNotFoundException ex) {
+ } catch (FileNotFoundException | NoSuchFileException ex) {
archive = new MissingArchive(zipFileName);
} catch (ZipFileIndex.ZipFormatException zfe) {
throw zfe;
} catch (IOException ex) {
- if (zipFileName.exists())
+ if (Files.exists(zipFileName))
log.error("error.reading.file", zipFileName, getMessage(ex));
archive = new MissingArchive(zipFileName);
}
@@ -609,13 +614,13 @@
nullCheck(packageName);
nullCheck(kinds);
- Iterable<? extends File> path = getLocation(location);
+ Iterable<? extends Path> path = asPaths(getLocation(location));
if (path == null)
return List.nil();
RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName);
ListBuffer<JavaFileObject> results = new ListBuffer<>();
- for (File directory : path)
+ for (Path directory : path)
listContainer(directory, subdirectory, kinds, recurse, results);
return results.toList();
}
@@ -625,7 +630,7 @@
file.getClass(); // null check
location.getClass(); // null check
// Need to match the path semantics of list(location, ...)
- Iterable<? extends File> path = getLocation(location);
+ Iterable<? extends Path> path = getLocationAsPaths(location);
if (path == null) {
return null;
}
@@ -685,16 +690,16 @@
}
private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException {
- Iterable<? extends File> path = getLocation(location);
+ Iterable<? extends Path> path = asPaths(getLocation(location));
if (path == null)
return null;
- for (File dir: path) {
+ for (Path dir: path) {
Archive a = archives.get(dir);
if (a == null) {
if (fsInfo.isDirectory(dir)) {
- File f = name.getFile(dir);
- if (f.exists())
+ Path f = name.getFile(dir);
+ if (Files.exists(f))
return new RegularFileObject(this, f);
continue;
}
@@ -748,29 +753,32 @@
FileObject sibling)
throws IOException
{
- File dir;
+ Path dir;
if (location == CLASS_OUTPUT) {
if (getClassOutDir() != null) {
dir = getClassOutDir();
} else {
- File siblingDir = null;
+ Path siblingDir = null;
if (sibling != null && sibling instanceof RegularFileObject) {
- siblingDir = ((RegularFileObject)sibling).file.getParentFile();
+ siblingDir = ((RegularFileObject)sibling).file.getParent();
}
- return new RegularFileObject(this, new File(siblingDir, fileName.basename()));
+ if (siblingDir == null)
+ return new RegularFileObject(this, Paths.get(fileName.basename()));
+ else
+ return new RegularFileObject(this, siblingDir.resolve(fileName.basename()));
}
} else if (location == SOURCE_OUTPUT) {
dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir());
} else {
- Iterable<? extends File> path = locations.getLocation(location);
+ Iterable<? extends Path> path = locations.getLocation(location);
dir = null;
- for (File f: path) {
+ for (Path f: path) {
dir = f;
break;
}
}
- File file = fileName.getFile(dir); // null-safe
+ Path file = fileName.getFile(dir); // null-safe
return new RegularFileObject(this, file);
}
@@ -785,7 +793,7 @@
else
result = new ArrayList<>();
for (File f: files)
- result.add(new RegularFileObject(this, nullCheck(f)));
+ result.add(new RegularFileObject(this, nullCheck(f).toPath()));
return result;
}
@@ -796,24 +804,29 @@
@DefinedBy(Api.COMPILER)
public void setLocation(Location location,
- Iterable<? extends File> path)
+ Iterable<? extends File> searchpath)
throws IOException
{
nullCheck(location);
- locations.setLocation(location, path);
+ locations.setLocation(location, asPaths(searchpath));
}
@DefinedBy(Api.COMPILER)
public Iterable<? extends File> getLocation(Location location) {
nullCheck(location);
+ return asFiles(locations.getLocation(location));
+ }
+
+ private Iterable<? extends Path> getLocationAsPaths(Location location) {
+ nullCheck(location);
return locations.getLocation(location);
}
- private File getClassOutDir() {
+ private Path getClassOutDir() {
return locations.getOutputLocation(CLASS_OUTPUT);
}
- private File getSourceOutDir() {
+ private Path getSourceOutDir() {
return locations.getOutputLocation(SOURCE_OUTPUT);
}
@@ -884,4 +897,50 @@
return s;
return e.toString();
}
+
+ /* Converters between files and paths.
+ * These are temporary until we can update the StandardJavaFileManager API.
+ */
+
+ static Iterable<Path> asPaths(final Iterable<? extends File> files) {
+ if (files == null)
+ return null;
+
+ return () -> new Iterator<Path>() {
+ Iterator<? extends File> iter = files.iterator();
+
+ @Override
+ public boolean hasNext() {
+ return iter.hasNext();
+ }
+
+ @Override
+ public Path next() {
+ return iter.next().toPath();
+ }
+ };
+ }
+
+ static Iterable<File> asFiles(final Iterable<? extends Path> paths) {
+ if (paths == null)
+ return null;
+
+ return () -> new Iterator<File>() {
+ Iterator<? extends Path> iter = paths.iterator();
+
+ @Override
+ public boolean hasNext() {
+ return iter.hasNext();
+ }
+
+ @Override
+ public File next() {
+ return iter.next().toFile();
+ }
+ };
+ }
+
+ static File asFile(Path path) {
+ return path == null ? null : path.toFile();
+ }
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java Tue Oct 21 13:08:20 2014 -0700
@@ -29,6 +29,10 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -40,7 +44,8 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
-import java.util.StringTokenizer;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
import java.util.zip.ZipFile;
import javax.tools.JavaFileManager;
@@ -105,7 +110,7 @@
this.fsInfo = fsInfo;
}
- public Collection<File> bootClassPath() {
+ public Collection<Path> bootClassPath() {
return getLocation(PLATFORM_CLASS_PATH);
}
@@ -115,56 +120,52 @@
return h.isDefault();
}
- boolean isDefaultBootClassPathRtJar(File file) {
+ boolean isDefaultBootClassPathRtJar(Path file) {
BootClassPathLocationHandler h
= (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH);
return h.isDefaultRtJar(file);
}
- public Collection<File> userClassPath() {
+ public Collection<Path> userClassPath() {
return getLocation(CLASS_PATH);
}
- public Collection<File> sourcePath() {
- Collection<File> p = getLocation(SOURCE_PATH);
+ public Collection<Path> sourcePath() {
+ Collection<Path> p = getLocation(SOURCE_PATH);
// TODO: this should be handled by the LocationHandler
return p == null || p.isEmpty() ? null : p;
}
/**
- * Split a path into its elements. Empty path elements will be ignored.
+ * Split a search path into its elements. Empty path elements will be ignored.
*
- * @param path The path to be split
+ * @param searchPath The search path to be split
* @return The elements of the path
*/
- private static Iterable<File> getPathEntries(String path) {
- return getPathEntries(path, null);
+ private static Iterable<Path> getPathEntries(String searchPath) {
+ return getPathEntries(searchPath, null);
}
/**
- * Split a path into its elements. If emptyPathDefault is not null, all empty elements in the
+ * Split a search path into its elements. If emptyPathDefault is not null, all empty elements in the
* path, including empty elements at either end of the path, will be replaced with the value of
* emptyPathDefault.
*
- * @param path The path to be split
+ * @param searchPath The search path to be split
* @param emptyPathDefault The value to substitute for empty path elements, or null, to ignore
* empty path elements
* @return The elements of the path
*/
- private static Iterable<File> getPathEntries(String path, File emptyPathDefault) {
- ListBuffer<File> entries = new ListBuffer<>();
- int start = 0;
- while (start <= path.length()) {
- int sep = path.indexOf(File.pathSeparatorChar, start);
- if (sep == -1) {
- sep = path.length();
+ private static Iterable<Path> getPathEntries(String searchPath, Path emptyPathDefault) {
+ ListBuffer<Path> entries = new ListBuffer<>();
+ for (String s: searchPath.split(Pattern.quote(File.pathSeparator), -1)) {
+ if (s.isEmpty()) {
+ if (emptyPathDefault != null) {
+ entries.add(emptyPathDefault);
+ }
+ } else {
+ entries.add(Paths.get(s));
}
- if (start < sep) {
- entries.add(new File(path.substring(start, sep)));
- } else if (emptyPathDefault != null) {
- entries.add(emptyPathDefault);
- }
- start = sep + 1;
}
return entries;
}
@@ -173,12 +174,12 @@
* Utility class to help evaluate a path option. Duplicate entries are ignored, jar class paths
* can be expanded.
*/
- private class SearchPath extends LinkedHashSet<File> {
+ private class SearchPath extends LinkedHashSet<Path> {
private static final long serialVersionUID = 0;
private boolean expandJarClassPaths = false;
- private final Set<File> canonicalValues = new HashSet<>();
+ private final Set<Path> canonicalValues = new HashSet<>();
public SearchPath expandJarClassPaths(boolean x) {
expandJarClassPaths = x;
@@ -188,9 +189,9 @@
/**
* What to use when path element is the empty string
*/
- private File emptyPathDefault = null;
+ private Path emptyPathDefault = null;
- public SearchPath emptyPathDefault(File x) {
+ public SearchPath emptyPathDefault(Path x) {
emptyPathDefault = x;
return this;
}
@@ -200,7 +201,7 @@
expandJarClassPaths = true;
try {
if (dirs != null) {
- for (File dir : getPathEntries(dirs)) {
+ for (Path dir : getPathEntries(dirs)) {
addDirectory(dir, warn);
}
}
@@ -214,8 +215,8 @@
return addDirectories(dirs, warn);
}
- private void addDirectory(File dir, boolean warn) {
- if (!dir.isDirectory()) {
+ private void addDirectory(Path dir, boolean warn) {
+ if (!Files.isDirectory(dir)) {
if (warn) {
log.warning(Lint.LintCategory.PATH,
"dir.path.element.not.found", dir);
@@ -223,15 +224,10 @@
return;
}
- File[] files = dir.listFiles();
- if (files == null) {
- return;
- }
-
- for (File direntry : files) {
- if (isArchive(direntry)) {
- addFile(direntry, warn);
- }
+ try (Stream<Path> s = Files.list(dir)) {
+ s.filter(dirEntry -> isArchive(dirEntry))
+ .forEach(dirEntry -> addFile(dirEntry, warn));
+ } catch (IOException ignore) {
}
}
@@ -246,20 +242,20 @@
return addFiles(files, warn);
}
- public SearchPath addFiles(Iterable<? extends File> files, boolean warn) {
+ public SearchPath addFiles(Iterable<? extends Path> files, boolean warn) {
if (files != null) {
- for (File file : files) {
+ for (Path file : files) {
addFile(file, warn);
}
}
return this;
}
- public SearchPath addFiles(Iterable<? extends File> files) {
+ public SearchPath addFiles(Iterable<? extends Path> files) {
return addFiles(files, warn);
}
- public void addFile(File file, boolean warn) {
+ public void addFile(Path file, boolean warn) {
if (contains(file)) {
// discard duplicates
return;
@@ -275,7 +271,7 @@
return;
}
- File canonFile = fsInfo.getCanonicalFile(file);
+ Path canonFile = fsInfo.getCanonicalFile(file);
if (canonicalValues.contains(canonFile)) {
/* Discard duplicates and avoid infinite recursion */
return;
@@ -287,7 +283,7 @@
/* Not a recognized extension; open it to see if
it looks like a valid zip file. */
try {
- ZipFile z = new ZipFile(file);
+ ZipFile z = new ZipFile(file.toFile());
z.close();
if (warn) {
log.warning(Lint.LintCategory.PATH,
@@ -318,9 +314,9 @@
// Manifest entry. In some future release, we may want to
// update this code to recognize URLs rather than simple
// filenames, but if we do, we should redo all path-related code.
- private void addJarClassPath(File jarFile, boolean warn) {
+ private void addJarClassPath(Path jarFile, boolean warn) {
try {
- for (File f : fsInfo.getJarClassPath(jarFile)) {
+ for (Path f : fsInfo.getJarClassPath(jarFile)) {
addFile(f, warn);
}
} catch (IOException e) {
@@ -365,12 +361,12 @@
/**
* @see StandardJavaFileManager#getLocation
*/
- abstract Collection<File> getLocation();
+ abstract Collection<Path> getLocation();
/**
* @see StandardJavaFileManager#setLocation
*/
- abstract void setLocation(Iterable<? extends File> files) throws IOException;
+ abstract void setLocation(Iterable<? extends Path> files) throws IOException;
}
/**
@@ -380,7 +376,7 @@
*/
private class OutputLocationHandler extends LocationHandler {
- private File outputDir;
+ private Path outputDir;
OutputLocationHandler(Location location, Option... options) {
super(location, options);
@@ -396,31 +392,31 @@
// need to decide how best to report issue for benefit of
// direct API call on JavaFileManager.handleOption(specifies IAE)
// vs. command line decoding.
- outputDir = (value == null) ? null : new File(value);
+ outputDir = (value == null) ? null : Paths.get(value);
return true;
}
@Override
- Collection<File> getLocation() {
+ Collection<Path> getLocation() {
return (outputDir == null) ? null : Collections.singleton(outputDir);
}
@Override
- void setLocation(Iterable<? extends File> files) throws IOException {
+ void setLocation(Iterable<? extends Path> files) throws IOException {
if (files == null) {
outputDir = null;
} else {
- Iterator<? extends File> pathIter = files.iterator();
+ Iterator<? extends Path> pathIter = files.iterator();
if (!pathIter.hasNext()) {
throw new IllegalArgumentException("empty path for directory");
}
- File dir = pathIter.next();
+ Path dir = pathIter.next();
if (pathIter.hasNext()) {
throw new IllegalArgumentException("path too long for directory");
}
- if (!dir.exists()) {
+ if (!Files.exists(dir)) {
throw new FileNotFoundException(dir + ": does not exist");
- } else if (!dir.isDirectory()) {
+ } else if (!Files.isDirectory(dir)) {
throw new IOException(dir + ": not a directory");
}
outputDir = dir;
@@ -435,7 +431,7 @@
*/
private class SimpleLocationHandler extends LocationHandler {
- protected Collection<File> searchPath;
+ protected Collection<Path> searchPath;
SimpleLocationHandler(Location location, Option... options) {
super(location, options);
@@ -452,12 +448,12 @@
}
@Override
- Collection<File> getLocation() {
+ Collection<Path> getLocation() {
return searchPath;
}
@Override
- void setLocation(Iterable<? extends File> files) {
+ void setLocation(Iterable<? extends Path> files) {
SearchPath p;
if (files == null) {
p = computePath(null);
@@ -488,7 +484,7 @@
}
@Override
- Collection<File> getLocation() {
+ Collection<Path> getLocation() {
lazy();
return searchPath;
}
@@ -520,7 +516,7 @@
protected SearchPath createPath() {
return new SearchPath()
.expandJarClassPaths(true) // Only search user jars for Class-Paths
- .emptyPathDefault(new File(".")); // Empty path elt ==> current directory
+ .emptyPathDefault(Paths.get(".")); // Empty path elt ==> current directory
}
private void lazy() {
@@ -539,14 +535,14 @@
*/
private class BootClassPathLocationHandler extends LocationHandler {
- private Collection<File> searchPath;
+ private Collection<Path> searchPath;
final Map<Option, String> optionValues = new EnumMap<>(Option.class);
/**
* rt.jar as found on the default bootclasspath. If the user specified a bootclasspath, null
* is used.
*/
- private File defaultBootClassPathRtJar = null;
+ private Path defaultBootClassPathRtJar = null;
/**
* Is bootclasspath the default?
@@ -567,7 +563,7 @@
return isDefaultBootClassPath;
}
- boolean isDefaultRtJar(File file) {
+ boolean isDefaultRtJar(Path file) {
lazy();
return file.equals(defaultBootClassPathRtJar);
}
@@ -604,13 +600,13 @@
}
@Override
- Collection<File> getLocation() {
+ Collection<Path> getLocation() {
lazy();
return searchPath;
}
@Override
- void setLocation(Iterable<? extends File> files) {
+ void setLocation(Iterable<? extends Path> files) {
if (files == null) {
searchPath = null; // reset to "uninitialized"
} else {
@@ -645,9 +641,9 @@
// Standard system classes for this compiler's release.
String files = System.getProperty("sun.boot.class.path");
path.addFiles(files, false);
- File rt_jar = new File("rt.jar");
- for (File file : getPathEntries(files)) {
- if (new File(file.getName()).equals(rt_jar)) {
+ Path rt_jar = Paths.get("rt.jar");
+ for (Path file : getPathEntries(files)) {
+ if (file.getFileName().equals(rt_jar)) {
defaultBootClassPathRtJar = file;
}
}
@@ -709,12 +705,12 @@
return (h == null ? false : h.handleOption(option, value));
}
- Collection<File> getLocation(Location location) {
+ Collection<Path> getLocation(Location location) {
LocationHandler h = getHandler(location);
return (h == null ? null : h.getLocation());
}
- File getOutputLocation(Location location) {
+ Path getOutputLocation(Location location) {
if (!location.isOutputLocation()) {
throw new IllegalArgumentException();
}
@@ -722,7 +718,7 @@
return ((OutputLocationHandler) h).outputDir;
}
- void setLocation(Location location, Iterable<? extends File> files) throws IOException {
+ void setLocation(Location location, Iterable<? extends Path> files) throws IOException {
LocationHandler h = getHandler(location);
if (h == null) {
if (location.isOutputLocation()) {
@@ -743,8 +739,8 @@
/**
* Is this the name of an archive file?
*/
- private boolean isArchive(File file) {
- String n = StringUtils.toLowerCase(file.getName());
+ private boolean isArchive(Path file) {
+ String n = StringUtils.toLowerCase(file.getFileName().toString());
return fsInfo.isFile(file)
&& (n.endsWith(".jar") || n.endsWith(".zip"));
}
@@ -753,50 +749,41 @@
* Utility method for converting a search path string to an array of directory and JAR file
* URLs.
*
- * Note that this method is called by apt and the DocletInvoker.
+ * Note that this method is called by the DocletInvoker.
*
* @param path the search path string
* @return the resulting array of directory and JAR file URLs
*/
public static URL[] pathToURLs(String path) {
- StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
- URL[] urls = new URL[st.countTokens()];
- int count = 0;
- while (st.hasMoreTokens()) {
- URL url = fileToURL(new File(st.nextToken()));
- if (url != null) {
- urls[count++] = url;
+ java.util.List<URL> urls = new ArrayList<>();
+ for (String s: path.split(Pattern.quote(File.pathSeparator))) {
+ if (!s.isEmpty()) {
+ URL url = fileToURL(Paths.get(s));
+ if (url != null) {
+ urls.add(url);
+ }
}
}
- urls = Arrays.copyOf(urls, count);
- return urls;
+ return urls.toArray(new URL[urls.size()]);
}
/**
* Returns the directory or JAR file URL corresponding to the specified local file name.
*
- * @param file the File object
+ * @param file the Path object
* @return the resulting directory or JAR file URL, or null if unknown
*/
- private static URL fileToURL(File file) {
- String name;
+ private static URL fileToURL(Path file) {
+ Path p;
try {
- name = file.getCanonicalPath();
+ p = file.toRealPath();
} catch (IOException e) {
- name = file.getAbsolutePath();
- }
- name = name.replace(File.separatorChar, '/');
- if (!name.startsWith("/")) {
- name = "/" + name;
- }
- // If the file does not exist, then assume that it's a directory
- if (!file.isFile()) {
- name = name + "/";
+ p = file.toAbsolutePath();
}
try {
- return new URL("file", "", name);
+ return p.normalize().toUri().toURL();
} catch (MalformedURLException e) {
- throw new IllegalArgumentException(file.toString());
+ return null;
}
}
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/RegularFileObject.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/RegularFileObject.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, Oracle and/or its affiliates. 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
@@ -25,9 +25,6 @@
package com.sun.tools.javac.file;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -39,8 +36,12 @@
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharsetDecoder;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.text.Normalizer;
+
import javax.tools.JavaFileObject;
-import java.text.Normalizer;
import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api;
@@ -59,33 +60,33 @@
*/
private boolean hasParents = false;
private String name;
- final File file;
- private Reference<File> absFileRef;
+ final Path file;
+ private Reference<Path> absFileRef;
final static boolean isMacOS = System.getProperty("os.name", "").contains("OS X");
- public RegularFileObject(JavacFileManager fileManager, File f) {
- this(fileManager, f.getName(), f);
+ public RegularFileObject(JavacFileManager fileManager, Path f) {
+ this(fileManager, f.getFileName().toString(), f);
}
- public RegularFileObject(JavacFileManager fileManager, String name, File f) {
+ public RegularFileObject(JavacFileManager fileManager, String name, Path f) {
super(fileManager);
- if (f.isDirectory()) {
+ if (Files.isDirectory(f)) {
throw new IllegalArgumentException("directories not supported");
}
this.name = name;
this.file = f;
- if (f.lastModified() > System.currentTimeMillis())
+ if (getLastModified() > System.currentTimeMillis())
fileManager.log.warning("file.from.future", f);
}
@Override @DefinedBy(Api.COMPILER)
public URI toUri() {
- return file.toURI().normalize();
+ return file.toUri().normalize();
}
@Override @DefinedBy(Api.COMPILER)
public String getName() {
- return file.getPath();
+ return file.toString();
}
@Override
@@ -100,21 +101,21 @@
@Override @DefinedBy(Api.COMPILER)
public InputStream openInputStream() throws IOException {
- return new FileInputStream(file);
+ return Files.newInputStream(file);
}
@Override @DefinedBy(Api.COMPILER)
public OutputStream openOutputStream() throws IOException {
fileManager.flushCache(this);
ensureParentDirectoriesExist();
- return new FileOutputStream(file);
+ return Files.newOutputStream(file);
}
@Override @DefinedBy(Api.COMPILER)
public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
CharBuffer cb = fileManager.getCachedContent(this);
if (cb == null) {
- try (InputStream in = new FileInputStream(file)) {
+ try (InputStream in = Files.newInputStream(file)) {
ByteBuffer bb = fileManager.makeByteBuffer(in);
JavaFileObject prev = fileManager.log.useSource(this);
try {
@@ -135,17 +136,26 @@
public Writer openWriter() throws IOException {
fileManager.flushCache(this);
ensureParentDirectoriesExist();
- return new OutputStreamWriter(new FileOutputStream(file), fileManager.getEncodingName());
+ return new OutputStreamWriter(Files.newOutputStream(file), fileManager.getEncodingName());
}
@Override @DefinedBy(Api.COMPILER)
public long getLastModified() {
- return file.lastModified();
+ try {
+ return Files.getLastModifiedTime(file).toMillis();
+ } catch (IOException e) {
+ return 0;
+ }
}
@Override @DefinedBy(Api.COMPILER)
public boolean delete() {
- return file.delete();
+ try {
+ Files.delete(file);
+ return true;
+ } catch (IOException e) {
+ return false;
+ }
}
@Override
@@ -154,20 +164,21 @@
}
@Override
- protected String inferBinaryName(Iterable<? extends File> path) {
- String fPath = file.getPath();
+ protected String inferBinaryName(Iterable<? extends Path> path) {
+ String fPath = file.toString();
//System.err.println("RegularFileObject " + file + " " +r.getPath());
- for (File dir: path) {
+ for (Path dir: path) {
//System.err.println("dir: " + dir);
- String dPath = dir.getPath();
+ String sep = dir.getFileSystem().getSeparator();
+ String dPath = dir.toString();
if (dPath.length() == 0)
dPath = System.getProperty("user.dir");
- if (!dPath.endsWith(File.separator))
- dPath += File.separator;
+ if (!dPath.endsWith(sep))
+ dPath += sep;
if (fPath.regionMatches(true, 0, dPath, 0, dPath.length())
- && new File(fPath.substring(0, dPath.length())).equals(new File(dPath))) {
+ && Paths.get(fPath.substring(0, dPath.length())).equals(Paths.get(dPath))) {
String relativeName = fPath.substring(dPath.length());
- return removeExtension(relativeName).replace(File.separatorChar, '.');
+ return removeExtension(relativeName).replace(sep, ".");
}
}
return null;
@@ -199,7 +210,7 @@
if (name.equalsIgnoreCase(n)) {
try {
// allow for Windows
- return file.getCanonicalFile().getName().equals(n);
+ return file.toRealPath().getFileName().toString().equals(n);
} catch (IOException e) {
}
}
@@ -208,12 +219,12 @@
private void ensureParentDirectoriesExist() throws IOException {
if (!hasParents) {
- File parent = file.getParentFile();
- if (parent != null && !parent.exists()) {
- if (!parent.mkdirs()) {
- if (!parent.exists() || !parent.isDirectory()) {
- throw new IOException("could not create parent directories");
- }
+ Path parent = file.getParent();
+ if (parent != null && !Files.isDirectory(parent)) {
+ try {
+ Files.createDirectories(parent);
+ } catch (IOException e) {
+ throw new IOException("could not create parent directories", e);
}
}
hasParents = true;
@@ -242,10 +253,10 @@
return getAbsoluteFile().hashCode();
}
- private File getAbsoluteFile() {
- File absFile = (absFileRef == null ? null : absFileRef.get());
+ private Path getAbsoluteFile() {
+ Path absFile = (absFileRef == null ? null : absFileRef.get());
if (absFile == null) {
- absFile = file.getAbsoluteFile();
+ absFile = file.toAbsolutePath();
absFileRef = new SoftReference<>(absFile);
}
return absFile;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/RelativePath.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/RelativePath.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2014, Oracle and/or its affiliates. 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
@@ -25,9 +25,11 @@
package com.sun.tools.javac.file;
-import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+
import javax.tools.JavaFileObject;
/**
@@ -52,12 +54,14 @@
public abstract String basename();
- public File getFile(File directory) {
- if (path.length() == 0)
- return directory;
- return new File(directory, path.replace('/', File.separatorChar));
+ public Path getFile(Path directory) {
+ if (directory == null)
+ directory = Paths.get("");
+ String sep = directory.getFileSystem().getSeparator();
+ return directory.resolve(path.replace("/", sep));
}
+ @Override
public int compareTo(RelativePath other) {
return path.compareTo(other.path);
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/SymbolArchive.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/SymbolArchive.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, Oracle and/or its affiliates. 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
@@ -25,10 +25,11 @@
package com.sun.tools.javac.file;
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+
import javax.tools.JavaFileObject;
import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
@@ -43,10 +44,10 @@
*/
public class SymbolArchive extends ZipArchive {
- final File origFile;
+ final Path origFile;
final RelativeDirectory prefix;
- public SymbolArchive(JavacFileManager fileManager, File orig, ZipFile zdir, RelativeDirectory prefix) throws IOException {
+ public SymbolArchive(JavacFileManager fileManager, Path orig, ZipFile zdir, RelativeDirectory prefix) throws IOException {
super(fileManager, zdir, false);
this.origFile = orig;
this.prefix = prefix;
@@ -94,7 +95,7 @@
}
@Override
- protected String inferBinaryName(Iterable<? extends File> path) {
+ protected String inferBinaryName(Iterable<? extends Path> path) {
String entryName = entry.getName();
String prefix = ((SymbolArchive) zarch).prefix.path;
if (entryName.startsWith(prefix))
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipArchive.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipArchive.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, Oracle and/or its affiliates. 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
@@ -25,15 +25,18 @@
package com.sun.tools.javac.file;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharsetDecoder;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@@ -49,8 +52,6 @@
import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api;
import com.sun.tools.javac.util.List;
-import java.lang.ref.Reference;
-import java.lang.ref.SoftReference;
/**
* <p><b>This is NOT part of any supported API.
@@ -131,10 +132,10 @@
return "ZipArchive[" + zfile.getName() + "]";
}
- private File getAbsoluteFile() {
- File absFile = (absFileRef == null ? null : absFileRef.get());
+ private Path getAbsoluteFile() {
+ Path absFile = (absFileRef == null ? null : absFileRef.get());
if (absFile == null) {
- absFile = new File(zfile.getName()).getAbsoluteFile();
+ absFile = Paths.get(zfile.getName()).toAbsolutePath();
absFileRef = new SoftReference<>(absFile);
}
return absFile;
@@ -155,7 +156,7 @@
/**
* A reference to the absolute filename for the zip file for the archive.
*/
- protected Reference<File> absFileRef;
+ protected Reference<Path> absFileRef;
/**
* A subclass of JavaFileObject representing zip entries.
@@ -175,7 +176,7 @@
@DefinedBy(Api.COMPILER)
public URI toUri() {
- File zipFile = new File(zarch.zfile.getName());
+ Path zipFile = Paths.get(zarch.zfile.getName());
return createJarUri(zipFile, entry.getName());
}
@@ -186,7 +187,7 @@
@Override
public String getShortName() {
- return new File(zarch.zfile.getName()).getName() + "(" + entry + ")";
+ return Paths.get(zarch.zfile.getName()).getFileName() + "(" + entry + ")";
}
@Override @DefinedBy(Api.COMPILER)
@@ -246,7 +247,7 @@
}
@Override
- protected String inferBinaryName(Iterable<? extends File> path) {
+ protected String inferBinaryName(Iterable<? extends Path> path) {
String entryName = entry.getName();
return removeExtension(entryName).replace('/', '.');
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipFileIndex.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipFileIndex.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. 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
@@ -26,18 +26,20 @@
package com.sun.tools.javac.file;
-import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
+import java.util.HashMap;
import java.util.LinkedHashMap;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -91,14 +93,14 @@
Collections.<RelativeDirectory>emptySet();
// ZipFileIndex data entries
- final File zipFile;
- private Reference<File> absFileRef;
+ final Path zipFile;
+ private Reference<Path> absFileRef;
long zipFileLastModified = NOT_MODIFIED;
private RandomAccessFile zipRandomFile;
private Entry[] entries;
private boolean readFromIndex = false;
- private File zipIndexFile = null;
+ private Path zipIndexFile = null;
private boolean triedToReadIndex = false;
final RelativeDirectory symbolFilePrefix;
private final int symbolFilePrefixLength;
@@ -117,7 +119,7 @@
return (zipRandomFile != null);
}
- ZipFileIndex(File zipFile, RelativeDirectory symbolFilePrefix, boolean writeIndex,
+ ZipFileIndex(Path zipFile, RelativeDirectory symbolFilePrefix, boolean writeIndex,
boolean useCache, String cacheLocation) throws IOException {
this.zipFile = zipFile;
this.symbolFilePrefix = symbolFilePrefix;
@@ -128,7 +130,7 @@
this.preindexedCacheLocation = cacheLocation;
if (zipFile != null) {
- this.zipFileLastModified = zipFile.lastModified();
+ this.zipFileLastModified = Files.getLastModifiedTime(zipFile).toMillis();
}
// Validate integrity of the zip file
@@ -148,10 +150,11 @@
}
private boolean isUpToDate() {
- if (zipFile != null
- && ((!NON_BATCH_MODE) || zipFileLastModified == zipFile.lastModified())
- && hasPopulatedData) {
- return true;
+ try {
+ return (zipFile != null
+ && ((!NON_BATCH_MODE) || zipFileLastModified == Files.getLastModifiedTime(zipFile).toMillis())
+ && hasPopulatedData);
+ } catch (IOException ignore) {
}
return false;
@@ -199,7 +202,7 @@
private void openFile() throws FileNotFoundException {
if (zipRandomFile == null && zipFile != null) {
- zipRandomFile = new RandomAccessFile(zipFile, "r");
+ zipRandomFile = new RandomAccessFile(zipFile.toFile(), "r");
}
}
@@ -785,11 +788,11 @@
entries.add(zipFileIndex.entries[i]);
}
} else {
- File indexFile = zipFileIndex.getIndexFile();
+ Path indexFile = zipFileIndex.getIndexFile();
if (indexFile != null) {
RandomAccessFile raf = null;
try {
- raf = new RandomAccessFile(indexFile, "r");
+ raf = new RandomAccessFile(indexFile.toFile(), "r");
raf.seek(writtenOffsetOffset);
for (int nFiles = 0; nFiles < numEntries; nFiles++) {
@@ -856,11 +859,11 @@
triedToReadIndex = true;
RandomAccessFile raf = null;
try {
- File indexFileName = getIndexFile();
- raf = new RandomAccessFile(indexFileName, "r");
+ Path indexFileName = getIndexFile();
+ raf = new RandomAccessFile(indexFileName.toFile(), "r");
long fileStamp = raf.readLong();
- if (zipFile.lastModified() != fileStamp) {
+ if (Files.getLastModifiedTime(zipFile).toMillis() != fileStamp) {
ret = false;
} else {
directories = new LinkedHashMap<>();
@@ -908,7 +911,7 @@
return true;
}
- File indexFile = getIndexFile();
+ Path indexFile = getIndexFile();
if (indexFile == null) {
return false;
}
@@ -916,7 +919,7 @@
RandomAccessFile raf = null;
long writtenSoFar = 0;
try {
- raf = new RandomAccessFile(indexFile, "rw");
+ raf = new RandomAccessFile(indexFile.toFile(), "rw");
raf.writeLong(zipFileLastModified);
writtenSoFar += 8;
@@ -1016,27 +1019,27 @@
}
}
- private File getIndexFile() {
+ private Path getIndexFile() {
if (zipIndexFile == null) {
if (zipFile == null) {
return null;
}
- zipIndexFile = new File((preindexedCacheLocation == null ? "" : preindexedCacheLocation) +
- zipFile.getName() + ".index");
+ zipIndexFile = Paths.get((preindexedCacheLocation == null ? "" : preindexedCacheLocation) +
+ zipFile.getFileName() + ".index");
}
return zipIndexFile;
}
- public File getZipFile() {
+ public Path getZipFile() {
return zipFile;
}
- File getAbsoluteFile() {
- File absFile = (absFileRef == null ? null : absFileRef.get());
+ Path getAbsoluteFile() {
+ Path absFile = (absFileRef == null ? null : absFileRef.get());
if (absFile == null) {
- absFile = zipFile.getAbsoluteFile();
+ absFile = zipFile.toAbsolutePath();
absFileRef = new SoftReference<>(absFile);
}
return absFile;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java Tue Oct 21 13:08:20 2014 -0700
@@ -25,12 +25,8 @@
package com.sun.tools.javac.file;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.util.Set;
-import javax.tools.JavaFileObject;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
@@ -38,6 +34,10 @@
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharsetDecoder;
+import java.nio.file.Path;
+import java.util.Set;
+
+import javax.tools.JavaFileObject;
import com.sun.tools.javac.file.JavacFileManager.Archive;
import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
@@ -56,7 +56,7 @@
public class ZipFileIndexArchive implements Archive {
private final ZipFileIndex zfIndex;
- private JavacFileManager fileManager;
+ private final JavacFileManager fileManager;
public ZipFileIndexArchive(JavacFileManager fileManager, ZipFileIndex zdir) throws IOException {
super();
@@ -111,10 +111,10 @@
/** The name of the zip file where this entry resides.
*/
- File zipName;
+ Path zipName;
- ZipFileIndexFileObject(JavacFileManager fileManager, ZipFileIndex zfIndex, ZipFileIndex.Entry entry, File zipFileName) {
+ ZipFileIndexFileObject(JavacFileManager fileManager, ZipFileIndex zfIndex, ZipFileIndex.Entry entry, Path zipFileName) {
super(fileManager);
this.name = entry.getFileName();
this.zfIndex = zfIndex;
@@ -134,7 +134,7 @@
@Override
public String getShortName() {
- return zipName.getName() + "(" + entry.getName() + ")";
+ return zipName.getFileName() + "(" + entry.getName() + ")";
}
@Override @DefinedBy(Api.COMPILER)
@@ -194,7 +194,7 @@
}
@Override
- protected String inferBinaryName(Iterable<? extends File> path) {
+ protected String inferBinaryName(Iterable<? extends Path> path) {
String entryName = entry.getName();
if (zfIndex.symbolFilePrefix != null) {
String prefix = zfIndex.symbolFilePrefix.path;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipFileIndexCache.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipFileIndexCache.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2014, Oracle and/or its affiliates. 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
@@ -25,21 +25,22 @@
package com.sun.tools.javac.file;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
import com.sun.tools.javac.util.Context;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
/** A cache for ZipFileIndex objects. */
public class ZipFileIndexCache {
- private final Map<File, ZipFileIndex> map = new HashMap<>();
+ private final Map<Path, ZipFileIndex> map = new HashMap<>();
/** Get a shared instance of the cache. */
private static ZipFileIndexCache sharedInstance;
@@ -89,13 +90,13 @@
return zipFileIndexes;
}
- public synchronized ZipFileIndex getZipFileIndex(File zipFile,
+ public synchronized ZipFileIndex getZipFileIndex(Path zipFile,
RelativeDirectory symbolFilePrefix,
boolean useCache, String cacheLocation,
boolean writeIndex) throws IOException {
ZipFileIndex zi = getExistingZipIndex(zipFile);
- if (zi == null || (zi != null && zipFile.lastModified() != zi.zipFileLastModified)) {
+ if (zi == null || (zi != null && Files.getLastModifiedTime(zipFile).toMillis() != zi.zipFileLastModified)) {
zi = new ZipFileIndex(zipFile, symbolFilePrefix, writeIndex,
useCache, cacheLocation);
map.put(zipFile, zi);
@@ -103,7 +104,7 @@
return zi;
}
- public synchronized ZipFileIndex getExistingZipIndex(File zipFile) {
+ public synchronized ZipFileIndex getExistingZipIndex(Path zipFile) {
return map.get(zipFile);
}
@@ -112,7 +113,7 @@
}
public synchronized void clearCache(long timeNotUsed) {
- for (File cachedFile : map.keySet()) {
+ for (Path cachedFile : map.keySet()) {
ZipFileIndex cachedZipIndex = map.get(cachedFile);
if (cachedZipIndex != null) {
long timeToTest = cachedZipIndex.lastReferenceTimeStamp + timeNotUsed;
@@ -124,7 +125,7 @@
}
}
- public synchronized void removeFromCache(File file) {
+ public synchronized void removeFromCache(Path file) {
map.remove(file);
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Oct 21 13:08:20 2014 -0700
@@ -29,23 +29,27 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.CharBuffer;
+import java.nio.file.Path;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import javax.tools.JavaFileObject;
+
import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
-import com.sun.tools.javac.comp.Annotate;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Lint.LintCategory;
-import com.sun.tools.javac.code.Type.*;
import com.sun.tools.javac.code.Scope.WriteableScope;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Symtab;
+import com.sun.tools.javac.code.Type.*;
+import com.sun.tools.javac.comp.Annotate;
import com.sun.tools.javac.file.BaseFileObject;
+import com.sun.tools.javac.jvm.ClassFile.NameAndType;
+import com.sun.tools.javac.jvm.ClassFile.Version;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.DefinedBy.Api;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
@@ -2481,7 +2485,7 @@
}
@Override
- protected String inferBinaryName(Iterable<? extends File> path) {
+ protected String inferBinaryName(Iterable<? extends Path> path) {
return flatname.toString();
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Main.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Main.java Tue Oct 21 13:08:20 2014 -0700
@@ -29,10 +29,10 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
+import java.nio.file.NoSuchFileException;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-
import java.util.Set;
import javax.tools.JavaFileManager;
@@ -166,7 +166,7 @@
try {
argv = CommandLine.parse(argv);
- } catch (FileNotFoundException e) {
+ } catch (FileNotFoundException | NoSuchFileException e) {
warning("err.file.not.found", e.getMessage());
return Result.SYSERR;
} catch (IOException ex) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java Tue Oct 21 13:08:20 2014 -0700
@@ -30,12 +30,13 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
-import java.nio.file.Files;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
@@ -48,6 +49,7 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
+
import javax.lang.model.SourceVersion;
import javax.tools.FileObject;
import javax.tools.JavaFileManager;
@@ -55,9 +57,6 @@
import javax.tools.JavaFileObject.Kind;
import javax.tools.StandardLocation;
-import static java.nio.file.FileVisitOption.*;
-import static javax.tools.StandardLocation.*;
-
import com.sun.tools.javac.util.BaseFileManager;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.DefinedBy;
@@ -65,6 +64,10 @@
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
+import static java.nio.file.FileVisitOption.*;
+
+import static javax.tools.StandardLocation.*;
+
import static com.sun.tools.javac.main.Option.*;
@@ -221,7 +224,7 @@
}
private void setDefaultForLocation(Location locn) {
- Collection<File> files = null;
+ Collection<Path> files = null;
if (locn instanceof StandardLocation) {
switch ((StandardLocation) locn) {
case CLASS_PATH:
@@ -235,12 +238,12 @@
break;
case CLASS_OUTPUT: {
String arg = options.get(D);
- files = (arg == null ? null : Collections.singleton(new File(arg)));
+ files = (arg == null ? null : Collections.singleton(Paths.get(arg)));
break;
}
case SOURCE_OUTPUT: {
String arg = options.get(S);
- files = (arg == null ? null : Collections.singleton(new File(arg)));
+ files = (arg == null ? null : Collections.singleton(Paths.get(arg)));
break;
}
}
@@ -248,8 +251,8 @@
PathsForLocation pl = new PathsForLocation();
if (files != null) {
- for (File f: files)
- pl.add(f.toPath());
+ for (Path f: files)
+ pl.add(f);
}
if (!pl.isEmpty())
pathsForLocation.put(locn, pl);
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2014, Oracle and/or its affiliates. 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
@@ -24,6 +24,7 @@
*/
package com.sun.tools.javac.util;
+import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
@@ -48,6 +49,7 @@
import com.sun.tools.javac.jvm.Profile;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.tree.Pretty;
+
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
/**
@@ -186,7 +188,7 @@
else if (arg instanceof JCExpression) {
return expr2String((JCExpression)arg);
}
- else if (arg instanceof Iterable<?>) {
+ else if (arg instanceof Iterable<?> && !(arg instanceof Path)) {
return formatIterable(d, (Iterable<?>)arg, l);
}
else if (arg instanceof Type) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Tue Oct 21 13:08:20 2014 -0700
@@ -24,6 +24,7 @@
*/
package com.sun.tools.javac.util;
+import java.nio.file.Path;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
@@ -39,8 +40,8 @@
import com.sun.tools.javac.code.Type.*;
import com.sun.tools.javac.code.Types;
+import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.TypeTag.*;
-import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.Kinds.Kind.*;
import static com.sun.tools.javac.util.LayoutCharacters.*;
@@ -186,7 +187,7 @@
else if (arg instanceof JCDiagnostic) {
preprocessDiagnostic((JCDiagnostic)arg);
}
- else if (arg instanceof Iterable<?>) {
+ else if (arg instanceof Iterable<?> && !(arg instanceof Path)) {
for (Object o : (Iterable<?>)arg) {
preprocessArgument(o);
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javah/Gen.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javah/Gen.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2014, Oracle and/or its affiliates. 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
@@ -25,7 +25,6 @@
package com.sun.tools.javah;
-import java.io.UnsupportedEncodingException;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -33,6 +32,8 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -40,7 +41,6 @@
import java.util.Stack;
import javax.annotation.processing.ProcessingEnvironment;
-
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
@@ -48,7 +48,6 @@
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
-
import javax.tools.FileObject;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
@@ -204,7 +203,7 @@
event = "[Overwriting file ";
}
- } catch (FileNotFoundException e) {
+ } catch (FileNotFoundException | NoSuchFileException e) {
mustWrite = true;
event = "[Creating file ";
}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javah/JavahTask.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javah/JavahTask.java Tue Oct 21 13:08:20 2014 -0700
@@ -31,6 +31,7 @@
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
+import java.nio.file.NoSuchFileException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -50,7 +51,6 @@
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
-
import javax.lang.model.SourceVersion;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
@@ -62,7 +62,6 @@
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.SimpleTypeVisitor9;
import javax.lang.model.util.Types;
-
import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;
import javax.tools.JavaCompiler;
@@ -72,13 +71,15 @@
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;
-import static javax.tools.Diagnostic.Kind.*;
import com.sun.tools.javac.code.Symbol.CompletionFailure;
import com.sun.tools.javac.main.CommandLine;
import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api;
+import static javax.tools.Diagnostic.Kind.*;
+
+
/**
* Javah generates support files for native methods.
* Parse commandline options and invokes javadoc to execute those commands.
@@ -420,7 +421,7 @@
List<String> l = new ArrayList<>();
for (String arg: args) l.add(arg);
return Arrays.asList(CommandLine.parse(l.toArray(new String[l.size()])));
- } catch (FileNotFoundException e) {
+ } catch (FileNotFoundException | NoSuchFileException e) {
throw new BadArgs("at.args.file.not.found", e.getLocalizedMessage());
} catch (IOException e) {
throw new BadArgs("at.args.io.exception", e.getLocalizedMessage());
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/JavapTask.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/JavapTask.java Tue Oct 21 13:08:20 2014 -0700
@@ -36,6 +36,10 @@
import java.io.StringWriter;
import java.io.Writer;
import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.file.NoSuchFileException;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -61,10 +65,6 @@
import javax.tools.StandardLocation;
import com.sun.tools.classfile.*;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-
import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api;
@@ -568,7 +568,7 @@
} catch (EOFException e) {
reportError("err.end.of.file", className);
result = EXIT_ERROR;
- } catch (FileNotFoundException e) {
+ } catch (FileNotFoundException | NoSuchFileException e) {
reportError("err.file.not.found", e.getLocalizedMessage());
result = EXIT_ERROR;
} catch (IOException e) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/JavacState.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/JavacState.java Tue Oct 21 13:08:20 2014 -0700
@@ -26,16 +26,17 @@
package com.sun.tools.sjavac;
import java.io.*;
+import java.net.URI;
+import java.nio.file.NoSuchFileException;
+import java.text.SimpleDateFormat;
+import java.util.*;
import java.util.Collections;
import java.util.Date;
-import java.util.Set;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.HashMap;
-import java.text.SimpleDateFormat;
-import java.net.URI;
-import java.util.*;
+import java.util.Set;
import com.sun.tools.sjavac.options.Options;
import com.sun.tools.sjavac.server.Sjavac;
@@ -364,7 +365,7 @@
}
}
}
- } catch (FileNotFoundException e) {
+ } catch (FileNotFoundException | NoSuchFileException e) {
// Silently create a new javac_state file.
noFileFound = true;
} catch (IOException e) {
@@ -841,7 +842,7 @@
}
listedSources.add(l);
}
- } catch (FileNotFoundException e) {
+ } catch (FileNotFoundException | NoSuchFileException e) {
throw new ProblemException("Could not open "+makefileSourceList.getPath()+" since it does not exist!");
} catch (IOException e) {
throw new ProblemException("Could not read "+makefileSourceList.getPath());
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/client/SjavacClient.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/client/SjavacClient.java Tue Oct 21 13:08:20 2014 -0700
@@ -44,12 +44,12 @@
import com.sun.tools.sjavac.Log;
import com.sun.tools.sjavac.ProblemException;
import com.sun.tools.sjavac.Util;
+import com.sun.tools.sjavac.options.Options;
import com.sun.tools.sjavac.server.CompilationResult;
import com.sun.tools.sjavac.server.PortFile;
import com.sun.tools.sjavac.server.Sjavac;
import com.sun.tools.sjavac.server.SjavacServer;
import com.sun.tools.sjavac.server.SysInfo;
-import com.sun.tools.sjavac.options.Options;
/**
* Sjavac implementation that delegates requests to a SjavacServer.
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartFileObject.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/SmartFileObject.java Tue Oct 21 13:08:20 2014 -0700
@@ -27,6 +27,8 @@
import java.io.*;
import java.net.URI;
+import java.nio.file.NoSuchFileException;
+
import javax.lang.model.element.Modifier;
import javax.lang.model.element.NestingKind;
import javax.tools.JavaFileObject;
@@ -108,7 +110,7 @@
while (r.ready()) {
s.append(r.readLine()+lineseparator);
}
- } catch (FileNotFoundException e) {
+ } catch (FileNotFoundException | NoSuchFileException e) {
// Perfectly ok.
}
return new SmartWriter(file, s.toString(), file.getName(), stdout);
--- a/langtools/test/tools/javac/T6725036.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/test/tools/javac/T6725036.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2014, Oracle and/or its affiliates. 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
@@ -59,7 +59,7 @@
long jarEntryTime = je.getTime();
ZipFileIndexCache zfic = ZipFileIndexCache.getSharedInstance();
- ZipFileIndex zfi = zfic.getZipFileIndex(rt_jar, null, false, null, false);
+ ZipFileIndex zfi = zfic.getZipFileIndex(rt_jar.toPath(), null, false, null, false);
long zfiTime = zfi.getLastModified(TEST_ENTRY_NAME);
check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME.getPath(), zfiTime);
--- a/langtools/test/tools/javac/api/6440528/T6440528.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/test/tools/javac/api/6440528/T6440528.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2014, Oracle and/or its affiliates. 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
@@ -34,6 +34,7 @@
import java.io.File;
import java.lang.reflect.Field;
+import java.nio.file.Path;
import java.util.Arrays;
import static javax.tools.StandardLocation.CLASS_OUTPUT;
import javax.tools.*;
@@ -59,10 +60,10 @@
System.err.println("Got: " + got);
}
- private File getUnderlyingFile(Object o) throws Exception {
- Field file = o.getClass().getDeclaredField("file");
+ private File getUnderlyingFile(FileObject o) throws Exception {
+ Field file = o.getClass().getDeclaredField("file"); // assumes RegularFileObject
file.setAccessible(true);
- return (File)file.get(o);
+ return ((Path)file.get(o)).toFile();
}
public static void main(String... args) throws Exception {
--- a/langtools/test/tools/javac/file/T7018098.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/test/tools/javac/file/T7018098.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, Oracle and/or its affiliates. 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
@@ -99,7 +99,7 @@
round++;
if (round == 1) {
boolean expect = Boolean.valueOf(options.get("expect"));
- checkEqual("cache result", fsInfo.isDirectory(testDir), expect);
+ checkEqual("cache result", fsInfo.isDirectory(testDir.toPath()), expect);
initialFSInfo = fsInfo;
} else {
checkEqual("fsInfo", fsInfo, initialFSInfo);
--- a/langtools/test/tools/javac/file/T7068437.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/test/tools/javac/file/T7068437.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, Oracle and/or its affiliates. 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
@@ -30,6 +30,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Writer;
+import java.nio.file.NoSuchFileException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
@@ -104,7 +105,7 @@
messager.printMessage(Kind.NOTE, "found previous content of length " +
filer.getResource(StandardLocation.SOURCE_OUTPUT, "p", "C.java").getCharContent(false).length());
found = true;
- } catch (FileNotFoundException x) {
+ } catch (FileNotFoundException | NoSuchFileException x) {
messager.printMessage(Kind.NOTE, "not previously there");
found = false;
} catch (IOException x) {
--- a/langtools/test/tools/javac/file/T7068451.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/test/tools/javac/file/T7068451.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, Oracle and/or its affiliates. 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
@@ -33,6 +33,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
+import java.nio.file.NoSuchFileException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -140,7 +141,7 @@
try {
int len = filer.getResource(StandardLocation.SOURCE_OUTPUT, "p", "C.java").getCharContent(false).length();
messager.printMessage(Kind.NOTE, "C.java: found previous content of length " + len);
- } catch (FileNotFoundException x) {
+ } catch (FileNotFoundException | NoSuchFileException x) {
messager.printMessage(Kind.NOTE, "C.java: not previously there");
} catch (IOException x) {
messager.printMessage(Kind.ERROR, "while reading: " + x);
--- a/langtools/test/tools/javac/processing/errors/CrashOnNonExistingAnnotation/Processor.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/test/tools/javac/processing/errors/CrashOnNonExistingAnnotation/Processor.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, Oracle and/or its affiliates. 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
@@ -88,7 +88,7 @@
if (!testFile.canRead()) throw new IllegalStateException("Cannot read the test source");
JavacTool compiler = JavacTool.create();
JavacFileManager fm = compiler.getStandardFileManager(null, null, null);
- testContent = fm.getRegularFile(testFile).getCharContent(true).toString();
+ testContent = fm.getRegularFile(testFile.toPath()).getCharContent(true).toString();
JavaFileObject testFileObject = new TestFO(new URI("mem://" + args[0]), testContent);
TestFM testFileManager = new TestFM(fm);
JavacTask task = compiler.getTask(null,
--- a/langtools/test/tools/javac/processing/errors/StopOnInapplicableAnnotations/Processor.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/test/tools/javac/processing/errors/StopOnInapplicableAnnotations/Processor.java Tue Oct 21 13:08:20 2014 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, Oracle and/or its affiliates. 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
@@ -71,7 +71,7 @@
File inp = new File(sp, args[0]);
if (inp.canRead()) {
- testContent = fm.getRegularFile(inp).getCharContent(true).toString();
+ testContent = fm.getRegularFile(inp.toPath()).getCharContent(true).toString();
}
}
if (testContent == null) throw new IllegalStateException();
@@ -167,4 +167,4 @@
}
}
-}
\ No newline at end of file
+}
--- a/langtools/test/tools/javac/warnings/suppress/VerifySuppressWarnings.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/test/tools/javac/warnings/suppress/VerifySuppressWarnings.java Tue Oct 21 13:08:20 2014 -0700
@@ -74,7 +74,7 @@
File inp = new File(sp, args[0]);
if (inp.canRead()) {
- testContent = fm.getRegularFile(inp).getCharContent(true).toString();
+ testContent = fm.getRegularFile(inp.toPath()).getCharContent(true).toString();
}
}
if (testContent == null) throw new IllegalStateException();
--- a/langtools/test/tools/javap/WhitespaceTest.java Tue Oct 21 09:01:51 2014 -0400
+++ b/langtools/test/tools/javap/WhitespaceTest.java Tue Oct 21 13:08:20 2014 -0700
@@ -57,7 +57,7 @@
if (line.endsWith(" "))
error("line has trailing whitespace: " + line);
int comment = line.indexOf(doubleSlash);
- if (comment > 0 && line.charAt(comment - 1) != ' ')
+ if (comment > 0 && line.charAt(comment - 1) != ' ' && !line.contains("file:///"))
error("no space before comment: " + line);
if (line.matches(" +}"))
error("bad indentation: " + line);