gmethvin/directory-watcher

Fails with NoClassDefFoundError inside Wildfly

Artur- opened this issue · 2 comments

Artur- commented

When running inside Wildfly 27.0.1.Final, a call to waitAsync() fails with

12:01:30,947 ERROR [stderr] (default task-2) Caused by: java.lang.NoClassDefFoundError: com/sun/nio/file/ExtendedWatchEventModifier
12:01:30,947 ERROR [stderr] (default task-2) 	at deployment.project-base-flow-cdi-1.0-SNAPSHOT.war//io.methvin.watcher.DirectoryWatcher.register(DirectoryWatcher.java:454)
12:01:30,947 ERROR [stderr] (default task-2) 	at deployment.project-base-flow-cdi-1.0-SNAPSHOT.war//io.methvin.watcher.DirectoryWatcher.registerAll(DirectoryWatcher.java:433)
12:01:30,947 ERROR [stderr] (default task-2) 	at deployment.project-base-flow-cdi-1.0-SNAPSHOT.war//io.methvin.watcher.DirectoryWatcher.registerPaths(DirectoryWatcher.java:282)
12:01:30,947 ERROR [stderr] (default task-2) 	at deployment.project-base-flow-cdi-1.0-SNAPSHOT.war//io.methvin.watcher.DirectoryWatcher.watchAsync(DirectoryWatcher.java:229)
12:01:30,947 ERROR [stderr] (default task-2) 	at deployment.project-base-flow-cdi-1.0-SNAPSHOT.war//io.methvin.watcher.DirectoryWatcher.watchAsync(DirectoryWatcher.java:215)

The problematic code is

    WatchEvent.Modifier[] modifiers =
        useFileTreeModifier
            ? new WatchEvent.Modifier[] {ExtendedWatchEventModifier.FILE_TREE}
            : new WatchEvent.Modifier[] {};

and as it throws a NoClassDefFoundError, the case is not handled by

      } catch (UnsupportedOperationException e) {
        // UnsupportedOperationException should only happen if FILE_TREE is unsupported
        logger.debug("Assuming ExtendedWatchEventModifier.FILE_TREE is not supported", e);
        fileTreeSupported = false;
        // If we failed to use the FILE_TREE modifier, try again without
        registerAll(start, context);
      }

I guess if you still want it to work without having to have com.sun.nio.file on the classpath, then we could also catch the NoClassDefFoundError, but that modifier provides much better accuracy and performance when it is supported, so do we really want to do that? I'm not familiar with Wildfly in particular so I'm not sure about the impact there.

This might be related. I'm getting this error on GraalVM 22:

Execution error (NoSuchMethodError) at com.oracle.truffle.api.library.LibraryFactory/ensureLibraryInitialized (LibraryFactory.java:384).
'void sun.misc.Unsafe.ensureClassInitialized(java.lang.Class)'