Skip to content

Commit

Permalink
Fix NullPointerException after exception in data provider (#1925)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire authored Mar 20, 2024
1 parent 1c7ea7d commit a257b10
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public boolean hasNext() {
public Object[] next() {
Object[] next = delegate.next();

// delegate.next() will return null if an error occurred
if (next == null) {
return null;
}

try {
return (Object[]) invokeRaw(context.getSharedInstance(), context.getCurrentFeature().getDataProcessorMethod(), next);
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,29 @@ private int unused() {
}
'''
}

def "data provider throwing exception should not produce additional NullPointerException"() {
when:
runner.runFeatureBody '''
expect:
true
where:
a << new Iterator() {
@Override
boolean hasNext() {
return true
}
@Override
Object next() {
throw new RuntimeException('foo')
}
}
'''

then:
RuntimeException e = thrown()
e.message == 'foo'
}
}

0 comments on commit a257b10

Please sign in to comment.