-1

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);
}
Michail Alexakis
  • 1,042
  • 9
  • 12
  • 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. – Silvio Mayolo May 16 '22 at 15:40
  • 2
    Welcome. You should take a look at [ask] and take the [tour], if you have not done so already. Also take a look at [example]. – cliff2310 May 16 '22 at 15:44
  • 1
    What about [How to set system property?](https://stackoverflow.com/questions/5189914/how-to-set-system-property) and similar questions? Do these help? – andrewJames May 16 '22 at 16:00
  • Sorry about the lack of details, I changed the problem explanation. – Paulo Henrique Neves May 16 '22 at 16:34

1 Answers1

0

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.

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.

slindenau
  • 368
  • 2
  • 8