Using PowerMock throws java.lang.VerifyError exception

The following is an exception at runtime:

import com.sun.net.httpserver.HttpServer;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import java.net.InetSocketAddress;

@RunWith(PowerMockRunner.class)
public class MainTest {
    @org.junit.Test
    public void main() throws Exception {
        HttpServer.create(new InetSocketAddress(8080), 0);
    }
}

An exception:

java.lang.VerifyError: Bad type on the operand stack Exception Details: Location: com / sun / network / httpserver / spi / HttpServerProvider $ 1.run () Ljava / languages ​​/ object; @ 27: invokestatic Reason: Type "sun / net / httpserver / DefaultHttpServerProvider" (current frame, stack [0]) could not be assigned "com / sun / net / httpserver / spi / HttpServerProvider Current frame: bci: @ 27 flags : {} locals: {'com / sun / net / httpserver / spi / HttpServerProvider $ 1'} stack: {'sun / net / httpserver / DefaultHttpServerProvider'} Bytecode: 0x0000000: b800 2599 0007 b800 27b0 b800 2699 0007 0x0000010: b800 27b0 bb00 1b59 b700 2ab8 0028 57b8 0x0000020: 0027 b0
 Stop card table: same_frame (@ 10) same_frame (@ 20)

com.sun.net.httpserver.spi.HttpServerProvider.provider(HttpServerProvider.java:165)   at com.sun.net.httpserver.HttpServer.create(HttpServer.java:129)    HelloWorldByHour.main(HelloWorldByHour.java:16)    HelloWorldByHourTest.testMain(HelloWorldByHourTest.java:37)   at sun.reflect.NativeMethodAccessorImpl.invoke0 ( )   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    java.lang.reflect.Method.invoke(Method.java:498)    org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)    org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl $PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)    org.junit.internal.runners.MethodRoadie $2.run(MethodRoadie.java:86)    org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94)    org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl $PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)    org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl $PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)    org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)    org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)    org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)    org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)    org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl $1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)    org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)    org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)    org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122)    org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106)    org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)    org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)    org.junit.runner.JUnitCore.run(JUnitCore.java:159)   at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)   at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)   at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)   at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>testPowerMock</groupId>
    <artifactId>testPowerMock</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>(whatever version is current)</version>
                <configuration>
                    <!-- or whatever version you use -->
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.6.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-core</artifactId>
            <version>1.6.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.6.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

, - PowerMock, @RunWith(PowerMockRunner.class) "" .

, ?

+4
1

Java 7, StackMap "-XX: -UseSplitVerifier" JVM.

0

Source: https://habr.com/ru/post/1648465/


All Articles