Changeset 14406 in josm


Ignore:
Timestamp:
2018-11-03T01:07:53+01:00 (5 years ago)
Author:
Don-vip
Message:

see #16937 - Support user logins with space character on Java 11 (JOSM startup)

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Version.java

    r14273 r14406  
    66import java.io.IOException;
    77import java.io.InputStream;
     8import java.net.URL;
     9import java.nio.file.InvalidPathException;
    810import java.util.Map.Entry;
    911import java.util.Optional;
     
    105107     */
    106108    public void init() {
    107         try (InputStream stream = Version.class.getResourceAsStream("/REVISION")) {
     109        try (InputStream stream = openRevisionStream("/REVISION")) {
    108110            if (stream == null) {
    109111                Logging.warn(tr("The revision file ''/REVISION'' is missing."));
     
    118120    }
    119121
     122    private static InputStream openRevisionStream(String path) throws IOException {
     123        try {
     124            return Version.class.getResourceAsStream(path);
     125        } catch (InvalidPathException e) {
     126            Logging.error("Cannot open {0}: {1}", path, e.getMessage());
     127            URL betterUrl = Utils.betterJarUrl(Version.class.getResource(path));
     128            if (betterUrl != null) {
     129                return betterUrl.openStream();
     130            }
     131            return null;
     132        }
     133    }
     134
    120135    /**
    121136     * Replies the version string. Either the SVN revision "1234" (as string) or the
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r14404 r14406  
    227227            if (name != null && name.startsWith("resource://")) {
    228228                String resourceName = name.substring("resource:/".length());
    229                 InputStream is = getClass().getResourceAsStream(resourceName);
     229                InputStream is = null;
     230                try {
     231                    is = getClass().getResourceAsStream(resourceName);
     232                } catch (InvalidPathException e) {
     233                    Logging.error("Cannot open {0}: {1}", resourceName, e.getMessage());
     234                    Logging.trace(e);
     235                }
    230236                if (is == null) {
    231237                    URL resource = getClass().getResource(resourceName);
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r14013 r14406  
    138138    }
    139139
     140    private static String format(String text, Object... objects) {
     141        try {
     142            return MessageFormat.format(text, objects);
     143        } catch (InvalidPathException e) {
     144            System.err.println("!!! Unable to format '" + text + "': " + e.getMessage());
     145            e.printStackTrace();
     146            return null;
     147        }
     148    }
     149
    140150    /**
    141151     * Translates some text for the current locale.
     
    162172    public static String tr(String text, Object... objects) {
    163173        if (text == null) return null;
    164         return MessageFormat.format(gettext(text, null), objects);
     174        return format(gettext(text, null), objects);
    165175    }
    166176
     
    182192        if (text == null)
    183193            return null;
    184         return MessageFormat.format(gettext(text, context), (Object) null);
     194        return format(gettext(text, context), (Object) null);
    185195    }
    186196
     
    190200        if (text == null)
    191201            return null;
    192         return MessageFormat.format(gettextLazy(text, context), (Object) null);
     202        return format(gettextLazy(text, context), (Object) null);
    193203    }
    194204
     
    235245     */
    236246    public static String trn(String singularText, String pluralText, long n, Object... objects) {
    237         return MessageFormat.format(gettextn(singularText, pluralText, null, n), objects);
     247        return format(gettextn(singularText, pluralText, null, n), objects);
    238248    }
    239249
     
    262272     */
    263273    public static String trnc(String context, String singularText, String pluralText, long n, Object... objects) {
    264         return MessageFormat.format(gettextn(singularText, pluralText, context, n), objects);
     274        return format(gettextn(singularText, pluralText, context, n), objects);
    265275    }
    266276
     
    348358    }
    349359
    350     static void setupJavaLocaleProviders() {
     360    static String setupJavaLocaleProviders() {
    351361        // Look up SPI providers first (for JosmDecimalFormatSymbolsProvider).
    352362        // Enable CLDR locale provider on Java 8 to get additional languages, such as Khmer.
     
    355365        // See https://docs.oracle.com/javase/9/docs/api/java/util/spi/LocaleServiceProvider.html
    356366        try {
    357             // Don't call Utils.updateSystemProperty to avoid spurious log at startup
    358             System.setProperty("java.locale.providers", "SPI,JRE,CLDR");
     367            try {
     368                // First check we're able to open a stream to our own SPI file
     369                // Java will fail on Windows if the jar file is in a folder with a space character!
     370                I18n.class.getResourceAsStream("/META-INF/services/java.text.spi.DecimalFormatSymbolsProvider").close();
     371                // Don't call Utils.updateSystemProperty to avoid spurious log at startup
     372                return System.setProperty("java.locale.providers", "SPI,JRE,CLDR");
     373            } catch (RuntimeException | IOException e) {
     374                // Don't call Logging class, it may not be fully initialized yet
     375                System.err.println("Unable to set SPI locale provider: " + e.getMessage());
     376            }
    359377        } catch (SecurityException e) {
    360378            // Don't call Logging class, it may not be fully initialized yet
    361379            System.err.println("Unable to set locale providers: " + e.getMessage());
    362380        }
     381        return System.setProperty("java.locale.providers", "JRE,CLDR");
    363382    }
    364383
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r14404 r14406  
    3131import java.net.URL;
    3232import java.nio.charset.StandardCharsets;
     33import java.nio.file.InvalidPathException;
    3334import java.util.Arrays;
    3435import java.util.Base64;
     
    11651166            synchronized (getSvgUniverse()) {
    11661167                try {
    1167                     URI uri = getSvgUniverse().loadSVG(path);
     1168                    URI uri = null;
     1169                    try {
     1170                        uri = getSvgUniverse().loadSVG(path);
     1171                    } catch (InvalidPathException e) {
     1172                        Logging.error("Cannot open {0}: {1}", path, e.getMessage());
     1173                        Logging.trace(e);
     1174                    }
    11681175                    if (uri == null && "jar".equals(path.getProtocol())) {
    11691176                        URL betterPath = Utils.betterJarUrl(path);
Note: See TracChangeset for help on using the changeset viewer.