Skip to content

Conversation

mjsax
Copy link
Member

@mjsax mjsax commented Aug 28, 2025

Suppress build warning.

Reviewers: TengYao Chi [email protected], Ken Huang
[email protected], Chia-Ping Tsai [email protected]

@mjsax mjsax added streams tests Test fixes (including flaky tests) labels Aug 28, 2025
@github-actions github-actions bot added the small Small PRs label Aug 28, 2025
@@ -1978,7 +1978,7 @@ public ProductionExceptionHandlerResponse handle(final ErrorHandlerContext conte
assertNull(sourceRawData[1]);
}


@SuppressWarnings("unchecked")
Copy link
Member

Choose a reason for hiding this comment

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

Excuse me, which one requires this suppression? My IDE says the suppression is redundant :(

螢幕快照 2025-08-28 15-31-32

Copy link
Contributor

Choose a reason for hiding this comment

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

My build report has a warning:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I get your point.
It seems L1988 has already suppressed the warning.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm... I did see a gradle build warning -- I am pretty sure. But now I cannot reproduce it. 🤷

Will revert this. Found some other necessary cleanup though...

@github-actions github-actions bot added core Kafka Broker KIP-932 Queues for Kafka build Gradle build or GitHub Actions labels Aug 28, 2025
@mjsax mjsax force-pushed the minor-suppress-warning branch from 8757a09 to 7f6f7ba Compare August 28, 2025 17:54
@mjsax
Copy link
Member Author

mjsax commented Aug 28, 2025

Still seeing, but IntelliJ does not highlight anything, and I cannot spot the issue.

> Task :server:compileTestJava
Note: /Users/matthiassax/IdeaProjects/kafka/server/src/test/java/org/apache/kafka/server/quota/ClientQuotasRequestTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Copy link
Member

@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.

Still seeing, but IntelliJ does not highlight anything, and I cannot spot the issue.

> Task :server:compileTestJava
/home/chia7712/project/kafka/server/src/test/java/org/apache/kafka/server/quota/ClientQuotasRequestTest.java:499: warning: [unchecked] unchecked method invocation: method ofEntries in interface Map is applied to given types
            Map<Object, Object> expectedMatchesMap = Map.ofEntries(expectedMatches.toArray(new Map.Entry[0]));
                                                                  ^
  required: Entry<? extends K,? extends V>[]
  found:    Entry[]
  where K,V are type-variables:
    K extends Object declared in method <K,V>ofEntries(Entry<? extends K,? extends V>...)
    V extends Object declared in method <K,V>ofEntries(Entry<? extends K,? extends V>...)
/home/chia7712/project/kafka/server/src/test/java/org/apache/kafka/server/quota/ClientQuotasRequestTest.java:499: warning: [unchecked] unchecked conversion
            Map<Object, Object> expectedMatchesMap = Map.ofEntries(expectedMatches.toArray(new Map.Entry[0]));
                                                                  ^
  required: Map<Object,Object>
  found:    Map
2 warnings

Following my other comment, we can reproduce the warning above.

build.gradle Outdated
@@ -740,6 +740,7 @@ subprojects {
// For more details, refer to https://github.com/gradle/gradle/issues/13762.
// As a result, we need to explicitly configure the Scala compiler with this setting.
options.compilerArgs += ["--release", String.valueOf(releaseVersion)]
options.compilerArgs += ["-Xlint:unchecked"]
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps -Xlint:unchecked should be added at line 127 so that all warnings are visible.

    if (name in ["compileTestJava", "compileTestScala"]) {
      options.compilerArgs << "-parameters"
      options.compilerArgs << "-Xlint:unchecked"
    }

@mjsax
Copy link
Member Author

mjsax commented Aug 28, 2025

I still don't get this output... Not sure why 🤷

assertEquals(props.getProperty("my.empty.property"), "", "Value of a key with missing value should be an empty string");
assertEquals(props.getProperty("my.empty.property1"), "", "Value of a key with missing value with no delimiter should be an empty string");
assertEquals("", props.getProperty("my.empty.property"), "Value of a key with missing value should be an empty string");
assertEquals("", props.getProperty("my.empty.property1"), "Value of a key with missing value with no delimiter should be an empty string");
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixing incorrect order for expected vs actual value.

@chia7712
Copy link
Member

I still don't get this output... Not sure why

That’s strange. I tested JDK 17, 21, and 24 according to this comment, and all of them printed the unchecked warnings.

The following outputs were generated on my local setup. Since -Xlint:unchecked is not enabled for test code by default, it’s not necessary to fix all of them in this PR. Just FYI.

> Task :server-common:compileTestJava
/home/jenkins/kafka/server-common/src/test/java/org/apache/kafka/server/util/CommandLineUtilsTest.java:276: warning: [unchecked] unchecked conversion
        OptionSpec<String> spec = mock(OptionSpec.class);
                                      ^
  required: OptionSpec<String>
  found:    OptionSpec
1 warning

> Task :metadata:compileTestJava
/home/jenkins/kafka/metadata/src/test/java/org/apache/kafka/controller/metrics/ControllerMetadataMetricsTest.java:171: warning: [unchecked] unchecked cast
            Gauge<Integer> registrationState = (Gauge<Integer>) registry.allMetrics().get(name);
                                                                                         ^
  required: Gauge<Integer>
  found:    Metric
/home/jenkins/kafka/metadata/src/test/java/org/apache/kafka/controller/metrics/QuorumControllerMetricsTest.java:176: warning: [unchecked] unchecked cast
            Gauge<Integer> timeSinceLastHeartbeatReceivedMs = (Gauge<Integer>) registry.allMetrics().get(metricName("KafkaController", "TimeSinceLastHeartbeatReceivedMs", "broker=1"));
                                                                                                        ^
  required: Gauge<Integer>
  found:    Metric
2 warnings

> Task :streams:compileTestJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :server:compileTestJava
/home/jenkins/kafka/server/src/test/java/org/apache/kafka/server/quota/ClientQuotasRequestTest.java:499: warning: [unchecked] unchecked method invocation: method ofEntries in interface Map is applied to given types
            Map<Object, Object> expectedMatchesMap = Map.ofEntries(expectedMatches.toArray(new Map.Entry[0]));
                                                                  ^
  required: Entry<? extends K,? extends V>[]
  found:    Entry[]
  where K,V are type-variables:
    K extends Object declared in method <K,V>ofEntries(Entry<? extends K,? extends V>...)
    V extends Object declared in method <K,V>ofEntries(Entry<? extends K,? extends V>...)
/home/jenkins/kafka/server/src/test/java/org/apache/kafka/server/quota/ClientQuotasRequestTest.java:499: warning: [unchecked] unchecked conversion
            Map<Object, Object> expectedMatchesMap = Map.ofEntries(expectedMatches.toArray(new Map.Entry[0]));
                                                                                          ^
  required: Entry<? extends K,? extends V>[]
  found:    Entry[]
  where K,V are type-variables:
    K extends Object declared in method <K,V>ofEntries(Entry<? extends K,? extends V>...)
    V extends Object declared in method <K,V>ofEntries(Entry<? extends K,? extends V>...)
/home/jenkins/kafka/server/src/test/java/org/apache/kafka/server/quota/ClientQuotasRequestTest.java:499: warning: [unchecked] unchecked conversion
            Map<Object, Object> expectedMatchesMap = Map.ofEntries(expectedMatches.toArray(new Map.Entry[0]));
                                                                  ^
  required: Map<Object,Object>
  found:    Map
3 warnings

> Task :connect:runtime:compileTestJava
/home/jenkins/kafka/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerTestUtils.java:174: warning: [unchecked] unchecked conversion
        Transformation<R> transformation = mock(Transformation.class);
                                               ^
  required: Transformation<R>
  found:    Transformation
  where R,T are type-variables:
    R extends ConnectRecord<R> declared in method <T,R>getTransformationChain(RetryWithToleranceOperator<T>,List<Object>)
    T extends Object declared in method <T,R>getTransformationChain(RetryWithToleranceOperator<T>,List<Object>)
/home/jenkins/kafka/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerTestUtils.java:180: warning: [unchecked] unchecked cast
                stub = stub.thenReturn((R) result);
                                           ^
  required: R
  found:    Object
  where R,T are type-variables:
    R extends ConnectRecord<R> declared in method <T,R>getTransformationChain(RetryWithToleranceOperator<T>,List<Object>)
    T extends Object declared in method <T,R>getTransformationChain(RetryWithToleranceOperator<T>,List<Object>)
/home/jenkins/kafka/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:196: warning: [unchecked] unchecked method invocation: method createTask in class WorkerSinkTaskTest is applied to given types
        createTask(initialState, keyConverter, valueConverter, headerConverter, toleranceOperator, List::of, transformationChain);
                  ^
  required: TargetState,Converter,Converter,HeaderConverter,RetryWithToleranceOperator<ConsumerRecord<byte[],byte[]>>,Supplier<List<ErrorReporter<ConsumerRecord<byte[],byte[]>>>>,TransformationChain<ConsumerRecord<byte[],byte[]>,SinkRecord>
  found:    TargetState,Converter,Converter,HeaderConverter,RetryWithToleranceOperator,Supplier<List<ErrorReporter<ConsumerRecord<byte[],byte[]>>>>,TransformationChain
/home/jenkins/kafka/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:196: warning: [unchecked] unchecked conversion
        createTask(initialState, keyConverter, valueConverter, headerConverter, toleranceOperator, List::of, transformationChain);
                                                                                ^
  required: RetryWithToleranceOperator<ConsumerRecord<byte[],byte[]>>
  found:    RetryWithToleranceOperator
/home/jenkins/kafka/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:196: warning: [unchecked] unchecked conversion
        createTask(initialState, keyConverter, valueConverter, headerConverter, toleranceOperator, List::of, transformationChain);
                                                                                                             ^
  required: TransformationChain<ConsumerRecord<byte[],byte[]>,SinkRecord>
  found:    TransformationChain
/home/jenkins/kafka/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:1531: warning: [unchecked] unchecked method invocation: method forClass in class ArgumentCaptor is applied to given types
        ArgumentCaptor<Collection<TopicPartition>> closeCaptor = ArgumentCaptor.forClass(Collection.class);
                                                                                        ^
  required: Class<S>
  found:    Class<Collection>
  where S,U are type-variables:
    S extends U declared in method <U,S>forClass(Class<S>)
    U extends Object declared in method <U,S>forClass(Class<S>)
/home/jenkins/kafka/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/WorkerSinkTaskTest.java:1531: warning: [unchecked] unchecked conversion
        ArgumentCaptor<Collection<TopicPartition>> closeCaptor = ArgumentCaptor.forClass(Collection.class);
                                                                                        ^
  required: ArgumentCaptor<Collection<TopicPartition>>
  found:    ArgumentCaptor
7 warnings

> Task :core:compileTestScala
[Warn] /home/jenkins/kafka/core/src/test/java/kafka/server/share/SharePartitionManagerTest.java:3247:  [unchecked] unchecked cast
[Warn] /home/jenkins/kafka/core/src/test/java/kafka/server/share/DelayedShareFetchTest.java:1319:  [unchecked] unchecked method invocation: method thenReturn in interface OngoingStubbing is applied to given types
[Warn] /home/jenkins/kafka/core/src/test/java/kafka/server/share/DelayedShareFetchTest.java:1319:  [unchecked] unchecked conversion
[Warn] /home/jenkins/kafka/core/src/test/java/kafka/server/share/DelayedShareFetchTest.java:1463:  [unchecked] unchecked conversion
[Warn] /home/jenkins/kafka/core/src/test/java/kafka/server/share/DelayedShareFetchTest.java:1557:  [unchecked] unchecked conversion
[Warn] /home/jenkins/kafka/core/src/test/java/kafka/server/share/DelayedShareFetchTest.java:2204:  [unchecked] unchecked conversion
[Warn] /home/jenkins/kafka/core/src/test/java/kafka/server/share/SharePartitionTest.java:8011:  [unchecked] unchecked method invocation: method thenReturn in interface OngoingStubbing is applied to given types
[Warn] /home/jenkins/kafka/core/src/test/java/kafka/server/share/SharePartitionTest.java:8011:  [unchecked] unchecked conversion

> Task :storage:compileTestJava
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/metadata/storage/TopicBasedRemoteLogMetadataManagerTest.java:114: warning: [unchecked] unchecked conversion
        KafkaFuture<TopicDescription> mockFuture = mock(KafkaFuture.class);
                                                       ^
  required: KafkaFuture<TopicDescription>
  found:    KafkaFuture
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java:386: warning: [unchecked] unchecked method invocation: method forClass in class ArgumentCaptor is applied to given types
        ArgumentCaptor<Map<String, Object>> capture = ArgumentCaptor.forClass(Map.class);
                                                                             ^
  required: Class<S>
  found:    Class<Map>
  where S,U are type-variables:
    S extends U declared in method <U,S>forClass(Class<S>)
    U extends Object declared in method <U,S>forClass(Class<S>)
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java:386: warning: [unchecked] unchecked conversion
        ArgumentCaptor<Map<String, Object>> capture = ArgumentCaptor.forClass(Map.class);
                                                                             ^
  required: ArgumentCaptor<Map<String,Object>>
  found:    ArgumentCaptor
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java:422: warning: [unchecked] unchecked method invocation: method forClass in class ArgumentCaptor is applied to given types
            ArgumentCaptor<Map<String, Object>> capture = ArgumentCaptor.forClass(Map.class);
                                                                                 ^
  required: Class<S>
  found:    Class<Map>
  where S,U are type-variables:
    S extends U declared in method <U,S>forClass(Class<S>)
    U extends Object declared in method <U,S>forClass(Class<S>)
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java:422: warning: [unchecked] unchecked conversion
            ArgumentCaptor<Map<String, Object>> capture = ArgumentCaptor.forClass(Map.class);
                                                                                 ^
  required: ArgumentCaptor<Map<String,Object>>
  found:    ArgumentCaptor
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java:435: warning: [unchecked] unchecked method invocation: method forClass in class ArgumentCaptor is applied to given types
        ArgumentCaptor<Map<String, Object>> capture = ArgumentCaptor.forClass(Map.class);
                                                                             ^
  required: Class<S>
  found:    Class<Map>
  where S,U are type-variables:
    S extends U declared in method <U,S>forClass(Class<S>)
    U extends Object declared in method <U,S>forClass(Class<S>)
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java:435: warning: [unchecked] unchecked conversion
        ArgumentCaptor<Map<String, Object>> capture = ArgumentCaptor.forClass(Map.class);
                                                                             ^
  required: ArgumentCaptor<Map<String,Object>>
  found:    ArgumentCaptor
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java:2077: warning: [unchecked] unchecked conversion
            new Supplier[]{
            ^
  required: Supplier<RetentionSizeData>[]
  found:    Supplier[]
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java:2093: warning: [unchecked] unchecked conversion
            new Supplier[] {
            ^
  required: Supplier<RetentionTimeData>[]
  found:    Supplier[]
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java:3689: warning: [unchecked] unchecked generic array creation for varargs parameter of type INT#1[]
        clearInvocations(remoteLogMetadataManager, remoteStorageManager);
                        ^
  where INT#1 is an intersection type:
    INT#1 extends Object,Closeable,Configurable
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogReaderTest.java:63: warning: [unchecked] unchecked method invocation: method time in class Timer is applied to given types
        when(timer.time(any(Callable.class))).thenAnswer(ans -> ans.getArgument(0, Callable.class).call());
                       ^
  required: Callable<T>
  found:    Callable
  where T is a type-variable:
    T extends Object declared in method <T>time(Callable<T>)
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogReaderTest.java:63: warning: [unchecked] unchecked conversion
        when(timer.time(any(Callable.class))).thenAnswer(ans -> ans.getArgument(0, Callable.class).call());
                           ^
  required: Callable<T>
  found:    Callable
  where T is a type-variable:
    T extends Object declared in method <T>time(Callable<T>)
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogReaderTest.java:72: warning: [unchecked] unchecked conversion
        Consumer<RemoteLogReadResult> callback = mock(Consumer.class);
                                                     ^
  required: Consumer<RemoteLogReadResult>
  found:    Consumer
/home/jenkins/kafka/storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogReaderTest.java:105: warning: [unchecked] unchecked conversion
        Consumer<RemoteLogReadResult> callback = mock(Consumer.class);
                                                     ^
  required: Consumer<RemoteLogReadResult>
  found:    Consumer

> Task :clients:clients-integration-tests:compileTestJava
/home/jenkins/kafka/clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/ClientsTestUtils.java:314: warning: [unchecked] unchecked call to RetryCommitCallback(Consumer<K,V>,Optional<Map<TopicPartition,OffsetAndMetadata>>) as a member of the raw type RetryCommitCallback
        var commitCallback = new RetryCommitCallback(consumer, offsetsOpt);
                             ^
  where K,V are type-variables:
    K extends Object declared in class RetryCommitCallback
    V extends Object declared in class RetryCommitCallback
/home/jenkins/kafka/clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/MetricsDuringTopicCreationDeletionTest.java:144: warning: [unchecked] unchecked cast
            .map(entry -> (Gauge<Integer>) entry.getValue())
                                                         ^
  required: Gauge<Integer>
  found:    Metric
/home/jenkins/kafka/clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/ClientTelemetryTest.java:131: warning: [unchecked] unchecked generic array creation for varargs parameter of type List<String>[]
            ConfigCommand.ConfigCommandOptions addOpts = new ConfigCommand.ConfigCommandOptions(toArray(alterOpts));
                                                                                                       ^
/home/jenkins/kafka/clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/ClientTelemetryTest.java:155: warning: [unchecked] Possible heap pollution from parameterized vararg type List<String>
    private static String[] toArray(List<String>... lists) {
                                                    ^
4 warnings

@github-actions github-actions bot added connect kraft storage Pull requests that target the storage module tiered-storage Related to the Tiered Storage feature clients labels Aug 29, 2025
Copy link
Member

@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.

@mjsax thanks for this patch. not all warnings are fixed but it looks good enough. I just have one small comment left

build.gradle Outdated
@@ -3362,6 +3362,7 @@ project(':jmh-benchmarks') {
tasks.withType(JavaCompile) {
// Suppress warning caused by code generated by jmh: `warning: [cast] redundant cast to long`
options.compilerArgs << "-Xlint:-cast"
options.compilerArgs << "-Xlint:unchecked"
Copy link
Member

Choose a reason for hiding this comment

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

This should be included by -Xlint:all, right?

https://github.com/apache/kafka/blob/trunk/build.gradle#L129

Copy link
Member Author

Choose a reason for hiding this comment

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

Happy to remove it -- it seems something is off with my local setup -- I don't see the full warn output as you do, and adding this flag did make a difference for me... so 🤷

@mjsax mjsax merged commit 342a8e6 into apache:trunk Sep 1, 2025
23 checks passed
@mjsax mjsax deleted the minor-suppress-warning branch September 1, 2025 18:12
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 clients connect core Kafka Broker KIP-932 Queues for Kafka kraft small Small PRs storage Pull requests that target the storage module streams tests Test fixes (including flaky tests) tiered-storage Related to the Tiered Storage feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants