Skip to content

Commit ff2ca4f

Browse files
author
Vicente Romero
committed
8205187: javac/javadoc should not crash if no java.lang; crash message obsolete
Reviewed-by: jjg
1 parent bc0466c commit ff2ca4f

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,10 @@ private void resolveImports(JCCompilationUnit tree, Env<AttrContext> env) {
356356

357357
// Import-on-demand java.lang.
358358
PackageSymbol javaLang = syms.enterPackage(syms.java_base, names.java_lang);
359-
if (javaLang.members().isEmpty() && !javaLang.exists())
360-
throw new FatalError(diags.fragment(Fragments.FatalErrNoJavaLang));
359+
if (javaLang.members().isEmpty() && !javaLang.exists()) {
360+
log.error(Errors.NoJavaLang);
361+
throw new Abort();
362+
}
361363
importAll(make.at(tree.pos()).Import(make.QualIdent(javaLang), false), javaLang, env);
362364

363365
JCModuleDecl decl = tree.getModuleDecl();

src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,13 +1528,13 @@ compiler.err.locn.invalid.arg.for.xpatch=\
15281528
compiler.err.file.sb.on.source.or.patch.path.for.module=\
15291529
file should be on source path, or on patch path for module
15301530

1531+
compiler.err.no.java.lang=\
1532+
Unable to find package java.lang in platform classes
1533+
15311534
#####
15321535

15331536
# Fatal Errors
15341537

1535-
compiler.misc.fatal.err.no.java.lang=\
1536-
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
1537-
15381538
# 0: name
15391539
compiler.misc.fatal.err.cant.locate.meth=\
15401540
Fatal Error: Unable to find method {0}

test/langtools/tools/javac/diags/examples/NoJavaLang.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,9 @@
2121
* questions.
2222
*/
2323

24-
// key: compiler.misc.fatal.err.no.java.lang
24+
// key: compiler.err.error
25+
// key: compiler.err.no.java.lang
26+
// key: compiler.misc.count.error
2527
// options: -source 8 -target 8 -Xbootclasspath: -classpath .
2628
// run: backdoor
2729

test/langtools/tools/javac/fatalErrors/NoJavaLangTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 4263768 4785453
26+
* @bug 4263768 4785453 8205187
2727
* @summary Verify that the compiler does not crash when java.lang is not available
2828
* @library /tools/lib
2929
* @modules jdk.compiler/com.sun.tools.javac.api
@@ -38,7 +38,7 @@
3838
import toolbox.Task;
3939
import toolbox.ToolBox;
4040

41-
public class NoJavaLangTest {
41+
public class NoJavaLangTest {
4242

4343
private static final String noJavaLangSrc =
4444
"public class NoJavaLang {\n" +
@@ -50,7 +50,8 @@ public class NoJavaLangTest {
5050
"}";
5151

5252
private static final String compilerErrorMessage =
53-
"Fatal Error: Unable to find package java.lang in classpath or bootclasspath";
53+
"error: Unable to find package java.lang in platform classes\n" +
54+
"1 error";
5455

5556
public static void main(String[] args) throws Exception {
5657
new NoJavaLangTest().run();
@@ -90,7 +91,6 @@ void testModulePath() throws Exception {
9091

9192
Files.delete(Paths.get("modules", "java.base", "java", "lang", "Object.class"));
9293

93-
// ideally we'd have a better message for this case
9494
String[] mpOpts = { "--system", "none", "--module-path", "modules" };
9595
test(mpOpts, compilerErrorMessage);
9696
}
@@ -101,15 +101,13 @@ private void test(String[] options, String expect) {
101101
String out = new JavacTask(tb)
102102
.options(options)
103103
.sources(noJavaLangSrc)
104-
.run(Task.Expect.FAIL, 3)
104+
.run(Task.Expect.FAIL, 1)
105105
.writeAll()
106106
.getOutput(Task.OutputKind.DIRECT);
107107

108108
if (!out.trim().equals(expect)) {
109109
throw new AssertionError("javac generated error output is not correct");
110110
}
111-
112-
System.err.println("OK");
113111
}
114112

115113
}

0 commit comments

Comments
 (0)