Closed GoogleCodeExporter closed 8 years ago
For the reference I'm putting informations that have been exchanged behind the
scene.
The issue lies in "initMocks" which is using hash based collections. And
hashCode & equals are final in Charset's class, that explains why there is an
NPE.
Workaround is to not use the @Mock annotation in this very specific case. But
rather
public MyTest {
private Charset mockedCharset = mock(Charset.class);
}
More generally the future reader shall pay attention to similar use cases for
final hashCode & equals method.
Charset charset = mock(Charset.class); // ok
Sets.newHashSet(charset); // <!-- NPE raised on hashCode
Lists.newArrayList(Charset.defaultCharset()).contains(charset); // NPE raised
on equals
@David, I can patch it this week-end. Solution is fairly simple with a mock
hash safe collection
Original comment by brice.du...@gmail.com
on 10 Mar 2012 at 1:10
Couldn't resist to fix it :
revision 2a373dc755b4
Original comment by brice.du...@gmail.com
on 11 Mar 2012 at 1:28
Cool :)
Original comment by szcze...@gmail.com
on 11 Mar 2012 at 5:38
Brice - My client has asked me to pass on his thanks.
Original comment by dmwallace.nz
on 11 Mar 2012 at 8:17
A bug is a bug, and I'm on fire these days ;)
Original comment by brice.du...@gmail.com
on 11 Mar 2012 at 9:11
Plus I want this release out :P
Original comment by brice.du...@gmail.com
on 11 Mar 2012 at 9:11
Issue 328 has been merged into this issue.
Original comment by brice.du...@gmail.com
on 15 Mar 2012 at 11:55
Original comment by szcze...@gmail.com
on 13 May 2012 at 3:37
Original comment by szcze...@gmail.com
on 3 Jun 2012 at 2:06
Original comment by brice.du...@gmail.com
on 3 Sep 2012 at 10:00
Original issue reported on code.google.com by
dmwallace.nz
on 10 Mar 2012 at 2:41