Changeset 19637 in josm
- Timestamp:
- 2026-10-06T08:57:52+02:00 (5 days ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
-
native/linux/latest/usr/bin/josm-latest (modified) (1 diff)
-
native/linux/tested/usr/bin/josm (modified) (1 diff)
-
src/org/openstreetmap/josm/gui/bugreport/BugReportDialog.java (modified) (3 diffs)
-
src/org/openstreetmap/josm/tools/bugreport/ReportedException.java (modified) (3 diffs)
-
test/unit/org/openstreetmap/josm/gui/bugreport/BugReportDialogTest.java (added)
-
test/unit/org/openstreetmap/josm/tools/bugreport/ReportedExceptionTest.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/native/linux/latest/usr/bin/josm-latest
r19430 r19637 58 58 # shellcheck source=/etc/default/josm-latest 59 59 . "/etc/default/${JOSM_VERSION}" 60 fi 61 62 # Java decodes file names with the character set of the locale, and -Dsun.jnu.encoding 63 # cannot override it. If the locale is C/POSIX, or cannot be set at all - typically a 64 # UTF-8 LANG whose locale is not installed, as in a Flatpak sandbox - file names are 65 # decoded as ASCII and opening a folder that holds a non-ASCII name fails with 66 # InvalidPathException. Fall back to C.UTF-8 then, which is built into glibc 2.35 and 67 # later. This does not change the language of JOSM: when the locale cannot be set, Java 68 # already falls back to English. LC_ALL is needed, as setlocale() fails as a whole if 69 # any category names a locale that is not installed. 70 if { [ -n "$(locale 2>&1 >/dev/null)" ] || [ "$(locale charmap 2>/dev/null)" = "ANSI_X3.4-1968" ]; } \ 71 && [ -z "$(LC_ALL=C.UTF-8 locale 2>&1 >/dev/null)" ]; then 72 export LC_ALL=C.UTF-8 60 73 fi 61 74 -
trunk/native/linux/tested/usr/bin/josm
r19430 r19637 58 58 # shellcheck source=/etc/default/josm 59 59 . "/etc/default/${JOSM_VERSION}" 60 fi 61 62 # Java decodes file names with the character set of the locale, and -Dsun.jnu.encoding 63 # cannot override it. If the locale is C/POSIX, or cannot be set at all - typically a 64 # UTF-8 LANG whose locale is not installed, as in a Flatpak sandbox - file names are 65 # decoded as ASCII and opening a folder that holds a non-ASCII name fails with 66 # InvalidPathException. Fall back to C.UTF-8 then, which is built into glibc 2.35 and 67 # later. This does not change the language of JOSM: when the locale cannot be set, Java 68 # already falls back to English. LC_ALL is needed, as setlocale() fails as a whole if 69 # any category names a locale that is not installed. 70 if { [ -n "$(locale 2>&1 >/dev/null)" ] || [ "$(locale charmap 2>/dev/null)" = "ANSI_X3.4-1968" ]; } \ 71 && [ -z "$(LC_ALL=C.UTF-8 locale 2>&1 >/dev/null)" ]; then 72 export LC_ALL=C.UTF-8 60 73 fi 61 74 -
trunk/src/org/openstreetmap/josm/gui/bugreport/BugReportDialog.java
r17392 r19637 32 32 import org.openstreetmap.josm.tools.ImageProvider; 33 33 import org.openstreetmap.josm.tools.InputMapUtils; 34 import org.openstreetmap.josm.tools.Utils; 34 35 import org.openstreetmap.josm.tools.bugreport.BugReport; 35 36 import org.openstreetmap.josm.tools.bugreport.BugReportQueue.SuppressionMode; … … 46 47 public class BugReportDialog extends JDialog { 47 48 private static final int MAX_MESSAGE_SIZE = 500; 49 /** whether the user has been told about file names that cannot be represented, which is done once per session */ 50 private static volatile boolean unmappableFileNameExplained; 48 51 // This is explicitly not an ExtendedDialog - we still want to be able to display bug reports if there are problems with preferences/.. 49 52 private final JPanel content = new JPanel(new GridBagLayout()); … … 229 232 ); 230 233 return SuppressionMode.NONE; 234 } else if (e.isUnmappableFileName()) { 235 // Not a bug in JOSM, but a locale which cannot represent the name of a file, see #14596. Explain how to 236 // fix it rather than asking for a bug report, and only once: browsing other folders throws it again. 237 if (!unmappableFileNameExplained) { 238 unmappableFileNameExplained = true; 239 GuiHelper.runInEDTAndWait(() -> JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 240 tr("<html>JOSM cannot handle the name of a file, because it is running with the character set {0} " 241 + "for file names, which cannot represent it.<br>" 242 + "This happens when JOSM is started without a UTF-8 locale, for example with {1}, " 243 + "or with a locale which is not installed.<br><br>" 244 + "Please start JOSM with the environment variable {2}.</html>", 245 Utils.getSystemProperty("sun.jnu.encoding"), "<tt>LANG=C</tt>", "<tt>LC_ALL=C.UTF-8</tt>"), 246 tr("Unsupported file name"), 247 JOptionPane.WARNING_MESSAGE)); 248 } 249 return SuppressionMode.NONE; 231 250 } else { 232 251 PluginDownloadTask downloadTask = PluginHandler.updateOrdisablePluginAfterException(e); -
trunk/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java
r19535 r19637 5 5 import java.io.Serializable; 6 6 import java.lang.reflect.InvocationTargetException; 7 import java.nio.file.InvalidPathException; 7 8 import java.util.ArrayList; 8 9 import java.util.Arrays; … … 22 23 import org.openstreetmap.josm.tools.Logging; 23 24 import org.openstreetmap.josm.tools.StreamUtils; 25 import org.openstreetmap.josm.tools.Utils; 24 26 25 27 /** … … 279 281 280 282 /** 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 /** 281 297 * Iterates over the causes for this exception. Ignores cycles and aborts iteration then. 282 298 * @author Michal Zangl -
trunk/test/unit/org/openstreetmap/josm/tools/bugreport/ReportedExceptionTest.java
r17275 r19637 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 5 7 8 import java.nio.file.InvalidPathException; 6 9 import java.util.Arrays; 7 10 … … 62 65 63 66 /** 67 * Tests {@link ReportedException#isUnmappableFileName()}: a file name which the character set used for file names 68 * cannot represent is recognised, also as the cause of another exception, but only if that character set is not 69 * UTF-8 - otherwise the locale is not to blame. See #14596. 70 */ 71 @Test 72 void testIsUnmappableFileName() { 73 // the exception sun.nio.fs.UnixPath throws for "Capture d'écran.png" when the locale is C or not installed 74 InvalidPathException unmappable = new InvalidPathException("/home/user/Capture d'\u00e9cran.png", 75 "Malformed input or input contains unmappable characters"); 76 String jnuEncoding = System.getProperty("sun.jnu.encoding"); 77 try { 78 System.setProperty("sun.jnu.encoding", "ANSI_X3.4-1968"); 79 assertTrue(new ReportedException(unmappable).isUnmappableFileName()); 80 assertTrue(new ReportedException(new IllegalStateException(unmappable)).isUnmappableFileName()); 81 assertFalse(new ReportedException(new InvalidPathException("a\0b", "Nul character not allowed")).isUnmappableFileName()); 82 assertFalse(new ReportedException(new IllegalStateException()).isUnmappableFileName()); 83 84 System.setProperty("sun.jnu.encoding", "UTF-8"); 85 assertFalse(new ReportedException(unmappable).isUnmappableFileName()); 86 } finally { 87 System.setProperty("sun.jnu.encoding", jnuEncoding); 88 } 89 } 90 91 /** 64 92 * Tests that {@link ReportedException#isSame(ReportedException)} works as expected. 65 93 */
Note:
See TracChangeset
for help on using the changeset viewer.
