Can no longer pass null as parameter for invocations of private static methods

745 views
Skip to first unread message

Matthias Habermann

unread,
Jan 8, 2011, 5:05:58 PM1/8/11
to PowerMock
Hi,

with PowerMock 1.4.7 I'm no longer able to pass null as parameter for
invocations of private static methods, e.g. in

try {
actual = Whitebox.invokeMethod(HttpConnectionManagerImpl.class,
"createRequest", HttpConnectionManagerImpl.HttpMethod.GET,
uri, new byte[] {});
} catch (final Exception e) {
fail();
}

What I get is:

org.powermock.reflect.exceptions.MethodNotFoundException: No method
found with name 'createCompressedEntity' with parameter types:
[ null ] in class
com.bmw.b2v.cdalib.backend.HttpConnectionManagerImpl.
at
org.powermock.reflect.internal.WhiteboxImpl.throwExceptionIfMethodWasNotFound(WhiteboxImpl.java:
1273)
at
org.powermock.reflect.internal.WhiteboxImpl.findMethodOrThrowException(WhiteboxImpl.java:
1011)
at
org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:
910)
at
org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:
887)
...

Any help appreciated.

Thanks
Matthias

Johan Haleby

unread,
Jan 8, 2011, 6:00:55 PM1/8/11
to powe...@googlegroups.com
Hi,

Which parameter is "null"? The "uri"? Would it be possible for you to
create a small example demonstrating the issue?

/Johan

Matthias Habermann

unread,
Jan 8, 2011, 6:07:14 PM1/8/11
to PowerMock
> Which parameter is "null"?

Sorry, I posted the wrong example. The correct one is as follows:

try {
actual = Whitebox.invokeMethod(HttpConnectionManagerImpl.class,
"createCompressedEntity", (byte[]) null);
} catch (final Exception e) {
fail();
}

The method I'm trying to test:

private static ByteArrayEntity createCompressedEntity(byte[] data)
throws IOException {
...
}

Matthias

Johan Haleby

unread,
Jan 9, 2011, 5:41:27 AM1/9/11
to powe...@googlegroups.com
Hi,

Turns out that this was a bug introduced in 1.4.7. I've fixed it in
trunk. In the mean time try:

Whitebox.invokeMethod(HttpConnectionManagerImpl.class,"createCompressedEntity", new Object[] {null});

or

Whitebox.invokeMethod(HttpConnectionManagerImpl.class,"createCompressedEntity", new Class<?>[]{ byte[].class }, null);

Thanks for reporting,
/Johan

Reply all
Reply to author
Forward
0 new messages