Skip to content

Commit cbdb349

Browse files
committed
replace remaining URL() constructors
1 parent e84d396 commit cbdb349

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.StringWriter;
2929
import java.io.Writer;
3030
import java.net.MalformedURLException;
31+
import java.net.URI;
3132
import java.net.URISyntaxException;
3233
import java.net.URL;
3334
import java.nio.charset.StandardCharsets;
@@ -549,20 +550,20 @@ void getQueryParamsNullTest() {
549550
}
550551

551552
@Test
552-
void getQueryParamsEmptyTest() throws MalformedURLException {
553-
URL url = new URL("http://test.com/test");
553+
void getQueryParamsEmptyTest() throws MalformedURLException, URISyntaxException {
554+
URL url = new URI("http://test.com/test").toURL();
554555
assertTrue(Util.getQueryParams(url).isEmpty());
555556
}
556557

557558
@Test
558-
void getQueryParamsEmptyTest2() throws MalformedURLException {
559-
URL url = new URL("http://test.com/test?");
559+
void getQueryParamsEmptyTest2() throws MalformedURLException, URISyntaxException {
560+
URL url = new URI("http://test.com/test?").toURL();
560561
assertTrue(Util.getQueryParams(url).isEmpty());
561562
}
562563

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

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

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

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

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

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

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

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

604605
@Test
605-
void getQueryParamsEmptyValueTest() throws MalformedURLException {
606-
URL url = new URL("http://test.com?param1=");
606+
void getQueryParamsEmptyValueTest() throws MalformedURLException, URISyntaxException {
607+
URL url = new URI("http://test.com?param1=").toURL();
607608

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

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

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

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

opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SuggesterController.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2020, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.web.api.v1.controller;
@@ -63,7 +63,8 @@
6363
import org.opengrok.web.api.v1.suggester.provider.service.SuggesterService;
6464

6565
import java.net.MalformedURLException;
66-
import java.net.URL;
66+
import java.net.URI;
67+
import java.net.URISyntaxException;
6768
import java.time.Duration;
6869
import java.time.Instant;
6970
import java.util.AbstractMap.SimpleEntry;
@@ -194,10 +195,10 @@ public void rebuild(@PathParam("project") final String project) {
194195
@POST
195196
@Path("/init/queries")
196197
@Consumes(MediaType.APPLICATION_JSON)
197-
public void addSearchCountsQueries(final List<String> urls) {
198+
public void addSearchCountsQueries(final List<String> urls) throws URISyntaxException {
198199
for (String urlStr : urls) {
199200
try {
200-
var url = new URL(urlStr);
201+
var url = new URI(urlStr).toURL();
201202
var params = Util.getQueryParams(url);
202203

203204
var projects = params.get("project");

0 commit comments

Comments
 (0)