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

AnnotationSpec throwing java.lang.reflect.InvocationTargetException instead of User Exception #539

Closed
LeoColman opened this issue Jan 11, 2019 · 4 comments
Assignees
Labels
bug 🐛 Issues that report a problem or error in the code.
Milestone

Comments

@LeoColman
Copy link
Member

When executing a test with AnnotationSpec:


class Foo : AnnotationSpec() {
  class FooException: Exception()


  @Test
  fun foo() {
    throw FooException()
  }
}

I expected the stacktrace to contain my exception and my line at the top, but instead it returns a weird Stacktrace.

This happened after changing it's execution to invokeSuspend

java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:71)
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Instance.call(CallerImpl.kt:87)
	at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:106)
	at io.kotlintest.specs.AbstractAnnotationSpec$createTestCase$$inlined$let$lambda$1.invokeSuspend(AbstractAnnotationSpec.kt:76)
.....

@LeoColman LeoColman added the bug 🐛 Issues that report a problem or error in the code. label Jan 11, 2019
@LeoColman LeoColman self-assigned this Jan 11, 2019
@LeoColman LeoColman added this to the 3.2 milestone Jan 11, 2019
@LeoColman
Copy link
Member Author

I just discovered this isn't actually related to invokeSuspend, therefore it doesn't have anything to do with 3.2.0-RC2. It's just a bug in AnnotationSpec

Should we point it to 3.2.0 anyways, @sksamuel ?

LeoColman added a commit that referenced this issue Jan 11, 2019
When a test fails from an AnnotationSpec, it was wrapped in an InvocationTargetException, due to it being called via reflection. Because of it, the test failure stacktrace was confusing, as it wouldn't display user's exception directly.

As explained in https://stackoverflow.com/questions/6020719/what-could-cause-java-lang-reflect-invocationtargetexception , this commit attempts to unwrap an exception if it's thrown by a reflection call context, by returning it's cause instead.

Fixes #539
@sksamuel
Copy link
Member

Yeah can put it on 3.2.0 unless someone asks for it on 3.1

@LeoColman
Copy link
Member Author

I meant if this should go for 3.2 or 3.3, as it's unrelated to 3.2

@sksamuel
Copy link
Member

Yes it's a bug and we've not yet released 3.2.0 so definitely target that.

sksamuel pushed a commit that referenced this issue Jan 11, 2019
When a test fails from an AnnotationSpec, it was wrapped in an InvocationTargetException, due to it being called via reflection. Because of it, the test failure stacktrace was confusing, as it wouldn't display user's exception directly.

As explained in https://stackoverflow.com/questions/6020719/what-could-cause-java-lang-reflect-invocationtargetexception , this commit attempts to unwrap an exception if it's thrown by a reflection call context, by returning it's cause instead.

Fixes #539
LeoColman added a commit that referenced this issue Jan 11, 2019
LeoColman added a commit that referenced this issue Jan 11, 2019
When a test fails from an AnnotationSpec, it was wrapped in an InvocationTargetException, due to it being called via reflection. Because of it, the test failure stacktrace was confusing, as it wouldn't display user's exception directly.

As explained in https://stackoverflow.com/questions/6020719/what-could-cause-java-lang-reflect-invocationtargetexception , this commit attempts to unwrap an exception if it's thrown by a reflection call context, by returning it's cause instead.

Fixes #539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Issues that report a problem or error in the code.
Projects
None yet
Development

No branches or pull requests

2 participants