Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JGiven 0.14 doesn't work any more on OSGi #302

Closed
gzunino opened this issue Feb 11, 2017 · 1 comment
Closed

JGiven 0.14 doesn't work any more on OSGi #302

gzunino opened this issue Feb 11, 2017 · 1 comment
Assignees
Milestone

Comments

@gzunino
Copy link

gzunino commented Feb 11, 2017

JGiven 0.14 doesn't work by default on an OSGi environment. Versions before 0.14 worked fine.

The problem seems to be here:
com.tngtech.jgiven.impl.ByteBuddyStageCreator.getClassLoader(Class<?>)
which returns Thread.currentThread().getContextClassLoader();

returning the wrong ClassLoader to load the stageClass.

In OSGi it should be stageClass.getClassLoader() which returns the bundle class loader that has access to bundle classes and dependencies (jgiven classes).

I have validated my assumption by overriding the method in a custom StageCreator and setting the stageCreator overriding createScenario() on SimpleScenarioTest.
With those changes it works, but I think it should word under OSGi without manual customization.

The exception is:

java.lang.RuntimeException: Error while trying to create an instance of class class com.querix.dbt.common.steps.CatalogSteps at com.tngtech.jgiven.impl.ByteBuddyStageCreator.createStage(ByteBuddyStageCreator.java:26) at com.tngtech.jgiven.impl.ScenarioExecutor.addStage(ScenarioExecutor.java:205) at com.tngtech.jgiven.impl.Scenario.initialize(Scenario.java:94) at com.tngtech.jgiven.impl.ScenarioBase.performInitialization(ScenarioBase.java:91) at com.tngtech.jgiven.impl.ScenarioBase.startScenario(ScenarioBase.java:74) at com.tngtech.jgiven.junit.JGivenMethodRule.starting(JGivenMethodRule.java:109) at com.tngtech.jgiven.junit.JGivenMethodRule$1.evaluate(JGivenMethodRule.java:71) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.jboss.reddeer.junit.internal.runner.RequirementsRunner.runChild(RequirementsRunner.java:171) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.jboss.reddeer.junit.internal.runner.statement.RunBefores.evaluate(RunBefores.java:79) at org.jboss.reddeer.junit.internal.runner.statement.FulfillRequirementsStatement.evaluate(FulfillRequirementsStatement.java:45) at org.jboss.reddeer.junit.internal.runner.statement.RunIBeforeClassExtensions.evaluate(RunIBeforeClassExtensions.java:72) at org.jboss.reddeer.junit.internal.runner.statement.RunAfters.evaluate(RunAfters.java:68) at org.jboss.reddeer.junit.internal.runner.statement.CleanUpRequirementStatement.evaluate(CleanUpRequirementStatement.java:44) at org.jboss.reddeer.junit.internal.runner.statement.RunIAfterClassExtensions.evaluate(RunIAfterClassExtensions.java:59) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.jboss.reddeer.junit.internal.runner.RequirementsRunner.run(RequirementsRunner.java:153) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:66) at org.eclipse.pde.internal.junit.runtime.PlatformUITestHarness.lambda$0(PlatformUITestHarness.java:43) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalStateException: Error invoking java.lang.ClassLoader#findClass at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Resolved.loadClass(ClassInjector.java:389) at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.inject(ClassInjector.java:202) at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:188) at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default.load(ClassLoadingStrategy.java:117) at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:73) at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4525) at com.tngtech.jgiven.impl.ByteBuddyStageCreator.createStageClass(ByteBuddyStageCreator.java:37) at com.tngtech.jgiven.impl.ByteBuddyStageCreator.createStage(ByteBuddyStageCreator.java:20) ... 48 more Caused by: java.lang.NoClassDefFoundError: com/tngtech/jgiven/impl/intercept/StageInterceptorInternal at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Resolved.loadClass(ClassInjector.java:385) ... 55 more Caused by: java.lang.ClassNotFoundException: com.tngtech.jgiven.impl.intercept.StageInterceptorInternal at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.eclipse.osgi.internal.framework.ContextFinder.loadClass(ContextFinder.java:132) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 62 more

@janschaefer janschaefer self-assigned this Feb 11, 2017
@janschaefer janschaefer added this to the v0.14.1 milestone Feb 11, 2017
@janschaefer
Copy link
Contributor

Thank you for the report and for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants