ssacher-tgm / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

@Captor annotation might lead to NPE during autounboxing when capturing primitives #188

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Say I have a
@Captor ArgumentCaptor<Double> fooCaptor;

I'd like to have it capture primitive double arguments, but the annotation
gives me an Object captor.

Unfortunately this also fails in a non-obvious way. I get a
NullPointerException because fooCaptor.capture() returns an Object, which
obviously cannot be unboxed to a double.

It might be nice if @Captor had an optional parameter for specifying the
class. This would make one say the type twice in these cases (curse you,
erasure!), but otherwise one would be forced to remove the @Captor
annotation, which I'd personally consider even more ugly.

Original issue reported on code.google.com by martin.p...@gmail.com on 12 May 2010 at 9:25

GoogleCodeExporter commented 8 years ago
Looks like there was already some discussion about autoboxing in issue 99.

Original comment by martin.p...@gmail.com on 12 May 2010 at 9:41

GoogleCodeExporter commented 8 years ago
Hey,

The problem you described is fixable. I can defer parametrized type using 
reflection
and create captor for the right type. This means no more NPE at autounboxing.

Thanks a lot for reporting!

Original comment by szcze...@gmail.com on 16 May 2010 at 2:53

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 16 May 2010 at 4:20

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r1981.

Original comment by szcze...@gmail.com on 16 May 2010 at 4:20

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 24 May 2010 at 7:58