mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-11 05:59:52 +00:00
8172901: javac: 'opens' statement cannot specify non observable package
Reviewed-by: jlahoda
This commit is contained in:
parent
c42d389e2d
commit
f4c670d9b6
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2017, 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
|
||||
@ -118,6 +118,7 @@ public class Lint
|
||||
if (source.compareTo(Source.JDK1_9) >= 0) {
|
||||
values.add(LintCategory.DEP_ANN);
|
||||
}
|
||||
values.add(LintCategory.OPENS);
|
||||
values.add(LintCategory.MODULE);
|
||||
values.add(LintCategory.REMOVAL);
|
||||
}
|
||||
@ -210,6 +211,11 @@ public class Lint
|
||||
*/
|
||||
MODULE("module"),
|
||||
|
||||
/**
|
||||
* Warn about issues regarding module opens.
|
||||
*/
|
||||
OPENS("opens"),
|
||||
|
||||
/**
|
||||
* Warn about issues relating to use of command line options
|
||||
*/
|
||||
|
||||
@ -3876,4 +3876,14 @@ public class Check {
|
||||
}
|
||||
}
|
||||
|
||||
void checkPackageExistsForOpens(final DiagnosticPosition pos, PackageSymbol packge) {
|
||||
if (packge.members().isEmpty() &&
|
||||
((packge.flags() & Flags.HAS_RESOURCE) == 0)) {
|
||||
deferredLintHandler.report(() -> {
|
||||
if (lint.isEnabled(LintCategory.OPENS))
|
||||
log.warning(pos, Warnings.PackageEmptyOrNotFound(packge));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -696,9 +696,6 @@ public class Modules extends JCTree.Visitor {
|
||||
PackageSymbol packge = syms.enterPackage(sym, name);
|
||||
attr.setPackageSymbols(tree.qualid, packge);
|
||||
|
||||
if (tree.hasTag(Tag.OPENS) && sym.flags.contains(ModuleFlags.OPEN)) {
|
||||
log.error(tree.pos(), Errors.NoOpensUnlessStrong);
|
||||
}
|
||||
List<ExportsDirective> exportsForPackage = allExports.computeIfAbsent(packge, p -> List.nil());
|
||||
for (ExportsDirective d : exportsForPackage) {
|
||||
reportExportsConflict(tree, packge);
|
||||
@ -899,10 +896,7 @@ public class Modules extends JCTree.Visitor {
|
||||
|
||||
@Override
|
||||
public void visitOpens(JCOpens tree) {
|
||||
if (tree.directive.packge.members().isEmpty() &&
|
||||
((tree.directive.packge.flags() & Flags.HAS_RESOURCE) == 0)) {
|
||||
log.error(tree.qualid.pos(), Errors.PackageEmptyOrNotFound(tree.directive.packge));
|
||||
}
|
||||
chk.checkPackageExistsForOpens(tree.qualid, tree.directive.packge);
|
||||
msym.directives = msym.directives.prepend(tree.directive);
|
||||
}
|
||||
|
||||
|
||||
@ -2928,6 +2928,10 @@ compiler.err.service.implementation.no.args.constructor.not.public=\
|
||||
compiler.err.package.empty.or.not.found=\
|
||||
package is empty or does not exist: {0}
|
||||
|
||||
# 0: symbol
|
||||
compiler.warn.package.empty.or.not.found=\
|
||||
package is empty or does not exist: {0}
|
||||
|
||||
compiler.err.no.output.dir=\
|
||||
no class output directory specified
|
||||
|
||||
|
||||
@ -204,6 +204,9 @@ javac.opt.Xlint.desc.finally=\
|
||||
javac.opt.Xlint.desc.module=\
|
||||
Warn about module system related issues.
|
||||
|
||||
javac.opt.Xlint.desc.opens=\
|
||||
Warn about issues regarding module opens.
|
||||
|
||||
javac.opt.Xlint.desc.options=\
|
||||
Warn about issues relating to use of command line options.
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, 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
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017, 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
|
||||
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2017, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
// key: compiler.warn.package.empty.or.not.found
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2017, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
module m1x {
|
||||
opens p1;
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2017, 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
|
||||
@ -105,7 +105,7 @@ public class ReportNonExistentPackageTest extends ModuleTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExportPrivateEmptyPackage(Path base) throws Exception {
|
||||
public void testOpensEmptyPackage(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"module m { opens p; }");
|
||||
@ -116,15 +116,34 @@ public class ReportNonExistentPackageTest extends ModuleTestBase {
|
||||
.options("-XDrawDiagnostics")
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(src))
|
||||
.run(Task.Expect.FAIL)
|
||||
.run(Task.Expect.SUCCESS)
|
||||
.writeAll()
|
||||
.getOutput(Task.OutputKind.DIRECT);
|
||||
if (!log.contains("module-info.java:1:18: compiler.err.package.empty.or.not.found: p"))
|
||||
if (!log.contains("module-info.java:1:18: compiler.warn.package.empty.or.not.found: p"))
|
||||
throw new Exception("expected output not found, actual output: " + log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExportPrivateOnlyWithResources(Path base) throws Exception {
|
||||
public void testOpensEmptyPackageSuppressed(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"@SuppressWarnings(\"opens\") module m { opens p; }");
|
||||
Path classes = base.resolve("classes");
|
||||
Files.createDirectories(classes);
|
||||
|
||||
String log = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics")
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(src))
|
||||
.run(Task.Expect.SUCCESS)
|
||||
.writeAll()
|
||||
.getOutput(Task.OutputKind.DIRECT);
|
||||
if (!log.equals(""))
|
||||
throw new Exception("expected output not found, actual output: " + log);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenOnlyWithResources(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"module m { opens p; }");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user