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] java.lang.ExceptionInInitializerError when running JUnit tests using new CureString("string") #26

Closed
prouzpe3 opened this issue Jun 5, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@prouzpe3
Copy link

prouzpe3 commented Jun 5, 2024

Description

When running JUnit tests that use this library - calling new CuredString("value") results in an exception

Caused by: java.lang.RuntimeException: [x86_64-unknown-linux-gnu] this operating system (Linux) and/or architecture (x64) is not supported.
original error:
no decancer-x86_64-unknown-linux-gnu in java.library.path: /usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib
	at com.github.null8626.decancer.CuredString.<clinit>(CuredString.java:70)
	... 48 more

I have identified the issue is with the exception for loading the library for JUnit tests.

if (CuredString.isJUnit()) {
    System.loadLibrary("decancer-" + rustTarget);
}

I assume it was supposed to detect test runs for regression testing of this library. But it does not distinguish it from running it from another project. It goes through the thread stack trace and checks the class name, looking for the first appearence of org.junit element.getClassName().startsWith("org.junit.")

If I remove the condition for JUnit tests and use the NativeUtils to load the library as is used for the production use. It works well in the unit tests as well.

Would it be possible to create a more sophisticated approach to detecting which unit tests are run?

Steps to Reproduce:

  1. Create a new project
  2. import the library
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.github.null8626</groupId>
            <artifactId>decancer</artifactId>
            <version>v3.2.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>          
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
  1. Create and run JUnit tests using this library

Environment:

OS: Ubuntu 24
Java Version: Java 21
Library Version: v3.2.0

@null8626
Copy link
Owner

null8626 commented Jun 6, 2024

Hai! Thanks for reporting this bug. This bug should be fixed in 3fdf8e7.

Sadly, i can't publish the latest results to jitpack because the repository's history went over 500 MB. Currently i am thinking of migrating from jitpack to maven central.

@null8626 null8626 added the bug Something isn't working label Jun 6, 2024
@prouzpe3
Copy link
Author

prouzpe3 commented Jun 6, 2024

I've tried it on top of current HEAD (2a1030f) and unfortunately it finished with the same error.

@null8626
Copy link
Owner

null8626 commented Jun 6, 2024

Huh, alright. Thanks for reporting.

@null8626
Copy link
Owner

null8626 commented Jun 6, 2024

@prouzpe3 I think c4ec664 should suffice. Can you try it again on top of ffa31ed?

@prouzpe3
Copy link
Author

prouzpe3 commented Jun 7, 2024

I can confirm it works on top of ffa31ed, Great work!

@null8626
Copy link
Owner

null8626 commented Jun 7, 2024

Thank you! ❤️

@null8626
Copy link
Owner

null8626 commented Jun 7, 2024

As this bug is fixed, the issue may be closed. Though the fix will officially be released in v3.2.1, which is sadly delayed because of #27.

@null8626 null8626 closed this as completed Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants