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

JVM 11+ support #7

Closed
ov7a opened this issue May 19, 2022 · 9 comments
Closed

JVM 11+ support #7

ov7a opened this issue May 19, 2022 · 9 comments

Comments

@ov7a
Copy link

ov7a commented May 19, 2022

Does this library work with JVM 11, 17, etc?
For example, with corretto-17.0.3 and stacktrace-decoroutinator-jvm:2.2.1 I get

Exception in thread "main" java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) accessible: module java.base does not "opens java.lang" to unnamed module @1c20c684
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
	at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
	at dev.reformator.stacktracedecoroutinator.utils.Utils_jvmKt.getClassIfLoaded(utils-jvm.kt:11)
	at dev.reformator.stacktracedecoroutinator.runtime.DecoroutinatorRuntime.getState(runtime-jvm.kt:42)
	at dev.reformator.stacktracedecoroutinator.runtime.DecoroutinatorRuntime.load(runtime-jvm.kt:52)
	at dev.reformator.stacktracedecoroutinator.runtime.DecoroutinatorRuntime.load$default(runtime-jvm.kt:51)
	at MainKt.main(Main.kt:14)
	at MainKt.main(Main.kt)

when I launch the example from README. With 1.8 it works fine.

@Anamorphosee
Copy link
Owner

Anamorphosee commented May 19, 2022

Please check version 2.3.0. It have to fix this issue.

@ov7a
Copy link
Author

ov7a commented May 19, 2022

The example works with 2.3.0, yeah, thanks.

With bigger project I get a strange exception when I just add a dependency and run a junit test.

Caused by: java.lang.IllegalStateException: Decoroutinator registry is not set. Didn't you miss to call 'DecoroutinatorRuntime.load()'?
	at dev.reformator.stacktracedecoroutinator.common.Registry_commonKt.decoroutinatorRuntimeNotLoaded(registry-common.kt:36)
	at dev.reformator.stacktracedecoroutinator.common.Registry_commonKt.access$decoroutinatorRuntimeNotLoaded(registry-common.kt:1)
	at dev.reformator.stacktracedecoroutinator.common.Registry_commonKt$decoroutinatorRegistry$1.getEnabled(registry-common.kt:29)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(continuation-stdlib.kt:17)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	... 90 more

I think a common use case is when decoroutinator is enabled/disabled in test/prod environment via debug switch, and just having a dependency shouldn't impact project behavior. Unfortunately, I cannot reproduce this in sample project, maybe I'll dig into this later.

@Anamorphosee
Copy link
Owner

Anamorphosee commented May 19, 2022

The last exception throws when you didn't call the method 'DecoroutinatorRuntime.load()'.

For unit tests you should add that call in @BeforeTest static method.
Example is at https://github.com/Anamorphosee/stacktrace-decoroutinator/blob/master/stacktrace-decoroutinator-jvm/src/test/kotlin/runtime-test-jvm.kt#L26.

@ov7a
Copy link
Author

ov7a commented May 19, 2022

I get it, but what should a use do if he wants to switch Decoroutinator on and off via flag (config setting, env variable, etc)? For example, to enable it in tests and in dev environments, but disable it in prod?

@Anamorphosee
Copy link
Owner

Right now you can set the system property dev.reformator.stacktracedecoroutinator.enabled to false before calling DecoroutinatorRuntime.load() to disable SD. But the call is still mandatory.

This property is read once, so you cannot switch SD on and off dynamically during the execution of your app.

@ov7a
Copy link
Author

ov7a commented May 19, 2022

Its nice to have this in README.

But even with systemProperty set to false, decoroutinator still impacts the project. Behavior with and without dependency differs. For example, mockito complains and can't mock some objects (didn't dig that yet).

@Anamorphosee
Copy link
Owner

I'm agree with you that just existence of the dependency shouldn't change the app behaviour. It will be fixed in #8.

@ov7a
Copy link
Author

ov7a commented May 19, 2022

Awesome, thanks!

@ov7a ov7a closed this as completed May 19, 2022
@Anamorphosee
Copy link
Owner

Thank you for the feedback!

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

No branches or pull requests

2 participants