diff -aru a/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java b/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java --- a/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java 2022-06-05 11:19:08.427653868 +0800 +++ b/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java 2022-06-05 11:21:39.300102583 +0800 @@ -371,7 +371,28 @@ String userDir = System.getProperty("user.home"); String version = System.getProperty("java.version"); String fs = File.separator; - String dir = userDir+fs+".java"+fs+"fonts"+fs+version; + String dir; + /* On Linux systems, put the font config into + * ${XDG_CONFIG_HOME:-$HOME/.config}/java/fonts in order to follow + * the XDG Base Directory Specification. + */ + if (System.getProperty("os.name").equals("Linux")) { + /* assume homedir can be found, which the jvm already does */ + String xdgDefaultConfigHome = System.getenv("HOME")+"/.config"; + String xdgConfigHomeEnvVar = "XDG_CONFIG_HOME"; + String xdgConfigDir; + + String xdgSetConfigDir = System.getenv(xdgConfigHomeEnvVar); + + if (xdgSetConfigDir == null) + xdgConfigDir = xdgDefaultConfigHome; + else + xdgConfigDir = xdgSetConfigDir; + + dir = xdgConfigDir+"/java/fonts/"+version; + } else { + dir = userDir+fs+".java"+fs+"fonts"+fs+version; + } Locale locale = SunToolkit.getStartupLocale(); String lang = locale.getLanguage(); String country = locale.getCountry(); diff -aru a/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java b/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java --- a/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java 2022-06-05 11:19:08.464321174 +0800 +++ b/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java 2022-06-05 11:23:26.031650504 +0800 @@ -121,9 +121,30 @@ private static void setupUserRoot() { AccessController.doPrivileged(new PrivilegedAction() { public Void run() { - userRootDir = - new File(System.getProperty("java.util.prefs.userRoot", - System.getProperty("user.home")), ".java/.userPrefs"); + /* On Linux systems, put the userPrefs dir into + * ${XDG_CONFIG_HOME:-$HOME/.config}/java/userPrefs in order to + * follow the XDG Base Directory Specification. + */ + if (System.getProperty("os.name").equals("Linux")) { + /* assume findable homedir, which the jvm already does */ + String xdgDefaultConfigHome = System.getenv("HOME") + + "/.config"; + String xdgConfigHomeEnvVar = "XDG_CONFIG_HOME"; + String xdgConfigDir; + + String xdgSetConfigDir = System.getenv(xdgConfigHomeEnvVar); + + if (xdgSetConfigDir == null) + xdgConfigDir = xdgDefaultConfigHome; + else + xdgConfigDir = xdgSetConfigDir; + + userRootDir = new File(xdgConfigDir, "java/userPrefs"); + } else { + userRootDir = + new File(System.getProperty("java.util.prefs.userRoot", + System.getProperty("user.home")), ".java/.userPrefs"); + } // Attempt to create root dir if it does not yet exist. if (!userRootDir.exists()) { if (userRootDir.mkdirs()) {