8201544: Improve javac command line parsing and error reporting

Modified exception into an error message for invalid filenames on windows

Reviewed-by: vromero, jjg
This commit is contained in:
Srinivas Dama 2019-02-14 21:52:39 +05:30 committed by Srinivas Dama
parent 904bb0919f
commit 37169f4bbc
4 changed files with 25 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 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
@ -29,6 +29,7 @@ import java.io.FileWriter;
import java.io.PrintWriter;
import java.lang.module.ModuleDescriptor;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.Collator;
@ -752,14 +753,18 @@ public enum Option {
@Override
public void process(OptionHelper helper, String option) throws InvalidValueException {
if (option.endsWith(".java") ) {
Path p = Paths.get(option);
if (!Files.exists(p)) {
throw helper.newInvalidValueException(Errors.FileNotFound(p.toString()));
try {
Path p = Paths.get(option);
if (!Files.exists(p)) {
throw helper.newInvalidValueException(Errors.FileNotFound(p.toString()));
}
if (!Files.isRegularFile(p)) {
throw helper.newInvalidValueException(Errors.FileNotFile(p));
}
helper.addFile(p);
} catch (InvalidPathException ex) {
throw helper.newInvalidValueException(Errors.InvalidPath(option));
}
if (!Files.isRegularFile(p)) {
throw helper.newInvalidValueException(Errors.FileNotFile(p));
}
helper.addFile(p);
} else {
helper.addClassName(option);
}

View File

@ -1977,6 +1977,11 @@ compiler.warn.deprecated.annotation.has.no.effect=\
compiler.warn.invalid.path=\
Invalid filename: {0}
# 0: string
compiler.err.invalid.path=\
Invalid filename: {0}
# 0: path
compiler.warn.invalid.archive.file=\
Unexpected file on path: {0}

View File

@ -125,6 +125,7 @@ compiler.misc.bad.class.file # class file is malforme
compiler.misc.bad.const.pool.entry # constant pool entry has wrong type
compiler.warn.access.to.member.from.serializable.lambda # in order to generate it we need to modify a restricted package
compiler.warn.invalid.path # this warning is generated only in Windows systems
compiler.err.invalid.path # this error is generated only in Windows systems
compiler.note.multiple.elements # needs user code
compiler.err.preview.feature.disabled.classfile # preview feature support: needs compilation against classfile
compiler.warn.preview.feature.use.classfile # preview feature support: needs compilation against classfile

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 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
@ -24,6 +24,7 @@
/*
* @test
* @bug 6986895
* @bug 8201544
* @summary compiler gives misleading message for no input files
* @modules jdk.compiler
*/
@ -38,6 +39,8 @@ public class T6986895 {
String noSourceFiles = "no source files";
String noSourceFilesOrClasses = "no source files or class names";
String invalidFileName = "Invalid filename";
boolean isWindows = System.getProperty("os.name").startsWith("Windows");
void run() throws Exception {
Locale prev = Locale.getDefault();
@ -45,6 +48,8 @@ public class T6986895 {
Locale.setDefault(Locale.ENGLISH);
test(noSourceFiles, "-Werror");
test(noSourceFilesOrClasses, "-Werror", "-Xprint");
if (isWindows)
test(invalidFileName, "-Werror", "someNonExistingFile*.java");
} finally {
Locale.setDefault(prev);
}