Skip to content

[JAVA] java.lang.ExceptionInInitializerError when running JUnit tests using new CureString("string") #26

@prouzpe3

Description

@prouzpe3

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions