jmockit/jmockit1

NullPointerException in test execution: Cannot invoke "java.lang.instrument.Instrumentation.retransformClasses(java.lang.Class[])" because "mockit.internal.startup.Startup.instrumentation" is null

pksilen opened this issue · 2 comments

Version of JMockit that was used:
1.49

  • Description of the problem or enhancement request:
    All tests result in same NullPointerException:

[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) @ conflated-configuration-service ---
[WARNING] The parameter forkCount should likely not be 0. Forking a JVM for tests improves test accuracy. Ensure to have a >= 1.
[INFO] Using auto detected provider org.apache.maven.surefire.testng.TestNGProvider
[INFO] Running TestSuite
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[ERROR] Tests run: 178, Failures: 116, Errors: 0, Skipped: 0, Time elapsed: 1.124 s <<< FAILURE! - in TestSuite
[ERROR] com.silensoft.conflated.configuration.service.chart.ChartServiceTests.testGetEntityStore Time elapsed: 0.013 s <<< FAILURE!
java.lang.NullPointerException: Cannot invoke "java.lang.instrument.Instrumentation.retransformClasses(java.lang.Class[])" because "mockit.internal.startup.Startup.instrumentation" is null
at java.base/java.lang.Thread.run(Thread.java:833)

  • Check the following:
  • [x ] If a defect or unexpected result, JMockit project members should be able to reproduce it.
    For that, include an example test (perhaps accompanied by a Maven/Gradle build script) which
    can be executed without changes and reproduces the failure.

Here is pom.xml configuration for Maven surefire plugin:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M6</version>
    <configuration>
        <useSystemClassLoader>false</useSystemClassLoader>
        <forkCount>0</forkCount>
        <properties>
            <property>
                <name>parallel</name>
                <value>methods</value>
            </property>
            <property>
                <name>dataproviderthreadcount</name>
                <value>10</value>
            </property>
        </properties>
        <argLine>
            @{argLine} -javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar
        </argLine>
        <excludes>
            <exclude>integrationtests/RunCucumberTests.java</exclude>
        </excludes>
    </configuration>
</plugin>

Example test:

package com.silensoft.conflated.configuration.service.chart;

import com.silensoft.conflated.configuration.service.dashboard.DashboardStore;
import mockit.Injectable;
import mockit.Tested;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

@SuppressWarnings("InstanceVariableOfConcreteClass")
public class ChartServiceTests {
    @Tested
    private ChartService chartService;

    @Injectable
    private ChartStore chartStore;

    @Injectable
    private DashboardStore dashboardStore;

    @Test
    void testGetEntityStore() {
        assertEquals(chartService.getEntityStore(), chartStore);
    }
}
  • If an enhancement or new feature request, it should be justified by an example test
    demonstrating the validity and usefulness of the desired enhancement or new feature.

  • The issue does not fall outside the scope of the project (for example, attempting to use
    JMockit APIs from Groovy or Scala code, or with an Android runtime).

  • The JDK where the problem occurs is a final release, not a development build.
    Problem occurs in JDK 8/11/17

pksilen

may I know if this issue is resolved, I got the same errors when I tried to build the project but when the unit tests are run standalone - all the test cases are running successfully without reporting any error.

Hi ,I am facing same issue.. any updates on this plz?