diff --git a/bundles/org.openhab.core.addon.marketplace.karaf/src/main/java/org/openhab/core/addon/marketplace/karaf/internal/community/CommunityKarafAddonHandler.java b/bundles/org.openhab.core.addon.marketplace.karaf/src/main/java/org/openhab/core/addon/marketplace/karaf/internal/community/CommunityKarafAddonHandler.java index 252e59464cd..28c08c90dff 100644 --- a/bundles/org.openhab.core.addon.marketplace.karaf/src/main/java/org/openhab/core/addon/marketplace/karaf/internal/community/CommunityKarafAddonHandler.java +++ b/bundles/org.openhab.core.addon.marketplace.karaf/src/main/java/org/openhab/core/addon/marketplace/karaf/internal/community/CommunityKarafAddonHandler.java @@ -12,13 +12,13 @@ */ package org.openhab.core.addon.marketplace.karaf.internal.community; -import static org.openhab.core.addon.marketplace.MarketplaceConstants.KAR_CONTENT_TYPE; -import static org.openhab.core.addon.marketplace.MarketplaceConstants.KAR_DOWNLOAD_URL_PROPERTY; +import static org.openhab.core.addon.marketplace.MarketplaceConstants.*; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; @@ -108,13 +108,14 @@ public boolean isInstalled(String addonId) { @Override public void install(Addon addon) throws MarketplaceHandlerException { + URL sourceUrl; try { - URL sourceUrl = new URL((String) addon.getProperties().get(KAR_DOWNLOAD_URL_PROPERTY)); - addKarToCache(addon.getUid(), sourceUrl); - installFromCache(addon.getUid()); - } catch (MalformedURLException e) { + sourceUrl = (new URI((String) addon.getProperties().get(KAR_DOWNLOAD_URL_PROPERTY))).toURL(); + } catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) { throw new MarketplaceHandlerException("Malformed source URL: " + e.getMessage(), e); } + addKarToCache(addon.getUid(), sourceUrl); + installFromCache(addon.getUid()); } @Override diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityBlockLibaryAddonHandler.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityBlockLibaryAddonHandler.java index 67d086cb122..9c495612e6f 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityBlockLibaryAddonHandler.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityBlockLibaryAddonHandler.java @@ -12,12 +12,14 @@ */ package org.openhab.core.addon.marketplace.internal.community; -import static org.openhab.core.addon.marketplace.MarketplaceConstants.BLOCKLIBRARIES_CONTENT_TYPE; -import static org.openhab.core.addon.marketplace.MarketplaceConstants.YAML_DOWNLOAD_URL_PROPERTY; +import static org.openhab.core.addon.marketplace.MarketplaceConstants.*; import static org.openhab.core.addon.marketplace.internal.community.CommunityMarketplaceAddonService.YAML_CONTENT_PROPERTY; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; @@ -102,7 +104,12 @@ public void uninstall(Addon addon) throws MarketplaceHandlerException { } private String getWidgetFromURL(String urlString) throws IOException { - URL u = new URL(urlString); + URL u; + try { + u = (new URI(urlString)).toURL(); + } catch (IllegalArgumentException | URISyntaxException | MalformedURLException e) { + throw new IOException(e); + } try (InputStream in = u.openStream()) { return new String(in.readAllBytes(), StandardCharsets.UTF_8); } diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityBundleAddonHandler.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityBundleAddonHandler.java index 43873788a36..a5f8cdb17ed 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityBundleAddonHandler.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityBundleAddonHandler.java @@ -12,10 +12,11 @@ */ package org.openhab.core.addon.marketplace.internal.community; -import static org.openhab.core.addon.marketplace.MarketplaceConstants.JAR_CONTENT_TYPE; -import static org.openhab.core.addon.marketplace.MarketplaceConstants.JAR_DOWNLOAD_URL_PROPERTY; +import static org.openhab.core.addon.marketplace.MarketplaceConstants.*; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.List; import java.util.concurrent.ScheduledExecutorService; @@ -73,13 +74,14 @@ public boolean isInstalled(String id) { @Override public void install(Addon addon) throws MarketplaceHandlerException { + URL sourceUrl; try { - URL sourceUrl = new URL((String) addon.getProperties().get(JAR_DOWNLOAD_URL_PROPERTY)); - addBundleToCache(addon.getUid(), sourceUrl); - installFromCache(bundleContext, addon.getUid()); - } catch (MalformedURLException e) { + sourceUrl = (new URI((String) addon.getProperties().get(JAR_DOWNLOAD_URL_PROPERTY))).toURL(); + } catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) { throw new MarketplaceHandlerException("Malformed source URL: " + e.getMessage(), e); } + addBundleToCache(addon.getUid(), sourceUrl); + installFromCache(bundleContext, addon.getUid()); } @Override diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java index 17b4796440c..4c305e66442 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java @@ -163,7 +163,7 @@ protected List getRemoteAddons() { try { List pages = new ArrayList<>(); - URL url = new URL(COMMUNITY_MARKETPLACE_URL); + URL url = URI.create(COMMUNITY_MARKETPLACE_URL).toURL(); int pageNb = 1; while (url != null) { URLConnection connection = url.openConnection(); @@ -180,7 +180,7 @@ protected List getRemoteAddons() { if (parsed.topicList.moreTopicsUrl != null) { // Discourse URL for next page is wrong - url = new URL(COMMUNITY_MARKETPLACE_URL + "?page=" + pageNb++); + url = URI.create(COMMUNITY_MARKETPLACE_URL + "?page=" + pageNb++).toURL(); } else { url = null; } @@ -215,7 +215,7 @@ protected List getRemoteAddons() { // retrieve from remote try { - URL url = new URL(String.format("%s%s", COMMUNITY_TOPIC_URL, uid.replace(ADDON_ID_PREFIX, ""))); + URL url = URI.create(String.format("%s%s", COMMUNITY_TOPIC_URL, uid.replace(ADDON_ID_PREFIX, ""))).toURL(); URLConnection connection = url.openConnection(); connection.addRequestProperty("Accept", "application/json"); if (this.apiKey != null) { diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityRuleTemplateAddonHandler.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityRuleTemplateAddonHandler.java index d2b51c2b676..fbb42db3705 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityRuleTemplateAddonHandler.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityRuleTemplateAddonHandler.java @@ -17,6 +17,9 @@ import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; @@ -99,7 +102,12 @@ public void uninstall(Addon addon) throws MarketplaceHandlerException { } private String getTemplateFromURL(String urlString) throws IOException { - URL u = new URL(urlString); + URL u; + try { + u = (new URI(urlString)).toURL(); + } catch (IllegalArgumentException | URISyntaxException | MalformedURLException e) { + throw new IOException(e); + } try (InputStream in = u.openStream()) { return new String(in.readAllBytes(), StandardCharsets.UTF_8); } diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityTransformationAddonHandler.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityTransformationAddonHandler.java index 8761697a9bd..d25ca396ac0 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityTransformationAddonHandler.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityTransformationAddonHandler.java @@ -17,6 +17,9 @@ import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; @@ -131,7 +134,12 @@ public void uninstall(Addon addon) throws MarketplaceHandlerException { } private String downloadTransformation(String urlString) throws IOException { - URL u = new URL(urlString); + URL u; + try { + u = (new URI(urlString)).toURL(); + } catch (IllegalArgumentException | URISyntaxException | MalformedURLException e) { + throw new IOException(e); + } try (InputStream in = u.openStream()) { return new String(in.readAllBytes(), StandardCharsets.UTF_8); } diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityUIWidgetAddonHandler.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityUIWidgetAddonHandler.java index 7181fdf2645..68017cf535b 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityUIWidgetAddonHandler.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityUIWidgetAddonHandler.java @@ -12,12 +12,14 @@ */ package org.openhab.core.addon.marketplace.internal.community; -import static org.openhab.core.addon.marketplace.MarketplaceConstants.UIWIDGETS_CONTENT_TYPE; -import static org.openhab.core.addon.marketplace.MarketplaceConstants.YAML_DOWNLOAD_URL_PROPERTY; +import static org.openhab.core.addon.marketplace.MarketplaceConstants.*; import static org.openhab.core.addon.marketplace.internal.community.CommunityMarketplaceAddonService.YAML_CONTENT_PROPERTY; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; @@ -106,7 +108,12 @@ public void uninstall(Addon addon) throws MarketplaceHandlerException { } private String getWidgetFromURL(String urlString) throws IOException { - URL u = new URL(urlString); + URL u; + try { + u = (new URI(urlString)).toURL(); + } catch (IllegalArgumentException | URISyntaxException | MalformedURLException e) { + throw new IOException(e); + } try (InputStream in = u.openStream()) { return new String(in.readAllBytes(), StandardCharsets.UTF_8); } diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/json/JsonAddonService.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/json/JsonAddonService.java index 465e853428a..8b630666ee4 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/json/JsonAddonService.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/json/JsonAddonService.java @@ -18,7 +18,9 @@ import java.io.InputStreamReader; import java.io.Reader; import java.lang.reflect.Type; +import java.net.MalformedURLException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.util.Arrays; @@ -91,13 +93,23 @@ public JsonAddonService(@Reference EventPublisher eventPublisher, @Reference Sto public void modified(@Nullable Map config) { if (config != null) { String urls = ConfigParser.valueAsOrElse(config.get(CONFIG_URLS), String.class, ""); - addonServiceUrls = Arrays.asList(urls.split("\\|")); + addonServiceUrls = Arrays.asList(urls.split("\\|")).stream().filter(this::isValidUrl).toList(); showUnstable = ConfigParser.valueAsOrElse(config.get(CONFIG_SHOW_UNSTABLE), Boolean.class, false); cachedRemoteAddons.invalidateValue(); refreshSource(); } } + private boolean isValidUrl(String urlString) { + try { + (new URI(urlString)).toURL(); + } catch (IllegalArgumentException | URISyntaxException | MalformedURLException e) { + logger.warn("JSON Addon Service invalid URL: {}", urlString); + return false; + } + return true; + } + @Override @Reference(cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC) protected void addAddonHandler(MarketplaceAddonHandler handler) { @@ -124,7 +136,7 @@ public String getName() { protected List getRemoteAddons() { return addonServiceUrls.stream().map(urlString -> { try { - URL url = new URL(urlString); + URL url = URI.create(urlString).toURL(); URLConnection connection = url.openConnection(); connection.addRequestProperty("Accept", "application/json"); try (Reader reader = new InputStreamReader(connection.getInputStream())) { @@ -139,7 +151,7 @@ protected List getRemoteAddons() { } /** - * Check if the addon UID is present and the entry is eitehr stable or unstable add-ons are requested + * Check if the addon UID is present and the entry is either stable or unstable add-ons are requested * * @param addonEntry the add-on entry to check * @return {@code true} if the add-on entry should be processed, {@code false otherwise} diff --git a/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthClientServiceImpl.java b/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthClientServiceImpl.java index d391371f40b..57ea4744951 100644 --- a/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthClientServiceImpl.java +++ b/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthClientServiceImpl.java @@ -16,6 +16,8 @@ import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.security.GeneralSecurityException; import java.time.Instant; @@ -168,7 +170,7 @@ public String getAuthorizationUrl(@Nullable String redirectURI, @Nullable String public String extractAuthCodeFromAuthResponse(String redirectURLwithParams) throws OAuthException { // parse the redirectURL try { - URL redirectURLObject = new URL(redirectURLwithParams); + URL redirectURLObject = (new URI(redirectURLwithParams)).toURL(); UrlEncoded urlEncoded = new UrlEncoded(redirectURLObject.getQuery()); String stateFromRedirectURL = urlEncoded.getValue(STATE, 0); // may contain multiple... @@ -186,7 +188,7 @@ public String extractAuthCodeFromAuthResponse(String redirectURLwithParams) thro throw new OAuthException(String.format("state from redirectURL is incorrect. Expected: %s Found: %s", persistedParams.state, stateFromRedirectURL)); } - } catch (MalformedURLException e) { + } catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) { throw new OAuthException("Redirect URL is malformed", e); } } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandImport.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandImport.java index 076dcb25c39..eac57ba1d35 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandImport.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandImport.java @@ -14,6 +14,8 @@ import java.io.File; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -101,13 +103,13 @@ public String execute() { */ private @Nullable URL initURL(String parameterValue) { try { - return new URL(parameterValue); - } catch (MalformedURLException mue) { + return (new URI(parameterValue)).toURL(); + } catch (MalformedURLException | URISyntaxException mue) { File f = new File(parameterValue); if (f.isFile()) { try { return f.toURI().toURL(); - } catch (MalformedURLException e) { + } catch (IllegalArgumentException | MalformedURLException e) { } } } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandRemove.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandRemove.java index c6b8ee0ab6f..99f1b03db2e 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandRemove.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandRemove.java @@ -14,6 +14,8 @@ import java.io.File; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -96,13 +98,13 @@ public String execute() { */ private @Nullable URL initURL(String parameterValue) { try { - return new URL(parameterValue); - } catch (MalformedURLException mue) { + return (new URI(parameterValue)).toURL(); + } catch (MalformedURLException | URISyntaxException mue) { File f = new File(parameterValue); if (f.isFile()) { try { return f.toURI().toURL(); - } catch (MalformedURLException e) { + } catch (IllegalArgumentException | MalformedURLException e) { } } } diff --git a/bundles/org.openhab.core.config.discovery.addon.upnp/src/test/java/org/openhab/core/config/discovery/addon/upnp/tests/UpnpAddonFinderTests.java b/bundles/org.openhab.core.config.discovery.addon.upnp/src/test/java/org/openhab/core/config/discovery/addon/upnp/tests/UpnpAddonFinderTests.java index 34079d518f9..64d2a15310d 100644 --- a/bundles/org.openhab.core.config.discovery.addon.upnp/src/test/java/org/openhab/core/config/discovery/addon/upnp/tests/UpnpAddonFinderTests.java +++ b/bundles/org.openhab.core.config.discovery.addon.upnp/src/test/java/org/openhab/core/config/discovery/addon/upnp/tests/UpnpAddonFinderTests.java @@ -12,16 +12,12 @@ */ package org.openhab.core.config.discovery.addon.upnp.tests; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; import java.net.InetAddress; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.net.UnknownHostException; import java.util.ArrayList; @@ -85,7 +81,7 @@ private void setupMockUpnpService() { upnpService = mock(UpnpService.class, Mockito.RETURNS_DEEP_STUBS); URL url = null; try { - url = new URL("http://www.openhab.org/"); + url = URI.create("http://www.openhab.org/").toURL(); } catch (MalformedURLException e) { fail("MalformedURLException"); } diff --git a/bundles/org.openhab.core.ephemeris/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImpl.java b/bundles/org.openhab.core.ephemeris/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImpl.java index 892c071cc55..6dee5c3c7b9 100644 --- a/bundles/org.openhab.core.ephemeris/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImpl.java +++ b/bundles/org.openhab.core.ephemeris/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImpl.java @@ -17,6 +17,7 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; @@ -224,8 +225,8 @@ protected void modified(Map config) { private URL getUrl(String filename) throws FileNotFoundException { if (Files.exists(Paths.get(filename))) { try { - return new URL("file:" + filename); - } catch (MalformedURLException e) { + return (new URI("file:" + filename)).toURL(); + } catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) { throw new FileNotFoundException(e.getMessage()); } } else { diff --git a/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/PEMTrustManager.java b/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/PEMTrustManager.java index 24f1f36509b..e61451d1afa 100644 --- a/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/PEMTrustManager.java +++ b/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/PEMTrustManager.java @@ -19,6 +19,8 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.Socket; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -113,7 +115,11 @@ public static PEMTrustManager getInstanceFromFile(String path) throws FileNotFou * @throws CertificateInstantiationException */ public static PEMTrustManager getInstanceFromServer(String url) throws MalformedURLException, CertificateException { - return getInstanceFromServer(new URL(url)); + try { + return getInstanceFromServer((new URI(url)).toURL()); + } catch (IllegalArgumentException | URISyntaxException e) { + throw new MalformedURLException(e.getMessage()); + } } /** diff --git a/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java b/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java index b1635564f59..3aa763ba386 100644 --- a/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java +++ b/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java @@ -18,6 +18,8 @@ import java.io.IOException; import java.math.BigDecimal; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.time.Instant; @@ -306,8 +308,8 @@ public DummyObject() { private static URL newURL(String url) { try { - return new URL(url); - } catch (MalformedURLException e) { + return (new URI(url)).toURL(); + } catch (MalformedURLException | URISyntaxException e) { throw new IllegalArgumentException(e); } } diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java index 1c4c2646776..888e7c9606b 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java @@ -16,7 +16,6 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.util.Base64; import java.util.Hashtable; import java.util.List; @@ -293,9 +292,15 @@ URI uriFromRequest(HttpServletRequest request) { } private URI createURIFromString(String url) throws MalformedURLException, URISyntaxException { - // URI in this context should be valid URL. Therefore before creating URI, create URL, + URI uri = new URI(url); + // URI in this context should be valid URL. Therefore before returning URI, create URL, // which validates the string. - return new URL(url).toURI(); + try { + uri.toURL(); + } catch (IllegalArgumentException e) { + throw new MalformedURLException(e.getMessage()); + } + return uri; } /** diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java index 410e6b810a1..eccd7dd2d63 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/firmware/FirmwareTest.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.util.Map; @@ -91,7 +92,7 @@ public void testFirmwareBuilder() throws MalformedURLException { String description = "description"; String model = "model"; boolean modelRestricted = true; - URL onlineChangelog = new URL("http://online.changelog"); + URL onlineChangelog = URI.create("http://online.changelog").toURL(); String prerequisiteVersion = "0.0.9"; String md5hash = "123abc"; String vendor = "vendor"; @@ -304,7 +305,7 @@ public void assertDuplicateFirmwaresWithEquals() throws IOException { String description = "description"; String model = "model"; boolean modelRestricted = true; - URL onlineChangelog = new URL("https://secure.com/changelog"); + URL onlineChangelog = URI.create("https://secure.com/changelog").toURL(); String prerequisiteVersion = "0.1"; String vendor = "vendor"; Map properties = Map.of("prop1", "val1", "prop2", "val2"); @@ -330,7 +331,7 @@ public void duplicateFirmwaresHashWithoutRestrictions() throws IOException { String description = "description"; String model = "model"; boolean modelRestricted = true; - URL onlineChangelog = new URL("https://secure.com/changelog"); + URL onlineChangelog = URI.create("https://secure.com/changelog").toURL(); String prerequisiteVersion = "0.1"; String vendor = "vendor"; Map properties = Map.of("prop1", "val1", "prop2", "val2"); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/Constants.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/Constants.java index 8a16b0b1068..3817770b1ba 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/Constants.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/firmware/Constants.java @@ -133,7 +133,7 @@ public class Constants { private static URL newURL(String url) { try { - return new URL(url); + return URI.create(url).toURL(); } catch (MalformedURLException e) { throw new UncheckedIOException(e); }