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

Java version of assertAny #502

Open
ajburley opened this issue Jul 28, 2023 · 0 comments
Open

Java version of assertAny #502

ajburley opened this issue Jul 28, 2023 · 0 comments

Comments

@ajburley
Copy link

ajburley commented Jul 28, 2023

Library Version:

4.3.0

Describe the Bug:

I am not sure if this is a bug, but I could not find any way to invoke the convenience method assertAny from Java code.

The Kotlin function(s) are annotated with @JvmStatic (in BaristaAssertions.kt) which makes me think that there's meant to be a static version of this method which can be called from Java code, but there is no such method in the final bytecode. There IS a method com.adevinta.android.barista.internal.AssertAnyKt.assertAny in Java, but that method has a different signature assertAny(Matcher, Matcher) and also it's clearly an internal method from the package name.

I believe that reified functions cannot be called from Java code, which is why this issue appears.

If this was never meant to be possible, then I apologise and this should not be considered a bug - but in that case I'm not sure why the function is annotated as @JvmStatic.

Steps to reproduce the bug:

  1. Write a Java file with import static com.adevinta.android.barista.assertion.BaristaAssertions.assertAny; in the imports
  2. Compile and note that the compiler gives an error that the method was not found

Or:

  1. Extract the classes.jar from the final aar release of barista
  2. Decompile classes.jar using any Java decompiler (I used JD-GUI)
  3. Observe that there is no assertAny static method in the final bytecode (apart from the internal version mentioned above)

Expected Behavior:

I expected to be able to import this method and call it from Java code. I am aware that the syntax would not be quite as simple as in Kotlin code, but still better than creating custom matchers. Is it possible to create a non-reified version of this function so it can be called from Java code?

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

1 participant