1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 12:02:05 +01:00

Remove usage of deprecated URL constructor

Although those URL constructors are only deprecated with Java 20, this
already removes their usage.
This commit is contained in:
Florian Schmaus 2024-10-15 15:45:47 +02:00
parent 8b9cd98756
commit 0ee5acc494
6 changed files with 33 additions and 13 deletions

View file

@ -18,6 +18,7 @@ package org.jivesoftware.smack;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -35,7 +36,7 @@ public class Smack {
static { static {
try { try {
BUG_REPORT_URL = new URL("https://discourse.igniterealtime.org/c/smack/smack-support/9"); BUG_REPORT_URL = URI.create("https://discourse.igniterealtime.org/c/smack/smack-support/9").toURL();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new ExceptionInInitializerError(e); throw new ExceptionInInitializerError(e);
} }

View file

@ -18,6 +18,7 @@
package org.jivesoftware.smack; package org.jivesoftware.smack;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -60,7 +61,7 @@ public final class SmackConfiguration {
static { static {
try { try {
SMACK_URL = new URL(SMACK_URL_STRING); SMACK_URL = URI.create(SMACK_URL_STRING).toURL();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }

View file

@ -117,7 +117,7 @@ public final class HttpLookupMethod {
*/ */
public static InputStream getXrdStream(DomainBareJid xmppServiceAddress) throws IOException { public static InputStream getXrdStream(DomainBareJid xmppServiceAddress) throws IOException {
final String metadataUrl = "https://" + xmppServiceAddress + "/.well-known/host-meta"; final String metadataUrl = "https://" + xmppServiceAddress + "/.well-known/host-meta";
final URL putUrl = new URL(metadataUrl); final URL putUrl = URI.create(metadataUrl).toURL();
final URLConnection urlConnection = putUrl.openConnection(); final URLConnection urlConnection = putUrl.openConnection();
return urlConnection.getInputStream(); return urlConnection.getInputStream();
} }

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2019-2021 Florian Schmaus * Copyright 2019-2024 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,10 +20,15 @@ import java.io.IOException;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable; import java.lang.reflect.TypeVariable;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.ParseException; import java.text.ParseException;
import org.jivesoftware.smack.packet.Element; import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.parsing.SmackParsingException; import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.parsing.SmackParsingException.SmackUriSyntaxParsingException;
import org.jivesoftware.smack.xml.XmlPullParserException; import org.jivesoftware.smack.xml.XmlPullParserException;
public class AbstractProvider<E extends Element> { public class AbstractProvider<E extends Element> {
@ -106,4 +111,14 @@ public class AbstractProvider<E extends Element> {
return e; return e;
} }
public static URL toUrl(String string) throws SmackUriSyntaxParsingException, MalformedURLException {
URI uri;
try {
uri = new URI(string);
} catch (URISyntaxException e) {
throw new SmackUriSyntaxParsingException(e);
}
return uri.toURL();
}
} }

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright © 2017 Grigory Fedorov, 2017-2019 Florian Schmaus * Copyright © 2017 Grigory Fedorov, 2017-2024 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,12 +17,14 @@
package org.jivesoftware.smackx.httpfileupload.provider; package org.jivesoftware.smackx.httpfileupload.provider;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.jivesoftware.smack.packet.IqData; import org.jivesoftware.smack.packet.IqData;
import org.jivesoftware.smack.packet.XmlEnvironment; import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException.SmackUriSyntaxParsingException;
import org.jivesoftware.smack.provider.IqProvider; import org.jivesoftware.smack.provider.IqProvider;
import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser; import org.jivesoftware.smack.xml.XmlPullParser;
@ -42,7 +44,7 @@ import org.jivesoftware.smackx.httpfileupload.element.Slot_V0_2;
public class SlotProvider extends IqProvider<Slot> { public class SlotProvider extends IqProvider<Slot> {
@Override @Override
public Slot parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { public Slot parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackUriSyntaxParsingException {
final String namespace = parser.getNamespace(); final String namespace = parser.getNamespace();
final UploadService.Version version = HttpFileUploadManager.namespaceToVersion(namespace); final UploadService.Version version = HttpFileUploadManager.namespaceToVersion(namespace);
@ -63,7 +65,7 @@ public class SlotProvider extends IqProvider<Slot> {
switch (version) { switch (version) {
case v0_2: case v0_2:
String putUrlString = parser.nextText(); String putUrlString = parser.nextText();
putUrl = new URL(putUrlString); putUrl = toUrl(putUrlString);
break; break;
case v0_3: case v0_3:
putElementV04Content = parsePutElement_V0_4(parser); putElementV04Content = parsePutElement_V0_4(parser);
@ -85,7 +87,7 @@ public class SlotProvider extends IqProvider<Slot> {
default: default:
throw new AssertionError(); throw new AssertionError();
} }
getUrl = new URL(getUrlString); getUrl = toUrl(getUrlString);
break; break;
} }
break; break;
@ -114,7 +116,7 @@ public class SlotProvider extends IqProvider<Slot> {
final int initialDepth = parser.getDepth(); final int initialDepth = parser.getDepth();
String putUrlString = parser.getAttributeValue(null, "url"); String putUrlString = parser.getAttributeValue(null, "url");
URL putUrl = new URL(putUrlString); URL putUrl = URI.create(putUrlString).toURL();
Map<String, String> headers = null; Map<String, String> headers = null;
outerloop: while (true) { outerloop: while (true) {

View file

@ -18,10 +18,11 @@
package org.jivesoftware.smackx.muc; package org.jivesoftware.smackx.muc;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
@ -215,9 +216,9 @@ public class RoomInfo {
if (urlField != null && !urlField.getValues().isEmpty()) { if (urlField != null && !urlField.getValues().isEmpty()) {
String urlString = urlField.getFirstValue(); String urlString = urlField.getFirstValue();
try { try {
logs = new URL(urlString); logs = new URI(urlString).toURL();
} catch (MalformedURLException e) { } catch (MalformedURLException | URISyntaxException e) {
LOGGER.log(Level.SEVERE, "Could not parse URL", e); throw new IllegalArgumentException("Could not parse '" + urlString + "' to URL", e);
} }
} }