From 27e3049b230294f6e10b1641c8fd5fd1c7a6beb8 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Thu, 17 Apr 2025 10:41:01 +0200 Subject: [PATCH] replace remaining URL() constructors --- .../org/opengrok/indexer/web/UtilTest.java | 33 ++++++++++--------- .../v1/controller/SuggesterController.java | 9 ++--- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java index 44eb30dca4c..b7b413f52c3 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java @@ -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; @@ -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> params = Util.getQueryParams(url); assertEquals(1, params.size()); @@ -571,8 +572,8 @@ void getQueryParamsSingleTest() throws MalformedURLException { } @Test - void getQueryParamsMultipleTest() throws MalformedURLException { - URL url = new URL("http://test.com?param1=value1¶m2=value2"); + void getQueryParamsMultipleTest() throws MalformedURLException, URISyntaxException { + URL url = new URI("http://test.com?param1=value1¶m2=value2").toURL(); Map> params = Util.getQueryParams(url); assertEquals(2, params.size()); @@ -582,8 +583,8 @@ void getQueryParamsMultipleTest() throws MalformedURLException { } @Test - void getQueryParamsMultipleSameTest() throws MalformedURLException { - URL url = new URL("http://test.com?param1=value1¶m1=value2"); + void getQueryParamsMultipleSameTest() throws MalformedURLException, URISyntaxException { + URL url = new URI("http://test.com?param1=value1¶m1=value2").toURL(); Map> params = Util.getQueryParams(url); assertEquals(1, params.size()); @@ -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> params = Util.getQueryParams(url); assertEquals(1, params.size()); @@ -602,8 +603,8 @@ 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> params = Util.getQueryParams(url); @@ -611,8 +612,8 @@ void getQueryParamsEmptyValueTest() throws MalformedURLException { } @Test - void getQueryParamsEmptyAndNormalValuesCombinedTest() throws MalformedURLException { - URL url = new URL("http://test.com?param1=value1¶m2=¶m3¶m4=value4"); + void getQueryParamsEmptyAndNormalValuesCombinedTest() throws MalformedURLException, URISyntaxException { + URL url = new URI("http://test.com?param1=value1¶m2=¶m3¶m4=value4").toURL(); Map> params = Util.getQueryParams(url); diff --git a/opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SuggesterController.java b/opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SuggesterController.java index 926be5d02b2..5f204172d2e 100644 --- a/opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SuggesterController.java +++ b/opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SuggesterController.java @@ -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 . */ package org.opengrok.web.api.v1.controller; @@ -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; @@ -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 urls) { + public void addSearchCountsQueries(final List 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");