Skip to content

Commit

Permalink
Remove deprecated URI constructor usage for newer JVMs
Browse files Browse the repository at this point in the history
  • Loading branch information
jshiell committed Oct 19, 2024
1 parent b5c5ea9 commit 0b2bfbf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -215,9 +212,9 @@ private List<URL> getUrls(@NotNull final ClassLoader sourceClassLoader) {
} else {
URL classResource = CheckstyleClassLoaderContainer.class.getResource("CheckstyleClassLoaderContainer.class");
try {
URL trimmedUrl = new URL(Objects.requireNonNull(classResource).toString().replaceFirst("org[/\\\\]infernus.*", ""));
result = Collections.singletonList(trimmedUrl);
} catch (MalformedURLException e) {
URI trimmedUrl = URI.create(Objects.requireNonNull(classResource).toString().replaceFirst("org[/\\\\]infernus.*", ""));
result = Collections.singletonList(trimmedUrl.toURL());
} catch (IllegalArgumentException | MalformedURLException e) {
result = Collections.singletonList(classResource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
Expand Down Expand Up @@ -62,7 +63,7 @@ protected InputStream resolveFile(@NotNull final ClassLoader checkstyleClassLoad

@NotNull
URLConnection connectionTo(final String location) throws IOException {
final URL url = new URL(location);
final URL url = URI.create(location).toURL();

final URLConnection urlConnection = url.openConnection();
urlConnection.setConnectTimeout(HTTP_TIMEOUT_IN_MS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jetbrains.annotations.Nullable;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.Objects;

Expand All @@ -38,7 +39,7 @@ public Object execute(@NotNull final Project project,
public void actionPerformed(@NotNull final AnActionEvent event,
@NotNull final Notification notification) {
try {
final URL updateUrl = new URL("https://github.com/jshiell/checkstyle-idea/releases/tag/%s".formatted(version()));
final URL updateUrl = URI.create("https://github.com/jshiell/checkstyle-idea/releases/tag/%s".formatted(version())).toURL();
IdeUiService.getInstance().browse(updateUrl);
notification.expire();
} catch (MalformedURLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import org.jetbrains.annotations.NotNull;

import java.io.Serial;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import javax.swing.table.AbstractTableModel;
import java.util.*;

Expand Down Expand Up @@ -176,15 +175,15 @@ public Object getValueAt(final int rowIndex, final int columnIndex) {
case COLUMN_FILE:
String locationFile = locations.get(rowIndex).getLocation();
try {
String userInfo = new URL(locationFile).getUserInfo();
String userInfo = URI.create(locationFile).getUserInfo();
if (userInfo != null) {
return locationFile.replace(
userInfo,
userInfo.replaceAll("(.*):(.*)", "$1:*****")
);
}
return locationFile;
} catch (MalformedURLException e) {
} catch (IllegalArgumentException e) {
return locationFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Enumeration;
import java.util.List;
Expand All @@ -28,9 +29,9 @@ public class ResourceFilteringURLClassLoaderTest {

@Before
public void prepareParentClassLoader() throws IOException {
passedUrl = new URL("file:///passed.file");
passedUrl = URI.create("file:///passed.file").toURL();

when(parentClassLoader.getResource(FILTERED_FILE)).thenReturn(new URL("file:///filtered.file"));
when(parentClassLoader.getResource(FILTERED_FILE)).thenReturn(URI.create("file:///filtered.file").toURL());
when(parentClassLoader.getResource(PASSED_FILE)).thenReturn(passedUrl);
when(parentClassLoader.getResources(PASSED_FILE)).thenReturn(enumeration(List.of(passedUrl)));
}
Expand Down

0 comments on commit 0b2bfbf

Please sign in to comment.