Changeset 17688 in josm


Ignore:
Timestamp:
2021-03-30T09:03:19+02:00 (3 years ago)
Author:
simon04
Message:

see #19724 - Fix NPE in PlatformHookWindows.getInstalledFonts on Linux/macOS

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java

    r17679 r17688  
    529529        // Use more low-level method to find the installed fonts.
    530530        List<String> fontsAvail = new ArrayList<>();
    531         Path fontPath = FileSystems.getDefault().getPath(getSystemEnv("SYSTEMROOT"), "Fonts");
     531        String systemRoot = getSystemEnv("SYSTEMROOT");
     532        if (systemRoot == null) {
     533            return fontsAvail;
     534        }
     535        Path fontPath = FileSystems.getDefault().getPath(systemRoot, "Fonts");
    532536        try (DirectoryStream<Path> ds = Files.newDirectoryStream(fontPath)) {
    533537            for (Path p : ds) {
  • trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java

    r17679 r17688  
    55import static org.junit.jupiter.api.Assertions.assertFalse;
    66import static org.junit.jupiter.api.Assertions.assertNotNull;
    7 import static org.junit.jupiter.api.Assertions.assertNull;
    87import static org.junit.jupiter.api.Assertions.assertTrue;
    98import static org.junit.jupiter.api.Assertions.fail;
     
    1312import java.io.File;
    1413import java.io.IOException;
    15 import java.nio.file.FileSystems;
    1614import java.security.KeyStoreException;
    1715import java.util.Collection;
     
    172170    @Test
    173171    void testGetInstalledFonts() {
    174         assumeTrue(FileSystems.getDefault() != null); // weird NPE on Jenkins
    175         assumeTrue(Utils.getJavaVersion() < 16 || PlatformManager.isPlatformWindows()); // No idea why the test fails with Java 16+ on Linux
    176172        Collection<String> fonts = hook.getInstalledFonts();
    177173        if (PlatformManager.isPlatformWindows()) {
    178174            assertFalse(fonts.isEmpty());
    179175        } else {
    180             assertNull(fonts);
     176            assumeTrue(fonts.isEmpty());
    181177        }
    182178    }
Note: See TracChangeset for help on using the changeset viewer.