3

I'm trying to solve a problem with my Java project and one of the possible solutions is to change jdk.io.File.enableADS to TRUE in system properties. But, i don't know how to change it.

I'm also working in a project that uses jhipster and undertow. My project builds with no error, generating the connection link, but when I try to connect the page it doesn't load and the application shows the error:

java.lang.NoClassDefFoundError: Could not initialize class org.xnio.conduits.Conduit

I've looked at the code, found the line that throws the error and I saw in many blogs people telling to change the config above the text.

I'm using the JDK 11.0.15

This is the code that throws the error:

 try {
    if (osName.contains("windows")) {
         return new FileOutputStream("NUL:").getChannel();
    } else {
         return new FileOutputStream("/dev/null").getChannel();
    }
} catch (FileNotFoundException e) {
    throw new IOError(e);
}
3
  • 2
    "I'm working on a problem. I found a solution but it doesn't work". This is not a question we can answer in any form, without knowing what either the problem or the proposed solution is. May 16, 2022 at 15:40
  • 1
    What about How to set system property? and similar questions? Do these help? May 16, 2022 at 16:00
  • Sorry about the lack of details, I changed the problem explanation. May 16, 2022 at 16:34

2 Answers 2

7

It seems you're running into this problem: Java: FileOutputStream("NUL:") not working after Java upgrade

The code you're referencing that is causing the problem is from https://code.yawk.at/org.jboss.xnio/xnio-api/3.8.4.Final/org/xnio/conduits/Conduits.java

    static {
        NULL_FILE_CHANNEL = AccessController.doPrivileged(new PrivilegedAction<FileChannel>() {
            public FileChannel run() {
                final String osName = System.getProperty("os.name", "unknown").toLowerCase(Locale.US);
                try {
                    if (osName.contains("windows")) {
                        return new FileOutputStream("NUL:").getChannel();
                    } else {
                        return new FileOutputStream("/dev/null").getChannel();
                    }
                } catch (FileNotFoundException e) {
                    throw new IOError(e);
                }
            }
        });
    }

I've looked at the sources for this release (3.8.4) and the most recent release on maven central (3.8.7): https://mvnrepository.com/artifact/org.jboss.xnio/xnio-api/3.8.7.Final

And there is some good news, it has been fixed in the latest release of xnio-api. The current code in version 3.8.7 is now as follows: (NUL: was replaced by NUL)

                    if (osName.contains("windows")) {
                        return new FileOutputStream("NUL").getChannel();
                    } else {
                        return new FileOutputStream("/dev/null").getChannel();
                    }

So if it's possible i would suggest you try to upgrade your dependency so that xnio-api-3.8.7.Final.jar is used.

Update 09-2022 Thanks to the comment of @NicolasRiousset, who found the following issue logged on jhipster's github, i have further traced this problematic dependency.

It starts with the optional dependency to spring-boot-starter-undertow, which in turn depends on undertow-core, and that depends on xnio-api from Jboss.

The earliest version that includes the fix (xnio-api-3.8.7) can be found in undertow-core 2.2.18.Final. The earliest version that uses this is spring-boot-starter-undertow 2.7.1.

And JHipster starts including spring-boot version >= 2.7.1 from jhipster-framework 7.9.0.

So upgrading to JHipster >= 7.9.0 should fix this problematic xnio-api dependency.

In case you don't strictly need undertow as your embedded web server, you can also switch (back) to spring-boot-starter-tomcat, since tomcat doesn't use the xnio-api.


Otherwise the mentioned system property should indeed also be a valid workaround for now. Since the code is statically loaded, i think you'll have to use VM arguments to include it in your program instead of using System.setProperty.

So add -Djdk.io.File.enableADS=true to your programs startup/command line. See for reference the following question that was mentioned in the comments: How to set system property?

It does also seem to be fixed in newer version of the Java runtime, so upgrading your JDK/JRE is also an option. According to the linked question at the top it's fixed in Java 8u333, and on my test system with Java 17.0.2 both versions of NUL also work.

5
  • 2
    Thanks Man, I solved this issue downgrading my JDK version to 11.0.14 insted of 11.0.15 May 23, 2022 at 20:54
  • @PauloHenriqueNeves, thanks, I had same issue and downgrading to 14 also helped me. You can close this ticket I think.
    – zygimantus
    Jul 20, 2022 at 9:40
  • @PauloHenriqueNeves if this solved your problem, please consider accepting this answer as the solution to the question. Thanks!
    – slindenau
    Jul 20, 2022 at 9:45
  • 1
    There's a ticket opened about this issue github.com/jhipster/generator-jhipster/issues/18440 Upgrading to JHipster Upgrading from JHipster 7.0.1 to 7.9.3 solved the issue for me Sep 20, 2022 at 15:24
  • @NicolasRiousset great find, i have updated my answer
    – slindenau
    Sep 21, 2022 at 11:27
0

I ran into this same issue. I closed and reopened IntelliJ. Now it works. Worth trying before getting too deep down the rabbit hole.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.