From f11b5937f28e64ac4bff4d015f1f7e2c7c7e8d42 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 5 Apr 2019 08:01:56 +0200 Subject: [PATCH] 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 --- benchmarks/build.gradle | 2 +- .../main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy | 2 +- client/client-benchmark-noop-api-plugin/build.gradle | 2 +- modules/transport-netty4/build.gradle | 3 +-- server/build.gradle | 4 ++-- test/framework/build.gradle | 2 +- x-pack/plugin/ccr/build.gradle | 3 --- x-pack/plugin/core/build.gradle | 4 ++-- x-pack/plugin/monitoring/build.gradle | 4 ++-- x-pack/plugin/security/build.gradle | 4 ++-- x-pack/plugin/watcher/build.gradle | 4 ++-- x-pack/qa/rolling-upgrade-basic/build.gradle | 2 +- x-pack/qa/rolling-upgrade/build.gradle | 2 +- x-pack/qa/third-party/active-directory/build.gradle | 2 +- 14 files changed, 18 insertions(+), 22 deletions(-) diff --git a/benchmarks/build.gradle b/benchmarks/build.gradle index 351b0b9e97118..cca396071c195 100644 --- a/benchmarks/build.gradle +++ b/benchmarks/build.gradle @@ -39,7 +39,7 @@ dependencies { runtime 'org.apache.commons:commons-math3:3.2' } -compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked,-processing" +compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked,-processing" // enable the JMH's BenchmarkProcessor to generate the final benchmark classes // needs to be added separately otherwise Gradle will quote it and javac will fail compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generators.BenchmarkProcessor"]) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 8a0e7a05327b4..4bd740dde5106 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -752,7 +752,7 @@ class BuildPlugin implements Plugin { */ // don't even think about passing args with -J-xxx, oracle will ask you to submit a bug report :) // fail on all javac warnings - options.compilerArgs << '-Werror' << '-Xlint:all,-path,-serial,-options,-deprecation' << '-Xdoclint:all' << '-Xdoclint:-missing' + options.compilerArgs << '-Werror' << '-Xlint:all,-path,-serial,-options,-deprecation,-try' << '-Xdoclint:all' << '-Xdoclint:-missing' // either disable annotation processor completely (default) or allow to enable them if an annotation processor is explicitly defined if (options.compilerArgs.contains("-processor") == false) { diff --git a/client/client-benchmark-noop-api-plugin/build.gradle b/client/client-benchmark-noop-api-plugin/build.gradle index 6df52237e367e..2153ee3b72520 100644 --- a/client/client-benchmark-noop-api-plugin/build.gradle +++ b/client/client-benchmark-noop-api-plugin/build.gradle @@ -33,7 +33,7 @@ assemble.enabled = false dependencyLicenses.enabled = false dependenciesInfo.enabled = false -compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked" +compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked" // no unit tests unitTest.enabled = false diff --git a/modules/transport-netty4/build.gradle b/modules/transport-netty4/build.gradle index 787a4b6e9ecff..7ba745b1aa0fb 100644 --- a/modules/transport-netty4/build.gradle +++ b/modules/transport-netty4/build.gradle @@ -29,8 +29,7 @@ esplugin { hasClientJar = true } -compileJava.options.compilerArgs << "-Xlint:-try" -compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked" +compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked" dependencies { // network stack diff --git a/server/build.gradle b/server/build.gradle index 4fc8c451c9b96..d5ad8ac58ac66 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -151,8 +151,8 @@ if (isEclipse) { } } -compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked" -compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked" +compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked" +compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked" forbiddenPatterns { exclude '**/*.json' diff --git a/test/framework/build.gradle b/test/framework/build.gradle index fbc87988837cc..36eaa3f8b29a2 100644 --- a/test/framework/build.gradle +++ b/test/framework/build.gradle @@ -35,7 +35,7 @@ dependencies { compile "org.elasticsearch:mocksocket:${versions.mocksocket}" } -compileJava.options.compilerArgs << '-Xlint:-cast,-rawtypes,-try,-unchecked' +compileJava.options.compilerArgs << '-Xlint:-cast,-rawtypes,-unchecked' compileTestJava.options.compilerArgs << '-Xlint:-rawtypes' // the main files are actually test files, so use the appropriate forbidden api sigs diff --git a/x-pack/plugin/ccr/build.gradle b/x-pack/plugin/ccr/build.gradle index e1ddb2f12d78b..c3eb5b66e6af0 100644 --- a/x-pack/plugin/ccr/build.gradle +++ b/x-pack/plugin/ccr/build.gradle @@ -15,9 +15,6 @@ archivesBaseName = 'x-pack-ccr' integTest.enabled = false -compileJava.options.compilerArgs << "-Xlint:-try" -compileTestJava.options.compilerArgs << "-Xlint:-try" - // Integration Test classes that cannot run with the security manager String[] noSecurityManagerITClasses = [ "**/CloseFollowerIndexIT.class" ] diff --git a/x-pack/plugin/core/build.gradle b/x-pack/plugin/core/build.gradle index ed61fc9e3e703..19c1764e9c26d 100644 --- a/x-pack/plugin/core/build.gradle +++ b/x-pack/plugin/core/build.gradle @@ -85,8 +85,8 @@ forbiddenPatterns { exclude '**/*.zip' } -compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked" -compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked" +compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" +compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" licenseHeaders { approvedLicenses << 'BCrypt (BSD-like)' diff --git a/x-pack/plugin/monitoring/build.gradle b/x-pack/plugin/monitoring/build.gradle index 9341a957797ba..d3abb3fb2e733 100644 --- a/x-pack/plugin/monitoring/build.gradle +++ b/x-pack/plugin/monitoring/build.gradle @@ -26,8 +26,8 @@ dependencies { testCompile "org.elasticsearch.plugin:x-pack-ilm:${version}" } -compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked" -compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked" +compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" +compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" configurations { testArtifacts.extendsFrom testRuntime diff --git a/x-pack/plugin/security/build.gradle b/x-pack/plugin/security/build.gradle index 63b531b1f3319..acad15101f9b2 100644 --- a/x-pack/plugin/security/build.gradle +++ b/x-pack/plugin/security/build.gradle @@ -133,8 +133,8 @@ dependencies { testCompile('org.apache.directory.mavibot:mavibot:1.0.0-M8') } -compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked" -compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked" +compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" +compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" configurations { testArtifacts.extendsFrom testRuntime diff --git a/x-pack/plugin/watcher/build.gradle b/x-pack/plugin/watcher/build.gradle index a32a88aaf06e5..3efa13fc32024 100644 --- a/x-pack/plugin/watcher/build.gradle +++ b/x-pack/plugin/watcher/build.gradle @@ -14,8 +14,8 @@ archivesBaseName = 'x-pack-watcher' ext.compactProfile = 'full' -compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked" -compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked" +compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" +compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" dependencyLicenses { mapping from: /owasp-java-html-sanitizer.*/, to: 'owasp-java-html-sanitizer' diff --git a/x-pack/qa/rolling-upgrade-basic/build.gradle b/x-pack/qa/rolling-upgrade-basic/build.gradle index 5b7cad500361c..a3a2c078edc10 100644 --- a/x-pack/qa/rolling-upgrade-basic/build.gradle +++ b/x-pack/qa/rolling-upgrade-basic/build.gradle @@ -132,7 +132,7 @@ task bwcTestSnapshots { } check.dependsOn(bwcTestSnapshots) -compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked" +compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked" // copy x-pack plugin info so it is on the classpath and security manager has the right permissions task copyXPackRestSpec(type: Copy) { diff --git a/x-pack/qa/rolling-upgrade/build.gradle b/x-pack/qa/rolling-upgrade/build.gradle index 0cdbbe71e55ba..12ccf2c3f00a2 100644 --- a/x-pack/qa/rolling-upgrade/build.gradle +++ b/x-pack/qa/rolling-upgrade/build.gradle @@ -68,7 +68,7 @@ Closure waitWithAuth = { NodeInfo node, AntBuilder ant -> return tmpFile.exists() } -compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked" +compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked" forbiddenPatterns { exclude '**/system_key' diff --git a/x-pack/qa/third-party/active-directory/build.gradle b/x-pack/qa/third-party/active-directory/build.gradle index e33c0fa6d69f8..b0a48a7b19f91 100644 --- a/x-pack/qa/third-party/active-directory/build.gradle +++ b/x-pack/qa/third-party/active-directory/build.gradle @@ -10,7 +10,7 @@ testFixtures.useFixture ":x-pack:test:smb-fixture" // add test resources from security, so tests can use example certs sourceSets.test.resources.srcDirs(project(xpackModule('security')).sourceSets.test.resources.srcDirs) -compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked" +compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" // we have to repeat these patterns because the security test resources are effectively in the src of this project forbiddenPatterns {