Skip to content

Commit 809a5f1

Browse files
committed
Make -try xlint warning disabled by default. (#40833)
Many gradle projects specifically use the -try exclude flag, because there are many cases where auto-closeable resource ignore is never referenced in body of corresponding try statement. Suppressing this warning specifically in each case that it happens using `@SuppressWarnings("try")` would be very verbose. This change removes `-try` from any gradle project and adds it to the build plugin. Also this change removes exclude flags from gradle projects that is already specified in build plugin (for example -deprecation). Relates to #40366
1 parent 5a2eb07 commit 809a5f1

File tree

14 files changed

+18
-22
lines changed

14 files changed

+18
-22
lines changed

benchmarks/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies {
3939
runtime 'org.apache.commons:commons-math3:3.2'
4040
}
4141

42-
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked,-processing"
42+
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked,-processing"
4343
// enable the JMH's BenchmarkProcessor to generate the final benchmark classes
4444
// needs to be added separately otherwise Gradle will quote it and javac will fail
4545
compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generators.BenchmarkProcessor"])

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ class BuildPlugin implements Plugin<Project> {
752752
*/
753753
// don't even think about passing args with -J-xxx, oracle will ask you to submit a bug report :)
754754
// fail on all javac warnings
755-
options.compilerArgs << '-Werror' << '-Xlint:all,-path,-serial,-options,-deprecation' << '-Xdoclint:all' << '-Xdoclint:-missing'
755+
options.compilerArgs << '-Werror' << '-Xlint:all,-path,-serial,-options,-deprecation,-try' << '-Xdoclint:all' << '-Xdoclint:-missing'
756756

757757
// either disable annotation processor completely (default) or allow to enable them if an annotation processor is explicitly defined
758758
if (options.compilerArgs.contains("-processor") == false) {

client/client-benchmark-noop-api-plugin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ assemble.enabled = false
3333
dependencyLicenses.enabled = false
3434
dependenciesInfo.enabled = false
3535

36-
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
36+
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
3737

3838
// no unit tests
3939
unitTest.enabled = false

modules/transport-netty4/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ esplugin {
2929
hasClientJar = true
3030
}
3131

32-
compileJava.options.compilerArgs << "-Xlint:-try"
33-
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
32+
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
3433

3534
dependencies {
3635
// network stack

server/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ if (isEclipse) {
151151
}
152152
}
153153

154-
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
155-
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
154+
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
155+
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
156156

157157
forbiddenPatterns {
158158
exclude '**/*.json'

test/framework/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535
compile "org.elasticsearch:mocksocket:${versions.mocksocket}"
3636
}
3737

38-
compileJava.options.compilerArgs << '-Xlint:-cast,-rawtypes,-try,-unchecked'
38+
compileJava.options.compilerArgs << '-Xlint:-cast,-rawtypes,-unchecked'
3939
compileTestJava.options.compilerArgs << '-Xlint:-rawtypes'
4040

4141
// the main files are actually test files, so use the appropriate forbidden api sigs

x-pack/plugin/ccr/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ archivesBaseName = 'x-pack-ccr'
1515

1616
integTest.enabled = false
1717

18-
compileJava.options.compilerArgs << "-Xlint:-try"
19-
compileTestJava.options.compilerArgs << "-Xlint:-try"
20-
2118
// Integration Test classes that cannot run with the security manager
2219
String[] noSecurityManagerITClasses = [ "**/CloseFollowerIndexIT.class" ]
2320

x-pack/plugin/core/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ forbiddenPatterns {
8585
exclude '**/*.zip'
8686
}
8787

88-
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
89-
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
88+
compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
89+
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
9090

9191
licenseHeaders {
9292
approvedLicenses << 'BCrypt (BSD-like)'

x-pack/plugin/monitoring/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ dependencies {
2626
testCompile "org.elasticsearch.plugin:x-pack-ilm:${version}"
2727
}
2828

29-
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
30-
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
29+
compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
30+
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
3131

3232
configurations {
3333
testArtifacts.extendsFrom testRuntime

x-pack/plugin/security/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ dependencies {
123123
testCompile('org.apache.directory.mavibot:mavibot:1.0.0-M8')
124124
}
125125

126-
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
127-
compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
126+
compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
127+
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
128128

129129
configurations {
130130
testArtifacts.extendsFrom testRuntime

0 commit comments

Comments
 (0)