简体   繁体   中英

java.lang.VerifyError: Expecting a stackmap frame at branch, when using PowerMockRunner

I upgraded the MRUnit version to 1.1.0 in my project, to use the ReduceDriver for testing multiple outputs. After making changes to my test (to make it work with the upgrade), I get this error:

java.lang.VerifyError: Expecting a stackmap frame at branch target 63
Exception Details:
Location: (path to test class)
Reason: Expected stackmap frame at this location.
Bytecode: (Bytecode)

My test looks like this (have deliberately removed code to make this more concise):

@RunWith(PowerMockRunner.class)
@PrepareForTest(MultipleOutputs.class)
public class myReducerTest {
   private ReduceDriver<Text, Text, Text, Text> reduceDriver;

   @Before
   public void setUp() {
       reduceDriver = ReduceDriver.newReduceDriver(new myReducer());
   }

   @Test
   public void testHappyPath() throws IOException {
       /*
          Code to declare input key, inout value, expected output, etc.
       */

       reduceDriver.withInput(myInputKey, myInputVal);
       reduceDriver.withMultiOutput("reportName1", key, expectedValue1);
       reduceDriver.withMultiOutput("reportName2", key, expectedValue2);
       reduceDriver.runTest();
   }
}

I get the error when I use @PrepareForTest. Note that myReducer class has no static or final methods. That is why it is not included in @PrepareForTest annotation. Part of my pom file (I am using maven for building) looks like this:

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-core</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-easymock</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.mrunit</groupId>
        <artifactId>mrunit</artifactId>
        <version>1.1.0</version>
        <classifier>hadoop2</classifier>
        <scope>test</scope>
    </dependency>

Also note that I am using Java 8, and cannot downgrade to v7 or v6 as mentioned here: java.lang.VerifyError: Expecting a stackmap frame at branch target

I also tried adding the surefire plugin in the pom file, as mentioned here: java.lang.VerifyError: Expecting a stackmap frame at branch target 73

None of these solutions work in this case.

Maybe you can check this issue . In my case, change to the latest version that worked.Now, my version is 2.0.7

<properties>
    <powermock.version>2.0.7</powermock.version>
</properties>

I had a similar problem and found this link: https://github.com/jayway/powermock/issues/375 .

MRunit 1.1.0 uses PowerMock 1.5.1. which uses JavaAssist 3.18.0-GA.
JavaAssist 3.18.2-GA contains a fix for the verifyError.

Exclude the old PowerMock dependency in MRUnit and replace it with PowerMock 1.5.5 or higher. These PowerMock versions contain the fixed JavaAssist version.

    <dependency> (all PowerMock dependencies)
        ... PowerMock dependency ...
        <version>1.5.5(or higher)</version>
    </dependency>

    <dependency>
        <groupId>org.apache.mrunit</groupId>
        <artifactId>mrunit</artifactId>
        <version>1.1.0</version>
        <exclusions>
            ...insert all PowerMock exclusions...
        </exclusions>
        <classifier>hadoop2</classifier>
        <scope>test</scope>
    </dependency>

As a temporary fix you can add -noverify to your JVM arguments. Do not use this in any release though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM