Skip to content

Commit 8520fa5

Browse files
committed
Reduce warnings in WhatWgUrlParser
1 parent f4967f2 commit 8520fa5

File tree

1 file changed

+16
-46
lines changed

1 file changed

+16
-46
lines changed

spring-web/src/main/java/org/springframework/web/util/WhatWgUrlParser.java

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
* @author Arjen Poutsma
5858
* @since 6.2
5959
*/
60+
@SuppressWarnings({"SameParameterValue", "BooleanMethodIsAlwaysInverted"})
6061
final class WhatWgUrlParser {
6162

6263
public static final UrlRecord EMPTY_RECORD = new UrlRecord();
@@ -140,7 +141,7 @@ public static UrlRecord parse(String input, @Nullable UrlRecord base,
140141
/**
141142
* The basic URL parser takes a scalar value string input, with an optional
142143
* null or base URL base (default null), an optional encoding (default UTF-8),
143-
* an optional UrlRecord, and an optional state override.
144+
* and optionally, a UrlRecord and/or State overrides to start from.
144145
*/
145146
private UrlRecord basicUrlParser(@Nullable UrlRecord url, @Nullable State stateOverride) {
146147
// If url is not given:
@@ -471,6 +472,7 @@ private static boolean isNonCharacter(int ch) {
471472
ch == 0xEFFFE || ch == 0xEFFFF || ch == 0xFFFFE || ch == 0xFFFFF || ch == 0x10FFFE || ch == 0x10FFFF);
472473
}
473474

475+
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
474476
private static boolean isUrlCodePoint(int ch) {
475477
return (isAsciiAlphaNumeric(ch) ||
476478
ch == '!' || ch == '$' || ch == '&' || ch == '\'' || ch == '(' || ch == ')' ||
@@ -490,10 +492,8 @@ private static int defaultPort(@Nullable String scheme) {
490492
if (scheme != null) {
491493
return switch (scheme) {
492494
case "ftp" -> 21;
493-
case "http" -> 80;
494-
case "https" -> 443;
495-
case "ws" -> 80;
496-
case "wss" -> 443;
495+
case "http", "ws" -> 80;
496+
case "https", "wss" -> 443;
497497
default -> -1;
498498
};
499499
}
@@ -686,10 +686,9 @@ private static boolean isDoubleDotPathSegment(StringBuilder b) {
686686

687687
/**
688688
* A Windows drive letter is two code points, of which the first is an ASCII alpha
689-
* and the second is either U+003A (:) or U+007C (|).
690-
*
689+
* and the second is either U+003A {@code (:)} or U+007C {@code (|)}.
691690
* A normalized Windows drive letter is a Windows drive letter of which
692-
* the second code point is U+003A (:).
691+
* the second code point is U+003A {@code (:)}.
693692
*/
694693
private static boolean isWindowsDriveLetter(CharSequence input, boolean normalized) {
695694
if (input.length() != 2) {
@@ -699,8 +698,7 @@ private static boolean isWindowsDriveLetter(CharSequence input, boolean normaliz
699698
}
700699

701700
/**
702-
* A string starts with a Windows drive letter if all of the following are true:
703-
*
701+
* A string starts with a Windows drive letter if all the following are true:
704702
* its length is greater than or equal to 2
705703
* its first two code points are a Windows drive letter
706704
* its length is 2 or its third code point is U+002F (/), U+005C (\), U+003F (?), or U+0023 (#).
@@ -1204,7 +1202,6 @@ else if (p.stateOverride != null && p.buffer.isEmpty() &&
12041202
// If state override is given, then return.
12051203
if (p.stateOverride != null) {
12061204
p.stopMainLoop = true;
1207-
return;
12081205
}
12091206
}
12101207
// Otherwise:
@@ -1656,7 +1653,7 @@ public void handle(int c, UrlRecord url, WhatWgUrlParser p) {
16561653
}
16571654
}
16581655
// Otherwise, if c is not the EOF code point:
1659-
else if (c != EOF) {
1656+
else {
16601657
if (p.validate()) {
16611658
// If c is not a URL code point and not U+0025 (%), invalid-URL-unit validation error.
16621659
if (!isUrlCodePoint(c) && c != '%') {
@@ -1769,39 +1766,6 @@ public boolean hasOpaquePath() {
17691766
}
17701767

17711768

1772-
/**
1773-
* The serialization of an origin is the string obtained by applying
1774-
* the following algorithm to the given origin:
1775-
* <ol>
1776-
* <li>If origin is an opaque origin, then return "null".
1777-
* <li>Otherwise, let result be origin's scheme.
1778-
* <li>Append "://" to result.
1779-
* Append origin's host, serialized, to result.
1780-
* <li>If origin's port is non-null, append a U+003A COLON character (:),
1781-
* and origin's port, serialized, to result.
1782-
* <li>Return result.
1783-
* </ol>
1784-
*/
1785-
public String origin() {
1786-
String scheme = scheme();
1787-
if (scheme.equals("ftp") ||
1788-
scheme.equals("http") || scheme.equals("https") ||
1789-
scheme.equals("ws") || scheme.equals("wss")) {
1790-
StringBuilder builder = new StringBuilder(scheme);
1791-
builder.append("://");
1792-
builder.append(host());
1793-
Port port = port();
1794-
if (port != null) {
1795-
builder.append(':');
1796-
builder.append(port);
1797-
}
1798-
return builder.toString();
1799-
}
1800-
else {
1801-
return "null";
1802-
}
1803-
}
1804-
18051769
/**
18061770
* A URL’s scheme is an ASCII string that identifies the type of URL and
18071771
* can be used to dispatch a URL for further processing after parsing.
@@ -1814,6 +1778,7 @@ public String scheme() {
18141778
/**
18151779
* The protocol getter steps are to return this’s URL’s scheme, followed by U+003A (:).
18161780
*/
1781+
@SuppressWarnings("unused")
18171782
public String protocol() {
18181783
return scheme() + ":";
18191784
}
@@ -1899,6 +1864,7 @@ public Host host() {
18991864
* <li>Return url’s host, serialized, followed by U+003A (:) and url’s port, serialized.
19001865
* </ol>
19011866
*/
1867+
@SuppressWarnings("unused")
19021868
public String hostString() {
19031869
if (host() == null) {
19041870
return "";
@@ -2001,6 +1967,7 @@ public String fragment() {
20011967
* <li>Return U+0023 (#), followed by this’s URL’s fragment.
20021968
* </ol>
20031969
*/
1970+
@SuppressWarnings("unused")
20041971
public String hash() {
20051972
String fragment = fragment();
20061973
return (fragment != null && !fragment.isEmpty() ? "#" + fragment : "");
@@ -2248,6 +2215,7 @@ static final class IpAddressHost implements Host {
22482215
}
22492216
}
22502217

2218+
@SuppressWarnings("unused")
22512219
public IpAddress address() {
22522220
return this.address;
22532221
}
@@ -2776,7 +2744,7 @@ else if (c != EOF) {
27762744
}
27772745
// Otherwise, if compress is null and pieceIndex is not 8,
27782746
// IPv6-too-few-pieces validation error, return failure.
2779-
else if (compress == null && pieceIndex != 8) {
2747+
else if (pieceIndex != 8) {
27802748
throw new InvalidUrlException("An uncompressed IPv6 address contains fewer than 8 pieces.");
27812749
}
27822750
// Return address.
@@ -3019,6 +2987,7 @@ public boolean isOpaque() {
30192987
return true;
30202988
}
30212989

2990+
@SuppressWarnings("MethodDoesntCallSuperMethod")
30222991
@Override
30232992
public Path clone() {
30242993
return new PathSegment(segment());
@@ -3103,6 +3072,7 @@ public boolean isOpaque() {
31033072
return false;
31043073
}
31053074

3075+
@SuppressWarnings("MethodDoesntCallSuperMethod")
31063076
@Override
31073077
public Path clone() {
31083078
return new PathSegments(this.segments);

0 commit comments

Comments
 (0)