Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECJ allows modifiers in explicit requires of java.base #3151 #3152

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,8 @@ public interface IProblem {
int UndefinedModuleAddReads = ModuleRelated + 1319;
/** @since 3.20 */
int ExportingForeignPackage = ModuleRelated + 1320;

/** @since 3.40 */
int IllegalModifierInRequires = ModuleRelated + 1321;

/** @since 3.14 */
int DuplicateResource = Internal + 1251;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.SourceModuleBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit;
import org.eclipse.jdt.internal.compiler.problem.AbortMethod;
Expand Down Expand Up @@ -155,8 +156,13 @@ public void resolveModuleDirectives(CompilationUnitScope cuScope) {
if (!requiredModules.add(ref.resolvedBinding)) {
cuScope.problemReporter().duplicateModuleReference(IProblem.DuplicateRequires, ref.module);
}
if (ref.isTransitive())
requiredTransitiveModules.add(ref.resolvedBinding);
if (ref.modifiers != 0) {
if (!CharOperation.equals(TypeConstants.JAVA_BASE, this.tokens) &&
CharOperation.equals(TypeConstants.JAVA_BASE, ref.module.tokens)) {
cuScope.problemReporter().illegalModifierInRequires(ref.module);
} else if (ref.isTransitive())
requiredTransitiveModules.add(ref.resolvedBinding);
}
Collection<ModuleBinding> deps = ref.resolvedBinding.dependencyGraphCollector().get();
if (deps.contains(this.binding)) {
cuScope.problemReporter().cyclicModuleDependency(this.binding, ref.module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11547,6 +11547,13 @@ public void exportingForeignPackage(PackageVisibilityStatement ref, ModuleBindin
ref.pkgRef.sourceStart,
ref.pkgRef.sourceEnd);
}
public void illegalModifierInRequires(ModuleReference ref) {
this.handle(IProblem.IllegalModifierInRequires,
NoArgument,
new String[] { CharOperation.charToString(ref.moduleName) },
ref.sourceStart,
ref.sourceEnd);
}
public void duplicateModuleReference(int problem, ModuleReference ref) {
this.handle(problem,
NoArgument, new String[] { CharOperation.charToString(ref.moduleName) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@
1318 = Illegal modifier for module {0}; only open is permitted
1319 = {0} cannot be resolved to a module, it is referenced from an add-reads directive
1320 = Cannot export the package {0} which belongs to module {1}

1321 = Modifiers not allowed in requires statement for ''java.base''
#### Java 9
1351 = Variable resource not allowed here for source level below 9

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ class ProblemAttributes {
expectedProblemAttributes.put("IllegalModifierForArgument", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("IllegalModifierForClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IllegalModifierForConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("StrictfpNotRequired", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
expectedProblemAttributes.put("IllegalModifierForEnum", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IllegalModifierForEnumConstant", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("IllegalModifierForEnumConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
Expand All @@ -585,6 +584,7 @@ class ProblemAttributes {
expectedProblemAttributes.put("IllegalModifierForVariable", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("IllegalModifiersForElidedType", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
expectedProblemAttributes.put("IllegalModifiers", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
expectedProblemAttributes.put("IllegalModifierInRequires", new ProblemAttributes(CategorizedProblem.CAT_MODULE));
expectedProblemAttributes.put("IllegalParameterNullityRedefinition", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("IllegalPrimitiveOrArrayTypeForEnclosingInstance", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("IllegalQualifiedEnumConstantLabel", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
Expand Down Expand Up @@ -1050,6 +1050,7 @@ class ProblemAttributes {
expectedProblemAttributes.put("StaticMethodRequested", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("StaticMethodShouldBeAccessedStatically", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("StaticResourceField", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
expectedProblemAttributes.put("StrictfpNotRequired", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX));
expectedProblemAttributes.put("StringConstantIsExceedingUtf8Limit", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
expectedProblemAttributes.put("SuperAccessCannotBypassDirectSuper", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("SuperCallCannotBypassOverride", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
Expand Down Expand Up @@ -1699,7 +1700,6 @@ class ProblemAttributes {
expectedProblemAttributes.put("IllegalModifierForArgument", SKIP);
expectedProblemAttributes.put("IllegalModifierForClass", SKIP);
expectedProblemAttributes.put("IllegalModifierForConstructor", SKIP);
expectedProblemAttributes.put("StrictfpNotRequired", SKIP);
expectedProblemAttributes.put("IllegalModifierForEnum", SKIP);
expectedProblemAttributes.put("IllegalModifierForEnumConstant", SKIP);
expectedProblemAttributes.put("IllegalModifierForEnumConstructor", SKIP);
Expand All @@ -1719,6 +1719,7 @@ class ProblemAttributes {
expectedProblemAttributes.put("IllegalModifierForVariable", SKIP);
expectedProblemAttributes.put("IllegalModifiersForElidedType", SKIP);
expectedProblemAttributes.put("IllegalModifiers", SKIP);
expectedProblemAttributes.put("IllegalModifierInRequires", SKIP);
expectedProblemAttributes.put("IllegalParameterNullityRedefinition", SKIP);
expectedProblemAttributes.put("IllegalPrimitiveOrArrayTypeForEnclosingInstance", SKIP);
expectedProblemAttributes.put("IllegalQualifiedEnumConstantLabel", SKIP);
Expand Down Expand Up @@ -2187,6 +2188,7 @@ class ProblemAttributes {
expectedProblemAttributes.put("StaticMethodRequested", SKIP);
expectedProblemAttributes.put("StaticMethodShouldBeAccessedStatically", SKIP);
expectedProblemAttributes.put("StaticResourceField", new ProblemAttributes(JavaCore.COMPILER_PB_RECOMMENDED_RESOURCE_MANAGEMENT));
expectedProblemAttributes.put("StrictfpNotRequired", SKIP);
expectedProblemAttributes.put("StringConstantIsExceedingUtf8Limit", SKIP);
expectedProblemAttributes.put("SuperAccessCannotBypassDirectSuper", SKIP);
expectedProblemAttributes.put("SuperCallCannotBypassOverride", SKIP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6068,4 +6068,80 @@ public class AppServiceImpl implements IService {
""",
outFinal);
}
public void testGH3151_1() {
File outputDirectory = new File(OUTPUT_DIR);
Util.flushDirectoryContent(outputDirectory);
String out = "bin";
String directory = OUTPUT_DIR + File.separator + "src";
String moduleLoc = directory + File.separator + "mod.one";
List<String> files = new ArrayList<>();
writeFileCollecting(files, moduleLoc, "module-info.java",
"module mod.one { \n" +
" requires transitive java.base;\n" +
"}");
writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java",
"package p;\n" +
"public class X {\n" +
"}");

StringBuilder buffer = new StringBuilder();
buffer.append("-d " + OUTPUT_DIR + File.separator + out )
.append(" -9 ")
.append(" -classpath \"")
.append(Util.getJavaClassLibsAsString())
.append("\" ")
.append(" --module-source-path " + "\"" + directory + "\"");

runNegativeModuleTest(files,
buffer,
"",
"""
----------
1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 2)
requires transitive java.base;
^^^^^^^^^
Modifiers not allowed in requires statement for 'java.base'
----------
1 problem (1 error)
""",
"option");
}
public void testGH3151_2() {
File outputDirectory = new File(OUTPUT_DIR);
Util.flushDirectoryContent(outputDirectory);
String out = "bin";
String directory = OUTPUT_DIR + File.separator + "src";
String moduleLoc = directory + File.separator + "mod.one";
List<String> files = new ArrayList<>();
writeFileCollecting(files, moduleLoc, "module-info.java",
"module mod.one { \n" +
" requires static java.base;\n" +
"}");
writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java",
"package p;\n" +
"public class X {\n" +
"}");

StringBuilder buffer = new StringBuilder();
buffer.append("-d " + OUTPUT_DIR + File.separator + out )
.append(" -9 ")
.append(" -classpath \"")
.append(Util.getJavaClassLibsAsString())
.append("\" ")
.append(" --module-source-path " + "\"" + directory + "\"");

runNegativeModuleTest(files,
buffer,
"",
"""
----------
1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 2)
requires static java.base;
^^^^^^^^^
Modifiers not allowed in requires statement for 'java.base'
----------
1 problem (1 error)
""",
"option");
}
}
Loading