java-native-access/jna · error · Error
FileMonitor not implemented for " + os
Error message
FileMonitor not implemented for " + os
What it means
FileMonitor's Holder static initializer throws an Error when the os.name system property does not start with "Windows", because only a W32FileMonitor implementation exists in this code path. Loading FileMonitor.getInstance() on any non-Windows platform aborts class initialization.
Source
Thrown at contrib/platform/src/com/sun/jna/platform/FileMonitor.java:138
protected void finalize() {
for (File watchedFile : watched.keySet()) {
removeWatch(watchedFile);
}
dispose();
}
/** Canonical lazy loading of a singleton. */
private static class Holder {
public static final FileMonitor INSTANCE;
static {
String os = System.getProperty("os.name");
if (os.startsWith("Windows")) {
INSTANCE = new W32FileMonitor();
}
else {
throw new Error("FileMonitor not implemented for " + os);
}
}
}
public static FileMonitor getInstance() {
return Holder.INSTANCE;
}
}
View on GitHub (pinned to d036ad9781)
Solutions
- Only call FileMonitor.getInstance() after verifying Platform.isWindows()
- Use a cross-platform file watcher (java.nio.file.WatchService) on non-Windows platforms
- Check os.name at startup and disable file-monitor features on unsupported OSes
Example fix
// before
FileMonitor fm = FileMonitor.getInstance();
// after
if (Platform.isWindows()) {
FileMonitor fm = FileMonitor.getInstance();
} else {
WatchService ws = FileSystems.getDefault().newWatchService();
} Defensive patterns
Strategy: fallback
Validate before calling
if (!System.getProperty("os.name", "").startsWith("Windows")) {
throw new IllegalStateException("FileMonitor requires Windows");
} Type guard
boolean fileMonitorSupported() {
return Platform.isWindows();
} Try / catch
try {
monitor = FileMonitor.getInstance();
} catch (Throwable t) {
monitor = null; // fall back to WatchService
} Prevention
- Gate FileMonitor usage behind Platform.isWindows()
- Prefer java.nio.file.WatchService for cross-platform watching
- Never override os.name in production JVM flags
When it happens
Trigger: Calling FileMonitor.getInstance() (or otherwise triggering Holder class init) on macOS, Linux, or any OS whose name does not start with "Windows".
Common situations: Running directory/file watching code developed for Windows on a Linux CI server or a Mac developer machine; os.name overridden via -Dos.name=... causing even Windows to fail.
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
- No support (yet) for " + System.getProperty("os.name")
- No trash location found (define fileutils.trash to be the pa
- The following files could not be trashed: " + failed
- KeyboardUtils requires a keyboard
- Can't open X Display
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/4ff00dff46f4f698.
Report an issue: GitHub.