Ignore:
Timestamp:
2018-12-01T21:27:53+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #16937 - Support user logins ending by " !"

File:
1 edited

Legend:

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

    r14404 r14480  
    18711871     */
    18721872    public static URL betterJarUrl(URL jarUrl) throws IOException {
     1873        return betterJarUrl(jarUrl, null);
     1874    }
     1875
     1876    /**
     1877     * Tries to build a better JAR URL if we find it concerned by a JDK bug.
     1878     * @param jarUrl jar URL to test
     1879     * @param defaultUrl default URL to return
     1880     * @return potentially a better URL that won't provoke a JDK bug, or {@code defaultUrl}
     1881     * @throws IOException if an I/O error occurs
     1882     * @since 14480
     1883     */
     1884    public static URL betterJarUrl(URL jarUrl, URL defaultUrl) throws IOException {
    18731885        // Workaround to https://bugs.openjdk.java.net/browse/JDK-4523159
    18741886        String urlPath = jarUrl.getPath().replace("%20", " ");
     
    18881900            return new URL(jarUrl.getProtocol() + ':' + jarCopy.toUri().toURL().toExternalForm() + urlPath.substring(index));
    18891901        }
    1890         return null;
     1902        return defaultUrl;
     1903    }
     1904
     1905    /**
     1906     * Finds a resource with a given name, with robustness to known JDK bugs.
     1907     * @param klass class on which {@link Class#getResourceAsStream} will be called
     1908     * @param path name of the desired resource
     1909     * @return  A {@link java.io.InputStream} object or {@code null} if no resource with this name is found
     1910     * @since 14480
     1911     */
     1912    public static InputStream getResourceAsStream(Class<?> klass, String path) {
     1913        try {
     1914            return klass.getResourceAsStream(path);
     1915        } catch (InvalidPathException e) {
     1916            Logging.error("Cannot open {0}: {1}", path, e.getMessage());
     1917            try {
     1918                URL betterUrl = betterJarUrl(klass.getResource(path));
     1919                if (betterUrl != null) {
     1920                    return betterUrl.openStream();
     1921                }
     1922            } catch (IOException ex) {
     1923                Logging.error(ex);
     1924            }
     1925            return null;
     1926        }
    18911927    }
    18921928}
Note: See TracChangeset for help on using the changeset viewer.