The reason for this is that FlinkKafkaProducer010 is a peculiar hybrid of a 
StreamSink (a subclass of StreamOperator) and SinkFunction/RichFunction (the 
interface for user functions). The runtime context of this class is only set 
when you use it as an operator, which happens when you use 
FlinkKafkaProducer010.writeToKafkaWithTimestamps(). When used as a 
SinkFunction, i.e. DataStream.addSink() this doesn’t work.

I created an issue for resolving this in a general way: 
https://issues.apache.org/jira/browse/FLINK-6323

> On 17. Apr 2017, at 13:15, sohimankotia <sohimanko...@gmail.com> wrote:
> 
> Thanks for Reply Gordon . I am not doing any unit test . Its production code
> . 
> 
> public class MyClass extends FlinkKafkaProducer010<BasicInfoTuple>
> 
> and then
> 
> incrementCounter("items-not-found", this.getRuntimeContext());
> 
> 
> 
> --
> View this message in context: 
> http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/Why-I-am-getting-Null-pointer-exception-while-accessing-RuntimeContext-in-FlinkKafkaProducer010-tp12633p12635.html
> Sent from the Apache Flink User Mailing List archive. mailing list archive at 
> Nabble.com.

Reply via email to