8216170: java.lang.IllegalArgumentException: directories not supported

Reviewed-by: hannesw
This commit is contained in:
Jonathan Gibbons 2019-02-21 15:17:42 -08:00
parent 4aafd7b06e
commit 46666a2d94
2 changed files with 99 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2019, 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,9 @@
package jdk.javadoc.internal.tool;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
@ -165,7 +166,7 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
// Normally, the args should be a series of package names or file names.
// Parse the files and collect the package names.
for (String arg: javaNames) {
if (fm != null && arg.endsWith(".java") && new File(arg).exists()) {
if (fm != null && arg.endsWith(".java") && isRegularFile(arg)) {
parse(fm.getJavaFileObjects(arg), classTrees, true);
} else if (isValidPackageName(arg)) {
packageNames.add(arg);
@ -247,6 +248,14 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
return toolEnv.docEnv;
}
private boolean isRegularFile(String s) {
try {
return Files.isRegularFile(Paths.get(s));
} catch (InvalidPathException e) {
return false;
}
}
/** Is the given string a valid package name? */
boolean isValidPackageName(String s) {
if (s.contains("/")) {