Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Benjamin
@bdparrish
Error:(113, 70) java: method toBinary in class com.twitter.bijection.avro.SpecificAvroCodecs cannot be applied to given types;
required: scala.reflect.ClassTag<T>
found: scala.reflect.ClassTag<T>
reason: inference variable T has incompatible bounds
equality constraints: T
upper bounds: org.apache.avro.specific.SpecificRecordBase
P. Oscar Boykin
@johnynek
all, well just cast it do:
Class<org.apache.avro.specific.SpecificRecordBase>
rather than Class<T> I think
I mean, it is on you that cast is safe.
Benjamin
@bdparrish
yeah, i have Subscriber<T extends SpecificRecordBase>
so the cast will be safe
@johnynek: still doesn't like it
Error:(114, 70) java: method toBinary in class com.twitter.bijection.avro.SpecificAvroCodecs cannot be applied to given types;
required: scala.reflect.ClassTag<T>
found: java.lang.Class<org.apache.avro.specific.SpecificRecordBase>
reason: cannot infer type-variable(s) T
(argument mismatch; java.lang.Class<org.apache.avro.specific.SpecificRecordBase> cannot be converted to scala.reflect.ClassTag<T>)
P. Oscar Boykin
@johnynek
can you post a whole gist?
Benjamin
@bdparrish
of the class?
P. Oscar Boykin
@johnynek
did you change this like: final ClassTag<T> classTag
that still says T
Benjamin
@bdparrish
ahh, got it
T has to be changed on all 3
thanks
P. Oscar Boykin
@johnynek
@bdparrish let me know when it compiles and works for you
Benjamin
@bdparrish
it worked :+1:
@johnynek
P. Oscar Boykin
@johnynek
:)
Benjamin
@bdparrish
@johnynek: getting when picking up the messages off of Kafka
Exception in thread "main" java.lang.InstantiationException
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at com.twitter.bijection.avro.SpecificAvroCodecs$.toBinary(AvroCodecs.scala:106)
    at com.twitter.bijection.avro.SpecificAvroCodecs.toBinary(AvroCodecs.scala)
final ClassTag<SpecificRecordBase> classTag = ClassTag$.MODULE$.apply(SpecificRecordBase.class);

Injection<SpecificRecordBase, byte[]> binaryInjection = SpecificAvroCodecs.toBinary(classTag);
P. Oscar Boykin
@johnynek
okay, we might need the actual class of the actual type, not just SpecificRecordBase.
do you know what that type is?
Benjamin
@bdparrish
It is user defined
it is a generic
P. Oscar Boykin
@johnynek
can you take a Class<T extends SpecificRecordBase> to this function?
as an arg?
Benjamin
@bdparrish
it already does
that was throwing this...
P. Oscar Boykin
@johnynek
can you pass that to ClassTag$.MODULE$.apply( )?
Benjamin
@bdparrish
Error:(113, 70) java: method toBinary in class com.twitter.bijection.avro.SpecificAvroCodecs cannot be applied to given types;
  required: scala.reflect.ClassTag<T>
  found: scala.reflect.ClassTag<T>
  reason: inference variable T has incompatible bounds
    equality constraints: T
    upper bounds: org.apache.avro.specific.SpecificRecordBase
P. Oscar Boykin
@johnynek
can you show me the method we are dealing with (all the code)?
Benjamin
@bdparrish
Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];

final ClassTag<T> classTag = ClassTag$.MODULE$.apply(clazz);

Injection<T, byte[]> binaryInjection = SpecificAvroCodecs.toBinary(classTag);
P. Oscar Boykin
@johnynek
what is this for: Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
Benjamin
@bdparrish
public class Subscriber<T extends SpecificRecordBase> {

   // ... brevity ...

   public List<T> listen() throws Exception {
        long timeout = properties.getLong(PrConstants.PR_KAFKA_CONSUMER_POLL_TIMEOUT, 100);

        List<T> records = new ArrayList<>();

        ConsumerRecords<byte[], byte[]> consumedRecords = consumer.poll(timeout);

        for (ConsumerRecord<byte[], byte[]> consumedRecord : consumedRecords) {
            final ClassTag<SpecificRecordBase> classTag = ClassTag$.MODULE$.apply(SpecificRecordBase.class);

            Injection<SpecificRecordBase, byte[]> binaryInjection = SpecificAvroCodecs.toBinary(classTag);

            T avro = (T) binaryInjection.invert(consumedRecord.value());

            records.add(avro);
        }

        return records;
    }
}
P. Oscar Boykin
@johnynek
I think you need:
public class Subscriber<T extends SpecificRecordBase>(Class<T> klass) …
and pass that to:
final ClassTag<T extends SpecificRecordBase> classTag = ClassTag$.MODULE$.apply(klass);
or you need to get that concrete class somehow
due to erasure, I don’t think there is anyway around a user passing it (or an instance)
(in scala, that is what ClassTag[T] does, it only works if T is not abstract or you already have a ClassTag[T] to pass)
Benjamin
@bdparrish
ok
might have to move to something else
none of that works with Java
but i get your point
P. Oscar Boykin
@johnynek
why can’t you just pass the Class<T> in?
Benjamin
@bdparrish
i can pass that in