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

ClassCastException on attempt to get bootstrap server from SenderOption/ReceiverOptions #374

Closed
ajax-osadchuk-r opened this issue Dec 8, 2023 · 3 comments · Fixed by #376
Labels
type/bug A general bug
Milestone

Comments

@ajax-osadchuk-r
Copy link

ajax-osadchuk-r commented Dec 8, 2023

Expected Behavior

SenderOptions#bootstrapServers and ReceiverOptions#bootstrapServers should sucessffully return bootstrap.servers config property value

Actual Behavior

SenderOptions#bootstrapServers and ReceiverOptions#bootstrapServers throw next ClassCastException:

java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.String (java.util.ArrayList and java.lang.String are in module java.base of loader 'bootstrap')
        at reactor.kafka.sender.SenderOptions.bootstrapServers(SenderOptions.java:289)
        
//------------------------------------------------------------------------------------------------------------------

java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.String (java.util.ArrayList and java.lang.String are in module java.base of loader 'bootstrap')
        at reactor.kafka.receiver.ReceiverOptions.bootstrapServers(ReceiverOptions.java:573)        

that is because SenderOptions#producerProperty returns an instance of Object class, in case of BOOTSTRAP_SERVERS_CONFIG it is an object of List and it can not be casted to a String
image

Steps to Reproduce

@Test
void reproCase() {
        var kafkaProps =  new KafkaProperties();
        var senderOptions = SenderOptions.create(kafkaProps.buildProducerProperties());
        assertThrows(ClassCastException.class, senderOptions::bootstrapServers);

        var receiverOptions = ReceiverOptions.create(kafkaProps.buildConsumerProperties());
        assertThrows(ClassCastException.class, receiverOptions::bootstrapServers);
}

Possible Solution

Your Environment

  • Reactor version(s) used: reactor-kafka:1.3.22, reactor-core:3.5.12
  • Other relevant libraries versions (eg. netty, ...):
  • JVM version (java -version): 18
  • OS and version (eg uname -a): MacOS 13.4
@reactorbot reactorbot added the ❓need-triage This issue needs triage, hasn't been looked at by a team member yet label Dec 8, 2023
@sanderino666
Copy link

As a workaround, I did this:

Map<String, Object> props = kafkaProperties.buildProducerProperties(null);

//reactor-kafka 1.3.22 casts the given bootstrap servers arraylist to a string and throws a class cast exception
//https://github.com/reactor/reactor-kafka/issues/374
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, String.join(",", kafkaProperties.getProducer().getBootstrapServers()));

SenderOptions<String, CloudEvent> senderOptions = SenderOptions.create(props);
...

This is an example for the producer side, the same holds for the consumer side.

kafkaProperties is the org.springframework.boot.autoconfigure.kafka.KafkaProperties coming from the Spring Boot Kafka autoconfiguration.

@ajax-osadchuk-r
Copy link
Author

ajax-osadchuk-r commented Dec 14, 2023

As a workaround, I did this:

Map<String, Object> props = kafkaProperties.buildProducerProperties(null);

//reactor-kafka 1.3.22 casts the given bootstrap servers arraylist to a string and throws a class cast exception
//https://github.com/reactor/reactor-kafka/issues/374
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, String.join(",", kafkaProperties.getProducer().getBootstrapServers()));

SenderOptions<String, CloudEvent> senderOptions = SenderOptions.create(props);
...

This is an example for the producer side, the same holds for the consumer side.

kafkaProperties is the org.springframework.boot.autoconfigure.kafka.KafkaProperties coming from the Spring Boot Kafka autoconfiguration.

Yes, a have also used such workaround, it works.

@emmanuelsilva
Copy link
Contributor

Hey all, I also came across this class cast exception when using Spring Boot. I opened the merge request #376 to fix it in the library. Let's see how it goes.

@artembilan artembilan added this to the 1.3.23 milestone Jan 3, 2024
@artembilan artembilan added type/bug A general bug and removed ❓need-triage This issue needs triage, hasn't been looked at by a team member yet labels Jan 3, 2024
artembilan pushed a commit that referenced this issue Jan 10, 2024
Resolves #374

* support read bootstrap server config when it is defined as list

* update copyright year of the affected classes to 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug A general bug
Projects
None yet
5 participants