8205187: javac/javadoc should not crash if no java.lang; crash message obsolete

Reviewed-by: jjg
This commit is contained in:
Vicente Romero 2021-12-23 19:12:24 +00:00
parent bc0466c7ca
commit ff2ca4f21b
4 changed files with 17 additions and 15 deletions
src/jdk.compiler/share/classes/com/sun/tools/javac
test/langtools/tools/javac
diags/examples
fatalErrors

@ -356,8 +356,10 @@ public class TypeEnter implements Completer {
// Import-on-demand java.lang.
PackageSymbol javaLang = syms.enterPackage(syms.java_base, names.java_lang);
if (javaLang.members().isEmpty() && !javaLang.exists())
throw new FatalError(diags.fragment(Fragments.FatalErrNoJavaLang));
if (javaLang.members().isEmpty() && !javaLang.exists()) {
log.error(Errors.NoJavaLang);
throw new Abort();
}
importAll(make.at(tree.pos()).Import(make.QualIdent(javaLang), false), javaLang, env);
JCModuleDecl decl = tree.getModuleDecl();

@ -1528,13 +1528,13 @@ compiler.err.locn.invalid.arg.for.xpatch=\
compiler.err.file.sb.on.source.or.patch.path.for.module=\
file should be on source path, or on patch path for module
compiler.err.no.java.lang=\
Unable to find package java.lang in platform classes
#####
# Fatal Errors
compiler.misc.fatal.err.no.java.lang=\
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
# 0: name
compiler.misc.fatal.err.cant.locate.meth=\
Fatal Error: Unable to find method {0}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, 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
@ -21,7 +21,9 @@
* questions.
*/
// key: compiler.misc.fatal.err.no.java.lang
// key: compiler.err.error
// key: compiler.err.no.java.lang
// key: compiler.misc.count.error
// options: -source 8 -target 8 -Xbootclasspath: -classpath .
// run: backdoor

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@ -23,7 +23,7 @@
/*
* @test
* @bug 4263768 4785453
* @bug 4263768 4785453 8205187
* @summary Verify that the compiler does not crash when java.lang is not available
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
@ -38,7 +38,7 @@ import toolbox.JavacTask;
import toolbox.Task;
import toolbox.ToolBox;
public class NoJavaLangTest {
public class NoJavaLangTest {
private static final String noJavaLangSrc =
"public class NoJavaLang {\n" +
@ -50,7 +50,8 @@ public class NoJavaLangTest {
"}";
private static final String compilerErrorMessage =
"Fatal Error: Unable to find package java.lang in classpath or bootclasspath";
"error: Unable to find package java.lang in platform classes\n" +
"1 error";
public static void main(String[] args) throws Exception {
new NoJavaLangTest().run();
@ -90,7 +91,6 @@ public class NoJavaLangTest {
Files.delete(Paths.get("modules", "java.base", "java", "lang", "Object.class"));
// ideally we'd have a better message for this case
String[] mpOpts = { "--system", "none", "--module-path", "modules" };
test(mpOpts, compilerErrorMessage);
}
@ -101,15 +101,13 @@ public class NoJavaLangTest {
String out = new JavacTask(tb)
.options(options)
.sources(noJavaLangSrc)
.run(Task.Expect.FAIL, 3)
.run(Task.Expect.FAIL, 1)
.writeAll()
.getOutput(Task.OutputKind.DIRECT);
if (!out.trim().equals(expect)) {
throw new AssertionError("javac generated error output is not correct");
}
System.err.println("OK");
}
}