diff --git a/src/main/java/io/wcm/sling/commons/caservice/impl/ContextAwareServiceTracker.java b/src/main/java/io/wcm/sling/commons/caservice/impl/ContextAwareServiceTracker.java index 8270524..03fdf7a 100644 --- a/src/main/java/io/wcm/sling/commons/caservice/impl/ContextAwareServiceTracker.java +++ b/src/main/java/io/wcm/sling/commons/caservice/impl/ContextAwareServiceTracker.java @@ -39,6 +39,7 @@ class ContextAwareServiceTracker implements Servi private final String serviceClassName; private final BundleContext bundleContext; private final ServiceTracker> serviceTracker; + @SuppressWarnings("java:S3077") // accept volatile private volatile RankedServices> rankedServices; private volatile long lastServiceChange; diff --git a/src/main/java/io/wcm/sling/commons/caservice/impl/ServiceInfo.java b/src/main/java/io/wcm/sling/commons/caservice/impl/ServiceInfo.java index 0a6c1b0..a905c7b 100644 --- a/src/main/java/io/wcm/sling/commons/caservice/impl/ServiceInfo.java +++ b/src/main/java/io/wcm/sling/commons/caservice/impl/ServiceInfo.java @@ -180,10 +180,10 @@ public boolean matches(String resourcePath) { if (resourcePath == null) { return acceptsContextPathEmpty; } - if (contextPathRegex != PATTERN_MATCH_ALL && !contextPathRegex.matcher(resourcePath).matches()) { + else if (contextPathRegex != PATTERN_MATCH_ALL && !contextPathRegex.matcher(resourcePath).matches()) { return false; } - if (contextPathBlacklistRegex != PATTERN_MATCH_ALL && contextPathBlacklistRegex.matcher(resourcePath).matches()) { + else if (contextPathBlacklistRegex != PATTERN_MATCH_ALL && contextPathBlacklistRegex.matcher(resourcePath).matches()) { return false; } return true; diff --git a/src/main/java/io/wcm/sling/commons/osgi/RankedServices.java b/src/main/java/io/wcm/sling/commons/osgi/RankedServices.java index 653d761..ed14dfb 100644 --- a/src/main/java/io/wcm/sling/commons/osgi/RankedServices.java +++ b/src/main/java/io/wcm/sling/commons/osgi/RankedServices.java @@ -38,12 +38,13 @@ * @param Service type * @deprecated Please use org.apache.sling.commons.osgi.RankedServices instead. */ -@Deprecated +@Deprecated(since = "1.0.0") @ProviderType public final class RankedServices implements Iterable { private final ChangeListener changeListener; private final SortedMap, T> serviceMap = new TreeMap<>(); + @SuppressWarnings("java:S3077") // accept volatile private volatile Collection sortedServices = Collections.emptyList(); /** diff --git a/src/main/java/io/wcm/sling/commons/request/QueryStringBuilder.java b/src/main/java/io/wcm/sling/commons/request/QueryStringBuilder.java index 259255b..12c9eb9 100644 --- a/src/main/java/io/wcm/sling/commons/request/QueryStringBuilder.java +++ b/src/main/java/io/wcm/sling/commons/request/QueryStringBuilder.java @@ -93,9 +93,9 @@ else if (isArray(value)) { if (queryString.length() > 0) { queryString.append(PARAM_SEPARATOR); } - queryString.append(Escape.urlEncode(param.getName())); - queryString.append(VALUE_SEPARATOR); - queryString.append(Escape.urlEncode(param.getValue())); + queryString.append(Escape.urlEncode(param.getName())) + .append(VALUE_SEPARATOR) + .append(Escape.urlEncode(param.getValue())); } if (queryString.length() > 0) { diff --git a/src/main/java/io/wcm/sling/commons/request/RequestParam.java b/src/main/java/io/wcm/sling/commons/request/RequestParam.java index 30a5289..5864eb6 100644 --- a/src/main/java/io/wcm/sling/commons/request/RequestParam.java +++ b/src/main/java/io/wcm/sling/commons/request/RequestParam.java @@ -274,7 +274,7 @@ public static boolean getBoolean(@NotNull ServletRequest request, @NotNull Strin @SuppressWarnings("unchecked") public static @Nullable T getEnum(@NotNull ServletRequest request, @NotNull String param, @NotNull Class enumClass, @Nullable T defaultValue) { - String value = RequestParam.get(request, param); + String value = get(request, param); if (StringUtils.isNotEmpty(value)) { try { return (T)Enum.valueOf(enumClass, value); diff --git a/src/main/java/io/wcm/sling/commons/resource/ImmutableValueMap.java b/src/main/java/io/wcm/sling/commons/resource/ImmutableValueMap.java index 7b503d0..a007cea 100644 --- a/src/main/java/io/wcm/sling/commons/resource/ImmutableValueMap.java +++ b/src/main/java/io/wcm/sling/commons/resource/ImmutableValueMap.java @@ -133,7 +133,7 @@ public String toString() { * @deprecated Unsupported operation */ @Override - @Deprecated + @Deprecated(since = "1.0.0") public Object put(String key, Object value) { throw new UnsupportedOperationException(); } @@ -142,7 +142,7 @@ public Object put(String key, Object value) { * @deprecated Unsupported operation */ @Override - @Deprecated + @Deprecated(since = "1.0.0") public Object remove(Object key) { throw new UnsupportedOperationException(); } @@ -151,7 +151,7 @@ public Object remove(Object key) { * @deprecated Unsupported operation */ @Override - @Deprecated + @Deprecated(since = "1.0.0") public void putAll(Map m) { throw new UnsupportedOperationException(); } @@ -160,7 +160,7 @@ public void putAll(Map m) { * @deprecated Unsupported operation */ @Override - @Deprecated + @Deprecated(since = "1.0.0") public void clear() { throw new UnsupportedOperationException(); } @@ -173,7 +173,7 @@ public void clear() { * @return ImmutableValueMap */ public static @NotNull ImmutableValueMap of() { - return new ImmutableValueMap(ValueMap.EMPTY); + return new ImmutableValueMap(EMPTY); } /** @@ -364,7 +364,7 @@ public static final class Builder { */ public @NotNull ImmutableValueMap build() { if (map.isEmpty()) { - return ImmutableValueMap.of(); + return of(); } else { return new ImmutableValueMap(map); diff --git a/src/main/java/io/wcm/sling/commons/resource/ResourcePath.java b/src/main/java/io/wcm/sling/commons/resource/ResourcePath.java index 23cfa5a..1cd4676 100644 --- a/src/main/java/io/wcm/sling/commons/resource/ResourcePath.java +++ b/src/main/java/io/wcm/sling/commons/resource/ResourcePath.java @@ -26,7 +26,7 @@ * Helper methods for resource path handling. * @deprecated Use io.wcm.wcm.commons.util.Path instead. */ -@Deprecated +@Deprecated(since = "1.2.0") public final class ResourcePath { private ResourcePath() { diff --git a/src/main/java/io/wcm/sling/commons/resource/ResourceType.java b/src/main/java/io/wcm/sling/commons/resource/ResourceType.java index 01e1099..79dfb1b 100644 --- a/src/main/java/io/wcm/sling/commons/resource/ResourceType.java +++ b/src/main/java/io/wcm/sling/commons/resource/ResourceType.java @@ -45,14 +45,14 @@ private ResourceType() { * /apps prefix for resource types * @deprecated Search paths are confurable and should not be hard-coded. */ - @Deprecated + @Deprecated(since = "1.1.0") public static final String APPS_PREFIX = "/apps/"; /** * /libs prefix for resource types * @deprecated Search paths are confurable and should not be hard-coded. */ - @Deprecated + @Deprecated(since = "1.1.0") public static final String LIBS_PREFIX = "/libs/"; /** @@ -115,7 +115,7 @@ private ResourceType() { * @return Relative resource type * @deprecated Please use {@link #makeRelative(String, ResourceResolver)} instead. */ - @Deprecated + @Deprecated(since = "1.1.0") public static @NotNull String makeRelative(@NotNull String resourceType) { if (StringUtils.startsWith(resourceType, APPS_PREFIX)) { return resourceType.substring(APPS_PREFIX.length()); @@ -149,7 +149,7 @@ public static boolean equals(@NotNull String resourceType, @NotNull String anoth * @return true if the resource type equals the given resource type. * @deprecated Please use {@link #equals(String, String, ResourceResolver)} instead. */ - @Deprecated + @Deprecated(since = "1.1.0") public static boolean equals(@NotNull String resourceType, @NotNull String anotherResourceType) { return StringUtils.equals(makeRelative(resourceType), makeRelative(anotherResourceType)); } diff --git a/src/test/java/io/wcm/sling/commons/caservice/impl/ContextAwareServiceInventoryPrinterTest.java b/src/test/java/io/wcm/sling/commons/caservice/impl/ContextAwareServiceInventoryPrinterTest.java index 8af00c8..aba8f81 100644 --- a/src/test/java/io/wcm/sling/commons/caservice/impl/ContextAwareServiceInventoryPrinterTest.java +++ b/src/test/java/io/wcm/sling/commons/caservice/impl/ContextAwareServiceInventoryPrinterTest.java @@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; @@ -56,13 +55,13 @@ protected void setUp() { } @Test - void testNoServiceTracker() throws IOException { + void testNoServiceTracker() { String result = getResultFromInventoryPrinter(Format.TEXT); assertTrue(StringUtils.contains(result, "No context-aware services found.")); } @Test - void testWithServiceTracker() throws IOException { + void testWithServiceTracker() { // make dummy call to have a service tracker registered contextAwareServiceResolver.resolve(DummySpi.class, null); @@ -71,12 +70,12 @@ void testWithServiceTracker() throws IOException { } @Test - void testNonText() throws IOException { + void testNonText() { String result = getResultFromInventoryPrinter(Format.HTML); assertTrue(StringUtils.isEmpty(result)); } - private String getResultFromInventoryPrinter(Format format) throws IOException { + private String getResultFromInventoryPrinter(Format format) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(bos); underTest.print(pw, format, false); diff --git a/src/test/java/io/wcm/sling/commons/request/RequestParamTest.java b/src/test/java/io/wcm/sling/commons/request/RequestParamTest.java index f1ea73e..c96bedf 100644 --- a/src/test/java/io/wcm/sling/commons/request/RequestParamTest.java +++ b/src/test/java/io/wcm/sling/commons/request/RequestParamTest.java @@ -65,7 +65,7 @@ class RequestParamTest { private MockSlingHttpServletRequest request; @BeforeEach - void setUp() throws Exception { + void setUp() { request = context.request(); paramMap = getParamMap(); request.setParameterMap(paramMap); diff --git a/src/test/java/io/wcm/sling/commons/request/RequestPathTest.java b/src/test/java/io/wcm/sling/commons/request/RequestPathTest.java index 11947dc..693fe85 100644 --- a/src/test/java/io/wcm/sling/commons/request/RequestPathTest.java +++ b/src/test/java/io/wcm/sling/commons/request/RequestPathTest.java @@ -41,7 +41,7 @@ class RequestPathTest { private RequestPathInfo requestPathInfo; @BeforeEach - void setUp() throws Exception { + void setUp() { when(request.getRequestPathInfo()).thenReturn(requestPathInfo); } diff --git a/src/test/java/io/wcm/sling/commons/request/impl/RequestContextFilterImplTest.java b/src/test/java/io/wcm/sling/commons/request/impl/RequestContextFilterImplTest.java index 1065d93..b1574da 100644 --- a/src/test/java/io/wcm/sling/commons/request/impl/RequestContextFilterImplTest.java +++ b/src/test/java/io/wcm/sling/commons/request/impl/RequestContextFilterImplTest.java @@ -56,7 +56,7 @@ void setUp() { } @Test - void testFilter() throws Exception { + void testFilter() throws IOException, ServletException { assertNull(underTest.getThreadRequest()); underTest.doFilter(request, response, new FilterChain() { @@ -70,7 +70,7 @@ public void doFilter(ServletRequest req, ServletResponse resp) { } @Test - void testFilterNested() throws Exception { + void testFilterNested() throws IOException, ServletException { assertNull(underTest.getThreadRequest()); underTest.doFilter(request, response, new FilterChain() { @@ -97,7 +97,7 @@ public void doFilter(ServletRequest req2, ServletResponse resp2) { } @Test - void testWithExeption() throws Exception { + void testWithExeption() throws IOException { assertNull(underTest.getThreadRequest()); try { diff --git a/src/test/java/io/wcm/sling/commons/resource/ImmutableValueMapTest.java b/src/test/java/io/wcm/sling/commons/resource/ImmutableValueMapTest.java index e84c70e..2210c6b 100644 --- a/src/test/java/io/wcm/sling/commons/resource/ImmutableValueMapTest.java +++ b/src/test/java/io/wcm/sling/commons/resource/ImmutableValueMapTest.java @@ -92,10 +92,11 @@ void testMapPut() { @Test void testMapPutAll() { + Map input = Map.of( + "prop4", 25, + "prop5", 33); assertThrows(UnsupportedOperationException.class, () -> { - underTest.putAll(Map.of( - "prop4", 25, - "prop5", 33)); + underTest.putAll(input); }); } diff --git a/src/test/java/io/wcm/sling/commons/util/EscapeTest.java b/src/test/java/io/wcm/sling/commons/util/EscapeTest.java index 1c62314..5123de7 100644 --- a/src/test/java/io/wcm/sling/commons/util/EscapeTest.java +++ b/src/test/java/io/wcm/sling/commons/util/EscapeTest.java @@ -87,7 +87,7 @@ void testJcrQueryLiteralNull() { } @Test - void testJcrQueryContainsExpr() throws Exception { + void testJcrQueryContainsExpr() { assertEquals("'abc'", Escape.jcrQueryContainsExpr("abc")); assertEquals("'a''bc'", Escape.jcrQueryContainsExpr("a'bc")); assertEquals("'a''bc'''''", Escape.jcrQueryContainsExpr("a'bc''"));