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

KAFKA-16564: Apply Xlint to java code in core module #16965

Merged
merged 20 commits into from
Oct 25, 2024

Conversation

m1a2st
Copy link
Contributor

@m1a2st m1a2st commented Aug 22, 2024

Jira: https://issues.apache.org/jira/browse/KAFKA-16564

We should apply the same xlint to java code in core module before we complete the code migration.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

build.gradle Outdated
options.compilerArgs << "-parameters"
} else if (name == "compileJava") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change compileJava to compileScala to add the args to "scala compiler"

@m1a2st m1a2st marked this pull request as ready for review September 17, 2024 05:37
@chia7712
Copy link
Contributor

chia7712 commented Oct 7, 2024

@m1a2st could you please rebase code and fix conflicts?

# Conflicts:
#	core/src/test/java/kafka/admin/ConfigCommandTest.java
@github-actions github-actions bot added core Kafka Broker small Small PRs labels Oct 7, 2024
@m1a2st
Copy link
Contributor Author

m1a2st commented Oct 7, 2024

I have been fix it, Thanks for your reminder.

@chia7712
Copy link
Contributor

@m1a2st could you please rebase code and fix conflicts?

# Conflicts:
#	core/src/main/java/kafka/server/handlers/DescribeTopicPartitionsRequestHandler.java
@github-actions github-actions bot added the build Gradle build or GitHub Actions label Oct 15, 2024
build.gradle Outdated
options.compilerArgs << "-Xlint:-serial"
options.compilerArgs << "-Xlint:-try"
options.compilerArgs << "-Werror"
options.compilerArgs << "-Xlint:-options"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need this option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -Xlint:-options is "Warns about the issues relating to use of command line options" . doc
I think we don't need this option, I will remove it.

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m1a2st thanks for your patch

build.gradle Outdated
options.compilerArgs << "-parameters"
} else if (name == "compileScala") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please config both scala and java? for example:

    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)]
    }

@@ -119,8 +119,16 @@ ext {
addParametersForTests = { 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, addParametersForTests -> configureJavaCompiler

SecurityManager s = System.getSecurityManager();
Thread t = new Thread((s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup(), r,
Thread t = new Thread(Thread.currentThread().getThreadGroup(), r,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java 17 is deprecated the SecurityManager, see doc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use suppression to fix it? we can go back to dig in it later

@chia7712
Copy link
Contributor

@m1a2st please fix build error

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m1a2st thanks for this patch

if (!project.path.startsWith(":connect") && !project.path.startsWith(":storage"))
options.compilerArgs << "-Xlint:-rawtypes"
options.compilerArgs << "-encoding" << "UTF-8"
options.compilerArgs << "-Xlint:-rawtypes"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configureJavaCompiler also use in the tasks.withType(JavaCompile) and subprojects, it is dulpicate in the tasks.withType(JavaCompile)code block so I remove it which in tasks.withType(JavaCompile)

@@ -122,7 +122,7 @@ void testNeverExpiringX509Certificate() throws Exception {
wrappedCert.hasUnsupportedCriticalExtension());
// We have just generated a valid test certificate, it should still be valid now
assertEquals(cert.getBasicConstraints(), wrappedCert.getBasicConstraints());
assertEquals(cert.getIssuerDN(), wrappedCert.getIssuerDN());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need those changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seens this deprecated method won't cause build error, I will revert it

build.gradle Outdated
@@ -771,7 +773,7 @@ subprojects {
scalaCompileOptions.additionalParameters += ["-release", String.valueOf(minJavaVersion)]
options.compilerArgs += ["--release", String.valueOf(minJavaVersion)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please remove this duplicate config?

@chia7712 chia7712 merged commit 09d76f9 into apache:trunk Oct 25, 2024
6 checks passed
abhishekgiri23 pushed a commit to abhishekgiri23/kafka that referenced this pull request Nov 2, 2024
Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Gradle build or GitHub Actions ci-approved clients connect core Kafka Broker small Small PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants