Skip to content

replace remaining URL() constructors #4763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.StringWriter;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -549,20 +550,20 @@ void getQueryParamsNullTest() {
}

@Test
void getQueryParamsEmptyTest() throws MalformedURLException {
URL url = new URL("http://test.com/test");
void getQueryParamsEmptyTest() throws MalformedURLException, URISyntaxException {
URL url = new URI("http://test.com/test").toURL();
assertTrue(Util.getQueryParams(url).isEmpty());
}

@Test
void getQueryParamsEmptyTest2() throws MalformedURLException {
URL url = new URL("http://test.com/test?");
void getQueryParamsEmptyTest2() throws MalformedURLException, URISyntaxException {
URL url = new URI("http://test.com/test?").toURL();
assertTrue(Util.getQueryParams(url).isEmpty());
}

@Test
void getQueryParamsSingleTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=value1");
void getQueryParamsSingleTest() throws MalformedURLException, URISyntaxException {
URL url = new URI("http://test.com?param1=value1").toURL();
Map<String, List<String>> params = Util.getQueryParams(url);

assertEquals(1, params.size());
Expand All @@ -571,8 +572,8 @@ void getQueryParamsSingleTest() throws MalformedURLException {
}

@Test
void getQueryParamsMultipleTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=value1&param2=value2");
void getQueryParamsMultipleTest() throws MalformedURLException, URISyntaxException {
URL url = new URI("http://test.com?param1=value1&param2=value2").toURL();
Map<String, List<String>> params = Util.getQueryParams(url);

assertEquals(2, params.size());
Expand All @@ -582,8 +583,8 @@ void getQueryParamsMultipleTest() throws MalformedURLException {
}

@Test
void getQueryParamsMultipleSameTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=value1&param1=value2");
void getQueryParamsMultipleSameTest() throws MalformedURLException, URISyntaxException {
URL url = new URI("http://test.com?param1=value1&param1=value2").toURL();
Map<String, List<String>> params = Util.getQueryParams(url);

assertEquals(1, params.size());
Expand All @@ -592,8 +593,8 @@ void getQueryParamsMultipleSameTest() throws MalformedURLException {
}

@Test
void getQueryParamsEncodedTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=%3Fvalue%3F");
void getQueryParamsEncodedTest() throws MalformedURLException, URISyntaxException {
URL url = new URI("http://test.com?param1=%3Fvalue%3F").toURL();
Map<String, List<String>> params = Util.getQueryParams(url);

assertEquals(1, params.size());
Expand All @@ -602,17 +603,17 @@ void getQueryParamsEncodedTest() throws MalformedURLException {
}

@Test
void getQueryParamsEmptyValueTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=");
void getQueryParamsEmptyValueTest() throws MalformedURLException, URISyntaxException {
URL url = new URI("http://test.com?param1=").toURL();

Map<String, List<String>> params = Util.getQueryParams(url);

assertThat(params.get("param1"), contains(""));
}

@Test
void getQueryParamsEmptyAndNormalValuesCombinedTest() throws MalformedURLException {
URL url = new URL("http://test.com?param1=value1&param2=&param3&param4=value4");
void getQueryParamsEmptyAndNormalValuesCombinedTest() throws MalformedURLException, URISyntaxException {
URL url = new URI("http://test.com?param1=value1&param2=&param3&param4=value4").toURL();

Map<String, List<String>> params = Util.getQueryParams(url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
*/
package org.opengrok.web.api.v1.controller;
Expand Down Expand Up @@ -63,7 +63,8 @@
import org.opengrok.web.api.v1.suggester.provider.service.SuggesterService;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;
import java.time.Instant;
import java.util.AbstractMap.SimpleEntry;
Expand Down Expand Up @@ -194,10 +195,10 @@ public void rebuild(@PathParam("project") final String project) {
@POST
@Path("/init/queries")
@Consumes(MediaType.APPLICATION_JSON)
public void addSearchCountsQueries(final List<String> urls) {
public void addSearchCountsQueries(final List<String> urls) throws URISyntaxException {
for (String urlStr : urls) {
try {
var url = new URL(urlStr);
var url = new URI(urlStr).toURL();
var params = Util.getQueryParams(url);

var projects = params.get("project");
Expand Down
Loading