Thoppan / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

DeepCloner changes null array elements to XStream Mapper$Null. #472

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I cannot use the PowerMockAgent workaround because I absolutely must suppress 
static initialization on some classes.

What steps will reproduce the problem?

Run test at bottom of report.

Alternatively,

1. Create an object with an array field.
2. Inside the array field, have a null.
3. Use DeepCloner.clone to copy the object.

What is the expected output? What do you see instead?

Both tests should pass. Instead, the first test passes and second test fails 
with an Illegal Argument Exception: type mismatch.

Null items in arrays should be cloned as nulls. Instead, null items in arrays 
are cloned as type Mapper$Null.

What version of the product are you using? On what operating system?

PowerMock 1.5.1 (Mockito, XStream, JUnit4 Rule)
JUnitParams 1.0.2
XStream 1.4.6
JUnit 4.11
Windows 7

Please provide any additional information below.

Problem is caused by org.powermock.classloading.DeepCloner.clone changing null 
into XStream Mapper$Null.

For attached example:

org.powermock.classloading.ClassloaderExecutor [line 89]

Before cloning, instance.this$0.fNext.params[1] is null.

After cloning, objectLoadedWithClassloader.this$0.fNext.params[1] is an object 
of type com.thoughtworks.xstream.mapper.Mapper$Null.

The specific reason why this is a problem for me is because it is causing 
parametrized tests using JUnitParams to fail because of type errors.

----------------------------------

import static junitparams.JUnitParamsRunner.$;
import static org.junit.Assert.assertTrue;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.rule.PowerMockRule;

@PowerMockIgnore( { "junitparams.*" })
@RunWith(JUnitParamsRunner.class)
public class NullParameterTest {

    // commenting out this rule causes both tests to pass as expected
    @Rule
    public PowerMockRule rule = new PowerMockRule();

    @Test
    @Parameters
    public void testNullParameters(final Long paramA, final Long paramB) {
        assertTrue(true);
    }

    public Object[] parametersForTestNullParameters() {
        return $($(1L, 1L), $(1L, null));
    }
}

Original issue reported on code.google.com by ke.mi....@gmail.com on 18 Dec 2013 at 8:15