ethrbunny
ethrbunny

Reputation: 10469

passing java properties to scala - nosuchmethod errors

I'm attempting to compile some sample code from the Kafka site. It's giving runtime errors when scala tries to read the java properties.

Error:

Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.augmentString(Ljava/lang/String;)Ljava/lang/String;
at kafka.utils.VerifiableProperties.getShortInRange(VerifiableProperties.scala:83)
at kafka.utils.VerifiableProperties.getShort(VerifiableProperties.scala:59)
at kafka.producer.SyncProducerConfigShared$class.$init$(SyncProducerConfig.scala:49)
at kafka.producer.ProducerConfig.<init>(ProducerConfig.scala:51)
at kafka.producer.ProducerConfig.<init>(ProducerConfig.scala:56)
at Test_Producer.main(Test_Producer.java:28)

Here is the code snip in question. The error is coming from the new ProducerConfig(props) statement (line 28 above).

Properties props = new Properties();

props.put("metadata.broker.list", "broker1:9092,broker2:9092");
props.put("serializer.class", "kafka.serializer.StringEncoder");
props.put("partitioner.class", "example.producer.SimplePartitioner");
props.put("request.required.acks", "1");

ProducerConfig config = new ProducerConfig(props);

I tried stepping into the code in question and it appears that all the relevant values are set (IE getProperties is finding a value).

The code builds ok but perhaps I'm using an incorrect library?

Suggestions?


Edit:

Code is running (or supposed to) in Intellij 14.

Java is 1.8 Scala libraries are 2.11.6


Another data point: If I comment out all the properties except the first one ('broker1:9092...') I get this error:

Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.augmentString(Ljava/lang/String;)Ljava/lang/String;
at kafka.producer.ProducerConfig.liftedTree1$1(ProducerConfig.scala:83)
at kafka.producer.ProducerConfig.<init>(ProducerConfig.scala:82)
at kafka.producer.ProducerConfig.<init>(ProducerConfig.scala:56)
at Test_Producer.main(Test_Producer.java:28)  

Similar - but not quite the same. Still makes me think its a library issue.

Upvotes: 1

Views: 537

Answers (1)

Shawn Guo
Shawn Guo

Reputation: 3228

Encountered this problem with below kafka POM dependency:

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka_2.9.2</artifactId>
    <version>0.8.2.0</version>
    <scope>compile</scope>
</dependency>

Error Stack:

Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.augmentString(Ljava/lang/String;)Lscala/collection/immutable/StringOps;
    at kafka.utils.VerifiableProperties.getShortInRange(VerifiableProperties.scala:85)
    at kafka.producer.SyncProducerConfigShared$class.$init$(SyncProducerConfig.scala:53)
    at kafka.producer.ProducerConfig.<init>(ProducerConfig.scala:51)
    at kafka.producer.ProducerConfig.<init>(ProducerConfig.scala:56)
    at dominus.intg.jms.kafka.KafkaProducer.main(KafkaProducer.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Upgrade to 0.8.2.1, this issue is gone.

<dependency>
   <groupId>org.apache.kafka</groupId>
   <artifactId>kafka_2.10</artifactId>
   <version>0.8.2.1</version>
   <scope>compile</scope>
</dependency>

Upvotes: 1

Related Questions