java.lang.VerifyError:使用PowerMockRunner

时间:2016-06-05 05:50:42

标签: java java-8 powermock verifyerror mrunit

我在项目中将MRUnit版本升级到1.1.0,使用ReduceDriver测试多个输出。在对我的测试进行更改(使其与升级一起使用)之后,我收到此错误:

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)

我的测试看起来像这样(故意删除代码以使其更简洁):

@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();
   }
}

我使用@PrepareForTest时出错。请注意, myReducer 类没有静态或最终方法。这就是为什么它不包含在@PrepareForTest注释中。我的pom文件的一部分(我使用maven进行构建)看起来像这样:

    <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>

另请注意,我使用的是Java 8,并且无法降级到v7或v6,如下所述:java.lang.VerifyError: Expecting a stackmap frame at branch target

我还尝试在pom文件中添加surefire插件,如下所述: java.lang.VerifyError: Expecting a stackmap frame at branch target 73

在这种情况下,这些解决方案都不起作用。

3 个答案:

答案 0 :(得分:0)

我有类似的问题,发现此链接: https://github.com/jayway/powermock/issues/375

MRunit 1.1.0使用PowerMock 1.5.1。它使用JavaAssist 3.18.0-GA JavaAssist 3.18.2-GA包含verifyError的修复程序。

排除MRUnit中旧的PowerMock依赖关系,并将其替换为PowerMock 1.5.5或更高版本。这些PowerMock版本包含固定的JavaAssist版本。

    <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>

答案 1 :(得分:0)

也许您可以选中此issue。在我的情况下,请更改为可用的最新版本。现在,我的版本为2.0.7

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

答案 2 :(得分:-2)

作为临时修复,您可以将 -noverify 添加到JVM参数中。不要在任何版本中使用它。