KAFKA-16564 Apply `Xlint` to java code in core module (#16965)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Ken Huang 2024-10-26 01:07:56 +08:00 committed by GitHub
parent 33147d1089
commit 09d76f917c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 14 deletions

View File

@ -113,11 +113,22 @@ ext {
commitId = determineCommitId()
addParametersForTests = { name, options ->
configureJavaCompiler = { name, options ->
// -parameters generates arguments with parameter names in TestInfo#getDisplayName.
// ref: https://github.com/junit-team/junit5/blob/4c0dddad1b96d4a20e92a2cd583954643ac56ac0/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTest.java#L161-L164
if (name == "compileTestJava" || name == "compileTestScala")
if (name == "compileTestJava" || name == "compileTestScala") {
options.compilerArgs << "-parameters"
} else if (name == "compileJava" || name == "compileScala") {
options.compilerArgs << "-Xlint:all"
if (!project.path.startsWith(":connect") && !project.path.startsWith(":storage"))
options.compilerArgs << "-Xlint:-rawtypes"
options.compilerArgs << "-encoding" << "UTF-8"
options.compilerArgs << "-Xlint:-rawtypes"
options.compilerArgs << "-Xlint:-serial"
options.compilerArgs << "-Xlint:-try"
options.compilerArgs << "-Werror"
options.compilerArgs += ["--release", String.valueOf(minJavaVersion)]
}
}
runtimeTestLibs = [
@ -308,16 +319,7 @@ subprojects {
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:all"
// temporary exclusions until all the warnings are fixed
if (!project.path.startsWith(":connect") && !project.path.startsWith(":storage"))
options.compilerArgs << "-Xlint:-rawtypes"
options.compilerArgs << "-Xlint:-serial"
options.compilerArgs << "-Xlint:-try"
options.compilerArgs << "-Werror"
options.release = minJavaVersion
addParametersForTests(name, options)
configureJavaCompiler(name, options)
}
if (shouldPublish) {
@ -769,9 +771,8 @@ subprojects {
scalaCompileOptions.additionalParameters += ["-Xfatal-warnings"]
scalaCompileOptions.additionalParameters += ["-release", String.valueOf(minJavaVersion)]
options.compilerArgs += ["--release", String.valueOf(minJavaVersion)]
addParametersForTests(name, options)
configureJavaCompiler(name, options)
configure(scalaCompileOptions.forkOptions) {
memoryMaximumSize = defaultMaxHeapSize

View File

@ -456,6 +456,7 @@ public class SynchronizationTest {
}
}
@SuppressWarnings("removal")
private static ThreadFactory threadFactoryWithNamedThreads(String threadPrefix) {
AtomicInteger threadNumber = new AtomicInteger(1);
return r -> {

View File

@ -221,6 +221,7 @@ public class RemoteLogManager implements Closeable {
* @param brokerTopicStats BrokerTopicStats instance to update the respective metrics.
* @param metrics Metrics instance
*/
@SuppressWarnings({"this-escape"})
public RemoteLogManager(RemoteLogManagerConfig rlmConfig,
int brokerId,
String logDir,
@ -331,6 +332,7 @@ public class RemoteLogManager implements Closeable {
rlmConfig.remoteLogManagerFetchQuotaWindowSizeSeconds());
}
@SuppressWarnings("unchecked")
private <T> T createDelegate(ClassLoader classLoader, String className) {
try {
return (T) classLoader.loadClass(className)

View File

@ -1312,6 +1312,7 @@ public class ConfigCommandTest {
return describeResult;
}
@SuppressWarnings("deprecation")
@Override
public synchronized AlterConfigsResult alterConfigs(Map<ConfigResource, Config> configs, AlterConfigsOptions options) {
assertEquals(1, configs.size());