Skip to content

Commit 72efb43

Browse files
authored
Remove --add-exports and most --add-opens. (#2792)
--add-exports are only required when source is set to 9 or above. Also, target Java 8 bytecode.
1 parent 94057c6 commit 72efb43

3 files changed

Lines changed: 21 additions & 44 deletions

File tree

build.gradle

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,20 @@ allprojects {
125125
tasks.withType(JavaCompile) {
126126
dependsOn(':installGitHooks')
127127
sourceCompatibility = 8
128-
if (isJava8) {
129-
// option --add-exports not allowed with target 1.8
130-
targetCompatibility = 8
131-
}
128+
targetCompatibility = 8
129+
130+
// When sourceCompatibilty is changed to 11, then the following will be required.
131+
// options.compilerArgs += [
132+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
133+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
134+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
135+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
136+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
137+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
138+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
139+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
140+
// "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
141+
// ]
132142
options.failOnError = true
133143
options.deprecation = true
134144
options.compilerArgs += [
@@ -138,19 +148,7 @@ allprojects {
138148
"-Xlint:-options",
139149
"-Xlint",
140150
]
141-
if (!isJava8) {
142-
options.compilerArgs += [
143-
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
144-
"--add-exports", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
145-
"--add-exports", "jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
146-
"--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
147-
"--add-exports", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
148-
"--add-exports", "jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
149-
"--add-exports", "jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
150-
"--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
151-
"--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
152-
]
153-
}
151+
154152
options.encoding = 'UTF-8'
155153
options.fork = true
156154
if (isJava8) {
@@ -588,15 +586,7 @@ subprojects {
588586
tasks.withType(Test) {
589587
if (!isJava8) {
590588
jvmArgs += [
591-
"--add-opens", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
592-
"--add-opens", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
593-
"--add-opens", "jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
594-
"--add-opens", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
595-
"--add-opens", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
596-
"--add-opens", "jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
597-
"--add-opens", "jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
598-
"--add-opens", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
599-
"--add-opens", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
589+
"--add-opens", "jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED"
600590
]
601591
}
602592

framework/src/main/java/org/checkerframework/framework/util/CheckerMain.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -395,24 +395,7 @@ public List<String> getExecArguments() {
395395
} else {
396396
args.addAll(
397397
Arrays.asList(
398-
"--add-opens",
399-
"jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
400-
"--add-opens",
401-
"jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
402-
"--add-opens",
403-
"jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
404-
"--add-opens",
405-
"jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
406-
"--add-opens",
407-
"jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
408-
"--add-opens",
409-
"jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
410-
"--add-opens",
411-
"jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
412-
"--add-opens",
413-
"jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
414-
"--add-opens",
415-
"jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"));
398+
"--add-opens", "jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED"));
416399
}
417400

418401
args.add("-classpath");

javacutil/src/main/java/org/checkerframework/javacutil/Resolver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
import javax.lang.model.type.TypeMirror;
3232

3333
/** A Utility class to find symbols corresponding to string references. */
34+
// This class reflectively accesses jdk.compiler/com.sun.tools.javac.comp.
35+
// This is why --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED is required when
36+
// running the Checker Framework. If this class is re-written, then that --add-opens should be
37+
// removed.
3438
public class Resolver {
3539
private final Resolve resolve;
3640
private final Names names;

0 commit comments

Comments
 (0)