qaf icon indicating copy to clipboard operation
qaf copied to clipboard

java.lang.NoSuchFieldException: modifiers on jdk12.0.2

Open bOneKop opened this issue 5 years ago • 20 comments

QAF Version

Note: only the latest version is supported 3.0.0-RC3

Steps To Reproduce

1.maven:`<dependency>
		<groupId>com.qmetry</groupId>
		<artifactId>qaf-cucumber</artifactId>
		<version>3.0.0-RC3</version>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>com.qmetry</groupId>
		<artifactId>qaf</artifactId>
		    <version>3.0.0-RC3</version>
<scope>provided</scope>
		<exclusions>
			<exclusion>
				<groupId>com.sun.jersey</groupId>
				<artifactId>jersey-client</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.sun.jersey</groupId>
				<artifactId>jersey-core</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.sun.jersey.contribs</groupId>
				<artifactId>jersey-multipart</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.sun.jersey.contribs</groupId>
				<artifactId>jersey-apache-client</artifactId>
			</exclusion>
		</exclusions>
	</dependency>`

2.Cucumber-jvm cukerunner`@CucumberOptions(plugin = { "pretty", "html:build/reports/demo-cucumber", "json:build/cucumber/demo-cucumber.json",
	"io.qameta.allure.cucumber5jvm.AllureCucumber5Jvm",
	"com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin" }`

3.run on jdk8 no thing wrong

4.run on jdk12.0.2 there is a exceprion

5.Can we change this part:`Field modifiersField = Field.class.getDeclaredField("modifiers");`

Expected behavior

Actual behavior

16:07:15 Added "QAFMethodSelector" 16:07:15 java.lang.NoSuchFieldException: modifiers 16:07:15 at java.base/java.lang.Class.getDeclaredField(Class.java:2416) 16:07:15 at com.qmetry.qaf.automation.util.ClassUtil.setField(ClassUtil.java:599) 16:07:15 at com.qmetry.qaf.automation.testng.pro.QAFExecutionListener.(QAFExecutionListener.java:51) 16:07:15 at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 16:07:15 at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 16:07:15 at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 16:07:15 at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) 16:07:15 at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) 16:07:15 at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:781) 16:07:15 at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:723) 16:07:15 at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1395) 16:07:15 at org.testng.TestNG.addServiceLoaderListeners(TestNG.java:1017) 16:07:15 at org.testng.TestNG.initializeConfiguration(TestNG.java:966) 16:07:15 at org.testng.TestNG.run(TestNG.java:1089) 16:07:15 at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135) 16:07:15 at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass(TestNGDirectoryTestSuite.java:112) 16:07:15 at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99) 16:07:15 at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:146) 16:07:15 at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384) 16:07:15 at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345) 16:07:15 at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126) 16:07:15 at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)

Is the issue reproducible on runner?

  • [ ] QAS
  • [x] Maven
  • [ ] Gradle
  • [ ] Ant
  • [ ] Eclipse

Test case sample

Please, share the test case (as small as possible) which shows the issue

bOneKop avatar Apr 30 '20 08:04 bOneKop

Is it specific to jdk version?

cjayswal avatar Apr 30 '20 23:04 cjayswal

Is it specific to jdk version?

higher than jdk12

bOneKop avatar May 01 '20 00:05 bOneKop

Thanks for reporting. As we have to support java minimum version 8 because many of enterprises using java 8 we can't immediately provide fix for this issue.

By the way when you are using qaf-cucumber, TestNG is not required. So you can use plain cucumber runner or Junit runner and in that case you should not see above error.

cjayswal avatar May 01 '20 04:05 cjayswal

Ok, I understand. However I have tried to exclusive testng from qaf in maven, but it does have some dependence make me can not use the plugin "com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin". Is there any solution?

bOneKop avatar May 01 '20 05:05 bOneKop

This issue is version compatibility issue rather than a bug, but to get more attention in future, marked as bug.

cjayswal avatar May 01 '20 05:05 cjayswal

it's not related to excluding dependency but using runner. It looks like that you are using TestNG runner with cucumber. So instead of that you can use Junit runner and run as Junit or use cucumber runner and run as Java.

Here are few examples:

  1. Cucumber runner
  2. Junit runner

cjayswal avatar May 01 '20 05:05 cjayswal

I'm using cucumber-junit The runner is: @CucumberOptions(plugin = { "pretty", "html:build/reports/demo-cucumber", "json:build/cucumber/demo-cucumber.json", "io.qameta.allure.cucumber5jvm.AllureCucumber5Jvm", "com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin" } It seems nothing about testng but it will touch testng

bOneKop avatar May 01 '20 05:05 bOneKop

You need to fix your POM to run Junit instead of TesNG. From the exception i can see that surefire plugin is running as TestNG

16:07:15 at org.testng.TestNG.run(TestNG.java:1089) 16:07:15 at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135) 16:07:15 at

cjayswal avatar May 01 '20 05:05 cjayswal

You need to fix your POM to run Junit instead of TesNG. From the exception i can see that surefire plugin is running as TestNG

16:07:15 at org.testng.TestNG.run(TestNG.java:1089) 16:07:15 at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135) 16:07:15 at

Ok , thank you, I will check it

bOneKop avatar May 01 '20 05:05 bOneKop

You need to fix your POM to run Junit instead of TesNG. From the exception i can see that surefire plugin is running as TestNG

16:07:15 at org.testng.TestNG.run(TestNG.java:1089) 16:07:15 at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135) 16:07:15 at

Hi I just found out that I run my cucumber in maven in -Dtest=com.geetest.deepknow.runner.CukeTest test -Dcucumber.options="--tags ${tags} " It will run cucumber-junit but also surefire-testng. It will not run testng if I just use the IDE junit runner to the project, it will pass.

Any solution can I use to run the project in maven test and not to run testng?

bOneKop avatar May 06 '20 02:05 bOneKop

You need to fix your POM to run Junit instead of TesNG. From the exception i can see that surefire plugin is running as TestNG

16:07:15 at org.testng.TestNG.run(TestNG.java:1089) 16:07:15 at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135) 16:07:15 at

And I finally run without testng, However the log 14:24:13 java.lang.NoSuchFieldException: modifiers 14:24:13 at java.base/java.lang.Class.getDeclaredField(Class.java:2416) 14:24:13 at com.qmetry.qaf.automation.util.ClassUtil.setField(ClassUtil.java:599) 14:24:13 at com.qmetry.qaf.automation.cucumber.bdd2.parser.Bdd2Compiler.getExamples(Bdd2Compiler.java:200) 14:24:13 at com.qmetry.qaf.automation.cucumber.bdd2.parser.Bdd2Compiler.compileScenarioOutline(Bdd2Compiler.java:126) 14:24:13 at com.qmetry.qaf.automation.cucumber.bdd2.parser.Bdd2Compiler.compile(Bdd2Compiler.java:96) 14:24:13 at com.qmetry.qaf.automation.cucumber.bdd2.parser.BDD2FeatureParser.compilePickles(BDD2FeatureParser.java:57) 14:24:13 at com.qmetry.qaf.automation.cucumber.bdd2.parser.BDD2FeatureParser.parseBDD2(BDD2FeatureParser.java:41) 14:24:13 at com.qmetry.qaf.automation.cucumber.bdd2.parser.BDD2FeatureParser.parse(BDD2FeatureParser.java:69) 14:24:13 at io.cucumber.core.feature.FeatureParser.parseResource(FeatureParser.java:44) 14:24:13 at java.base/java.util.function.BiFunction.lambda$andThen$0(BiFunction.java:70) 14:24:13 at io.cucumber.core.resource.ResourceScanner.lambda$processResource$2(ResourceScanner.java:126) 14:24:13 at io.cucumber.core.resource.PathScanner$ResourceFileVisitor.visitFile(PathScanner.java:67) 14:24:13 at io.cucumber.core.resource.PathScanner$ResourceFileVisitor.visitFile(PathScanner.java:52) 14:24:13 at java.base/java.nio.file.Files.walkFileTree(Files.java:2801) 14:24:13 at java.base/java.nio.file.Files.walkFileTree(Files.java:2873) 14:24:13 at io.cucumber.core.resource.PathScanner.findResourcesForPath(PathScanner.java:46) 14:24:13 at io.cucumber.core.resource.PathScanner.findResourcesForUri(PathScanner.java:26) 14:24:13 at io.cucumber.core.resource.ResourceScanner.findResourcesForUri(ResourceScanner.java:109) 14:24:13 at io.cucumber.core.resource.ResourceScanner.scanForResourcesUri(ResourceScanner.java:86) 14:24:13 at io.cucumber.core.runtime.FeaturePathFeatureSupplier.loadFeatures(FeaturePathFeatureSupplier.java:61) 14:24:13 at io.cucumber.core.runtime.FeaturePathFeatureSupplier.get(FeaturePathFeatureSupplier.java:45) 14:24:13 at io.cucumber.junit.Cucumber.(Cucumber.java:156) 14:24:13 at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 14:24:13 at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 14:24:13 at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 14:24:13 at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) 14:24:13 at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) 14:24:13 at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104) 14:24:13 at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86) 14:24:13 at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) 14:24:13 at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) 14:24:13 at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) 14:24:13 at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33) 14:24:13 at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:362) 14:24:13 at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273) 14:24:13 at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238) 14:24:13 at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159) 14:24:13 at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384) 14:24:13 at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345) 14:24:13 at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126) 14:24:13 at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)

bOneKop avatar May 06 '20 06:05 bOneKop

is it blocking (exit without executing tests) or showing error and continues to run the test?

cjayswal avatar May 06 '20 21:05 cjayswal

is it blocking (exit without executing tests) or showing error and continues to run the test?

I'm using cucumber-jvm. It is blocking in one Scenario then run another Scenario then blocking.

bOneKop avatar May 07 '20 01:05 bOneKop

If my understanding is correct, all scenarios get executed. If so it means not blocking. You can ignore console log as long as scenario get executed and report has correct results.

cjayswal avatar May 07 '20 04:05 cjayswal

If my understanding is correct, all scenarios get executed. If so it means not blocking. You can ignore console log as long as scenario get executed and report has correct results.

all scenarios get executed but it will throw the exception in the beginning and my test steps will not execute.

bOneKop avatar May 07 '20 04:05 bOneKop

Will you try 3.0.0-SNAPSHOT? You will required to add snapshots repository to your pom.

<repository>
	<id>nexus-snapshots</id>
	<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>

cjayswal avatar May 07 '20 05:05 cjayswal

OK, thanks, I will try it

bOneKop avatar May 07 '20 05:05 bOneKop

3.0.0-SNAPSHOT

I change qaf-cucumber to 3.0.0-SNAPSHOT, there is an exception in the beginning. Then all scenarios get executed

14:06:17 java.lang.NoSuchFieldException: modifiers 14:06:17 at java.base/java.lang.Class.getDeclaredField(Class.java:2416) 14:06:17 at com.qmetry.qaf.automation.util.ClassUtil.setField(ClassUtil.java:599) 14:06:17 at com.qmetry.qaf.automation.cucumber.bdd2.parser.Bdd2Compiler.getExamples(Bdd2Compiler.java:200) 14:06:17 at com.qmetry.qaf.automation.cucumber.bdd2.parser.Bdd2Compiler.compileScenarioOutline(Bdd2Compiler.java:126) 14:06:17 at com.qmetry.qaf.automation.cucumber.bdd2.parser.Bdd2Compiler.compile(Bdd2Compiler.java:96) 14:06:17 at com.qmetry.qaf.automation.cucumber.bdd2.parser.BDD2FeatureParser.compilePickles(BDD2FeatureParser.java:57) 14:06:17 at com.qmetry.qaf.automation.cucumber.bdd2.parser.BDD2FeatureParser.parseBDD2(BDD2FeatureParser.java:41) 14:06:17 at com.qmetry.qaf.automation.cucumber.bdd2.parser.BDD2FeatureParser.parse(BDD2FeatureParser.java:69) 14:06:17 at io.cucumber.core.feature.FeatureParser.parseResource(FeatureParser.java:44) 14:06:17 at java.base/java.util.function.BiFunction.lambda$andThen$0(BiFunction.java:70) 14:06:17 at io.cucumber.core.resource.ResourceScanner.lambda$processResource$2(ResourceScanner.java:126) 14:06:17 at io.cucumber.core.resource.PathScanner$ResourceFileVisitor.visitFile(PathScanner.java:67) 14:06:17 at io.cucumber.core.resource.PathScanner$ResourceFileVisitor.visitFile(PathScanner.java:52) 14:06:17 at java.base/java.nio.file.Files.walkFileTree(Files.java:2801) 14:06:17 at java.base/java.nio.file.Files.walkFileTree(Files.java:2873) 14:06:17 at io.cucumber.core.resource.PathScanner.findResourcesForPath(PathScanner.java:46) 14:06:17 at io.cucumber.core.resource.PathScanner.findResourcesForUri(PathScanner.java:26) 14:06:17 at io.cucumber.core.resource.ResourceScanner.findResourcesForUri(ResourceScanner.java:109) 14:06:17 at io.cucumber.core.resource.ResourceScanner.scanForResourcesUri(ResourceScanner.java:86) 14:06:17 at io.cucumber.core.runtime.FeaturePathFeatureSupplier.loadFeatures(FeaturePathFeatureSupplier.java:61) 14:06:17 at io.cucumber.core.runtime.FeaturePathFeatureSupplier.get(FeaturePathFeatureSupplier.java:45) 14:06:17 at io.cucumber.junit.Cucumber.(Cucumber.java:156) 14:06:17 at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 14:06:17 at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 14:06:17 at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 14:06:17 at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) 14:06:17 at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) 14:06:17 at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104) 14:06:17 at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86) 14:06:17 at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) 14:06:17 at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) 14:06:17 at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) 14:06:17 at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33) 14:06:17 at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:362) 14:06:17 at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273) 14:06:17 at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238) 14:06:17 at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159) 14:06:17 at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384) 14:06:17 at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345) 14:06:17 at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126) 14:06:17 at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)

bOneKop avatar May 07 '20 06:05 bOneKop

You can ignore console log as long as your scenarios get executed, working as expected and reports correct pass/fail results in qaf dashboard. Keep in mind that cucumber/junit result may be incorrect for verification failure but qaf dashboard results should be correct.

cjayswal avatar May 07 '20 06:05 cjayswal

You can ignore console log as long as your scenarios get executed, working as expected and reports correct pass/fail results in qaf dashboard. Keep in mind that cucumber/junit result may be incorrect for verification failure but qaf dashboard results should be correct.

OK, I think it works. qaf-cucumebr-3.0.0-SNAPSHOT will release soon?

bOneKop avatar May 07 '20 06:05 bOneKop