Ignore:
Timestamp:
2026-10-06T08:57:52+02:00 (5 days ago)
Author:
stoecker
Message:

detect the UTF-8 filename issue in non-UTF contexts, patch by wangi, fix #24940

File:
1 edited

Legend:

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

    r19535 r19637  
    55import java.io.Serializable;
    66import java.lang.reflect.InvocationTargetException;
     7import java.nio.file.InvalidPathException;
    78import java.util.ArrayList;
    89import java.util.Arrays;
    … …  
    2223import org.openstreetmap.josm.tools.Logging;
    2324import org.openstreetmap.josm.tools.StreamUtils;
     25import org.openstreetmap.josm.tools.Utils;
    2426
    2527/**
    … …  
    279281
    280282    /**
     283     * Check if this is caused by the name of a file which cannot be represented in the character set Java uses for
     284     * file names. Java takes that character set from the locale, so this happens when JOSM runs in the C/POSIX locale,
     285     * or with a locale which is not installed: file names are then ASCII only, and opening a folder which holds a
     286     * non-ASCII name fails. See #14596.
     287     * @return <code>true</code> if it is.
     288     * @since 19637
     289     */
     290    public boolean isUnmappableFileName() {
     291        return !"UTF-8".equalsIgnoreCase(Utils.getSystemProperty("sun.jnu.encoding"))
     292                && StreamUtils.toStream(CauseTraceIterator::new).anyMatch(t -> t instanceof InvalidPathException
     293                        && String.valueOf(((InvalidPathException) t).getReason()).contains("unmappable characters"));
     294    }
     295
     296    /**
    281297     * Iterates over the causes for this exception. Ignores cycles and aborts iteration then.
    282298     * @author Michal Zangl
Note: See TracChangeset for help on using the changeset viewer.