[
https://issues.apache.org/jira/browse/FLINK-21278?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17302417#comment-17302417
]
Yao Zhang commented on FLINK-21278:
-----------------------------------
Hi HunterHunter:
I reproduced this issue and found it cause:
In org/apache/flink/api/common/functions/util/PrintSinkOutputWriter.java:
public void write(IN record) {
stream.println(completedPrefix + record.toString());
}
The record variable here is null so NPE will be thrown.
Then I debugged the upper call stack and discovered:
org/apache/flink/streaming/api/functions/windowing/ReduceApplyWindowFunction.java
@Override
public void apply(K k, W window, Iterable<T> input, Collector<R> out) throws
Exception {
T curr = null;
for (T val: input) {
if (curr == null) {
curr = val;
} else {
curr = reduceFunction.reduce(curr, val);
}
}
wrappedFunction.apply(k, window, Collections.singletonList(curr), out);
}
The problem is here. If there were no elements in the collection input, it
would not enter the for loop. So the variable curr would end up with null
value. Then Collections.singletonList(curr) would wrap the null value in a
list. That may possibly be the root cause.
> NullpointExecption error is reported when using the evictor method to filter
> the data before the window calculation
> -------------------------------------------------------------------------------------------------------------------
>
> Key: FLINK-21278
> URL: https://issues.apache.org/jira/browse/FLINK-21278
> Project: Flink
> Issue Type: Bug
> Components: API / DataStream
> Affects Versions: 1.12.1
> Reporter: HunterHunter
> Priority: Blocker
> Labels: pull-request-available
>
> When I use evictor() method to filter the data before a window is triggered,
> if there is no data that meets the conditions, a nullpointExecption error
> will be reported.
> This problem occurs in the ReduceApplyWindowFunction.apply method.
> So I think if there is no data to calculate whether it can not trigger the
> calculation, or judge whether it is null before transmitting the calculation
> result
--
This message was sent by Atlassian Jira
(v8.3.4#803005)