Regression on 1.4 ?

7 views
Skip to first unread message

i928

unread,
Aug 5, 2010, 6:15:30 PM8/5/10
to PowerMock

I have code look like

Connection conn=null;
...
Whitebox.invokeMethod(param, "establishConnection",conn);

I get following error use powermock 1.4, but works properly under
powermock 1.3.9

java.lang.IllegalArgumentException: type cannot be null
at
org.powermock.reflect.internal.WhiteboxImpl.getUnmockedType(WhiteboxImpl.java:
1780)
at
org.powermock.reflect.internal.WhiteboxImpl.getType(WhiteboxImpl.java:
2205)
at
org.powermock.reflect.internal.WhiteboxImpl.getTypes(WhiteboxImpl.java:
1011)
at
org.powermock.reflect.internal.WhiteboxImpl.findMethodOrThrowException(WhiteboxImpl.java:
962)
at
org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:
890)
at
org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:
721)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:399)

Any suggestion how to work around this error?

Best Regards,

Chiiwen

Johan Haleby

unread,
Aug 7, 2010, 6:03:29 AM8/7/10
to powe...@googlegroups.com
Could very well be a bug introduced in 1.4 (lot's of internal changes in Whitebox). Could you provide a more complete example?

/Johan


--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To post to this group, send email to powe...@googlegroups.com.
To unsubscribe from this group, send email to powermock+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/powermock?hl=en.


i928

unread,
Aug 30, 2010, 2:19:23 PM8/30/10
to PowerMock
Hi Johan,

Here is a simple example to reproduce type cannot be null error

P2.java
----------------------
import java.sql.Connection;

public class P2 {

protected void establishConnection(Connection conn)
throws Exception
{
if (conn== null) return;
}
}


@Test
public void testestablishConnection3() throws Exception {
P2 param=createMock(P2.class);
Connection conn=null;
Whitebox.invokeMethod(param, "establishConnection", conn);
}

Best Regards,

Chiiwen


On Aug 7, 3:03 am, Johan Haleby <johan.hal...@gmail.com> wrote:
> Could very well be a bug introduced in 1.4 (lot's of internal changes in
> Whitebox). Could you provide a more complete example?
>
> /Johan
>
> > powermock+...@googlegroups.com<powermock%2Bunsu...@googlegroups.com>
> > .

Johan Haleby

unread,
Aug 31, 2010, 8:27:12 AM8/31/10
to powe...@googlegroups.com
Hi,

I cannot seem to reproduce it. I'm doing this:

public class ClassWithAMethod  {
   
    public void connect(Connection connection) {
        if(connection == null) {
            throw new IllegalArgumentException("param was null");
        }
    }
}
The test;

ClassWithAMethod classWithAMethod = new ClassWithAMethod();
Connection connection = null;
Whitebox.invokeMethod(classWithAMethod, "connect", connection);

This works for me. Do you only see this problem when you're using Whitebox to invoke a method on a mocked object? In the example you posted to me why do want to invoke the method using reflection/Whitebox? Or was that just to demonstrate the issue? If you would do partial mocking then it could make sense but now I don't see the point?!

/Johan

To unsubscribe from this group, send email to powermock+...@googlegroups.com.

i928

unread,
Aug 31, 2010, 10:36:22 AM8/31/10
to PowerMock
Hi Johan,

This simple case just to demonstrate the issue.
I use your method for one test case, but I have to use partial mock
for another test case.

Best Regards,

Chiiwen



On Aug 31, 5:27 am, Johan Haleby <johan.hal...@gmail.com> wrote:
> Hi,
>
> I cannot seem to reproduce it. I'm doing this:
>
> public class ClassWithAMethod  {
>
>     public void connect(Connection connection) {
>         if(connection == null) {
>             throw new IllegalArgumentException("param was null");
>         }
>     }}
>
> The test;
>
> ClassWithAMethod classWithAMethod = new ClassWithAMethod();
> Connection connection = null;
> Whitebox.invokeMethod(classWithAMethod, "connect", connection);
>
> This works for me. Do you only see this problem when you're using Whitebox
> to invoke a method on a mocked object? In the example you posted to me why
> do want to invoke the method using reflection/Whitebox? Or was that just to
> demonstrate the issue? If you would do partial mocking then it could make
> sense but now I don't see the point?!
>
> /Johan
>
> > <powermock%2Bunsu...@googlegroups.com<powermock%252Buns...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages