Fix Unirest initialization conflict in URLDownload, AiModel
Maybe wih an update of the UniRest library, we have an issue with static?
URLDownloadTest > downloadOfHttpSucceeds() FAILED
java.lang.NoClassDefFoundError at URLDownloadTest.java:87
Caused by: java.lang.ExceptionInInitializerError at URLDownloadTest.java:68
⚠️ needs more knowledge - one needs to test an older version of the library - and maybe report upstream ⚠️
User-facing errors: Bug:
- Open JabRef (I mean start clear and don't do anything, except what's written here).
- Set valid OpenAI API key in preferences.
- Click on combobox with AI providers and see all currently available models (this triggers
Unirestinitialization). - Then exit preference and try to use WebSearch (this will trigger the first usage of
URLDownload, which initializesUnirest, and that causes error).
Logs:
java.util.concurrent.CompletionException: java.lang.NoClassDefFoundError: Could not initialize class org.jabref.logic.net.URLDownload
at java.base/java.util.concurrent.CompletableFuture.wrapInCompletionException(CompletableFuture.java:323)
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:359)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:364)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1791)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
at java.base/java.lang.Thread.run(Thread.java:1474)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jabref.logic.net.URLDownload
at org.jabref.jablib/org.jabref.logic.importer.WebFetcher.getUrlDownload(WebFetcher.java:33)
at org.jabref.jablib/org.jabref.logic.importer.fetcher.DoiFetcher.getAgency(DoiFetcher.java:228)
at org.jabref.jablib/org.jabref.logic.importer.fetcher.DoiFetcher.doAPILimiting(DoiFetcher.java:95)
at org.jabref.jablib/org.jabref.logic.importer.fetcher.DoiFetcher.asyncPerformSearchById(DoiFetcher.java:108)
at org.jabref.jablib/org.jabref.logic.importer.fetcher.ArXivFetcher.inplaceAsyncInfuseArXivWithDoi(ArXivFetcher.java:299)
at org.jabref.jablib/org.jabref.logic.importer.fetcher.ArXivFetcher.inplaceAsyncInfuseArXivWithDoi(ArXivFetcher.java:274)
at org.jabref.jablib/org.jabref.logic.importer.fetcher.ArXivFetcher.lambda$enrichPageWithDoi$1(ArXivFetcher.java:360)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1789)
... 3 more
Caused by: java.lang.ExceptionInInitializerError: Exception kong.unirest.core.UnirestConfigException: Http Clients are already built in order to build a new config execute Unirest.config().reset() before changing settings.
This should be done rarely. [in thread "pool-12-thread-6"]
at [email protected]/kong.unirest.core.Config.validateClientsNotRunning(Config.java:980)
at [email protected]/kong.unirest.core.Config.followRedirects(Config.java:530)
at org.jabref.jablib/org.jabref.logic.net.URLDownload.<clinit>(URLDownload.java:89)
... 11 more
https://kong.github.io/unirest-java/configuration/
/assign-me
👋 Hey @thesauravpoddar, thank you for your interest in this issue! 🎉
We're excited to have you on board. Start by exploring our Contributing guidelines, and set up your local development workspace by following the steps in our workspace setup guidelines to get started smoothly.
For questions on JabRef functionality, you can consult the JabRef Guru. For questions related to the codebase, please start using DeepWiki.
In case you encounter failing tests during development, please check our developer FAQs!
Still facing issues or having more questions? Feel free to ask here on GitHub or on JabRef's Gitter chat. Please don't hesitate to open a (draft) pull request early on to show the direction you are heading towards if unsure.
Happy coding! 🚀
/assign-me
👋 Hey @AleKK31, thank you for your interest in this issue! 🎉
We're excited to have you on board. Start by exploring our Contributing guidelines, and set up your local development workspace by following the steps in our workspace setup guidelines to get started smoothly.
For questions on JabRef functionality, you can consult the JabRef Guru. For questions related to the codebase, please start using DeepWiki.
In case you encounter failing tests during development, please check our developer FAQs!
Still facing issues or having more questions? Feel free to ask here on GitHub or on JabRef's Gitter chat. Please don't hesitate to open a (draft) pull request early on to show the direction you are heading towards if unsure.
Happy coding! 🚀
/unassign-me
@AleKK31 has been unassigned from this issue.
/assign-me
👋 Hey @akilan590, thank you for your interest in this issue! 🎉
We're excited to have you on board. Start by exploring our Contributing guidelines, and set up your local development workspace by following the steps in our workspace setup guidelines to get started smoothly.
For questions on JabRef functionality, you can consult the JabRef Guru. For questions related to the codebase, please start using DeepWiki.
In case you encounter failing tests during development, please check our developer FAQs!
Still facing issues or having more questions? Feel free to ask here on GitHub or on JabRef's Gitter chat. Please don't hesitate to open a (draft) pull request early on to show the direction you are heading towards if unsure.
Happy coding! 🚀
Hi @koppor,
I tried to reproduce this issue on the latest main branch.
Initially, I couldn't run URLDownloadTest because I was using the regular test task. After noticing it's marked with @FetcherTest, I ran it using the fetcherTest task instead.
On my setup, the test passed successfully, and I couldn't reproduce the NoClassDefFoundError.
Am I missing any specific setup, or was this issue observed on an older commit or a particular UniRest version?
@akilan590 Have fun at debugging
See https://github.com/JabRef/jabref/actions/runs/28348906637/job/83977645693
Note that locally on my linux it works. Thus, you probably need a Docker image mirroring the GitHub action runner.
Hi @koppor,
I investigated the issue a bit. I couldn't reproduce it on my local setup (latest main), but in the GitHub Actions log I noticed that the first failure is ExceptionInInitializerError caused by kong.unirest.core.UnirestConfigException. The later NoClassDefFoundErrors seem to happen because of that initial failure.
I couldn't find the full UnirestConfigException message in the Actions log. Am I looking in the wrong place, or is there a more detailed stack trace available?
I investigated the issue a bit. I couldn't reproduce it on my local setup (latest main),
Same here
I couldn't find the full UnirestConfigException message in the Actions log. Am I looking in the wrong place, or is there a more detailed stack trace available?
Try to tweak log config etc. maybe setup a separate repository with a MWE.
Logging is explained in our dev docs.
@koppor, I investigated it further, but I still couldn't reproduce the issue locally. I also looked through the Unirest source, and the obvious UnirestConfigException paths don't seem to match how JabRef initializes Unirest.config().
I think the GitHub Actions log may be hiding the actual underlying exception. What's the best way to get the full stack trace? Would you recommend adding temporary logging around Unirest.config(), or is there a better approach?
Hi @koppor !, I spent some time investigating this issue.
I tested it on the latest main branch on both Windows and an Ubuntu 24.04 Docker container with Java 25. In both cases, URLDownloadTest passed successfully. I also created a small standalone project using the same Unirest version, and Unirest.config() initialized without any issues.
From the GitHub Actions log, it looks like the first failure is an ExceptionInInitializerError caused by UnirestConfigException, and the remaining URLDownloadTest failures are a consequence of that. However, I haven't been able to reproduce the failure locally.
Is this issue still reproducible on the latest CI? If so, is there a more recent failing workflow or a full stack trace for the original UnirestConfigException? That would help narrow down what's different in the GitHub Actions environment.
Is this issue still reproducible on the latest CI?
Can't you see the failing tests for yourself?
also created a small standalone project using the same Unirest version, and Unirest.config() initialized without any issues.
Link? Link to CI output?
Hi @koppor ,
I investigated this issue further and was able to reproduce it locally.
Initially, I was only running URLDownloadTest by itself, and it passed successfully. After that, I ran the same task that the GitHub Actions workflow runs:
./gradlew fetcherTest
This reproduces the failure locally.
The exception is:
kong.unirest.core.UnirestConfigException: Http Clients are already built in order to build a new config. Execute Unirest.config().reset() before changing settings.
The stack trace points to the static initializer in URLDownload:
static { Unirest.config() .followRedirects(true) .enableCookieManagement(true) .setDefaultHeader("User-Agent", USER_AGENT); }
I also verified that running only URLDownloadTest succeeds:
./gradlew fetcherTest --tests "org.jabref.logic.net.URLDownloadTest"
However, running the complete fetcherTest suite reproduces the failure.
From what I observed, it looks like Unirest.config() is being called after the global Unirest client has already been initialized earlier in the same JVM. Since this happens during URLDownload's static initialization (URLDownload.
Does this match your understanding of the issue? If it does, I'd be happy to work on a PR.
Hi @koppor ,
just following up on my previous investigation. I was able to reproduce the issue locally by running the full fetcherTest suite, while URLDownloadTest passes when run in isolation. Based on the stack trace and the UnirestConfigException, it seems the failure is related to URLDownload configuring Unirest after the global client has already been initialized. Could you let me know if this matches your understanding of the issue? If it does, I'd be happy to work on a PR.
, it seems the failure is related to URLDownload configuring Unirest after the global client has already been initialized.
At which places? I only find a single "Unirest.config()" call.