Skip to content

Commit

Permalink
eliminate code warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jul 8, 2024
1 parent 49b4eff commit e0aa445
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ContextAwareServiceTracker<S extends ContextAwareService> implements Servi
private final String serviceClassName;
private final BundleContext bundleContext;
private final ServiceTracker<S, ServiceInfo<S>> serviceTracker;
@SuppressWarnings("java:S3077") // accept volatile
private volatile RankedServices<ServiceInfo<S>> rankedServices;
private volatile long lastServiceChange;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/wcm/sling/commons/osgi/RankedServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
* @param <T> Service type
* @deprecated Please use <code>org.apache.sling.commons.osgi.RankedServices</code> instead.
*/
@Deprecated
@Deprecated(since = "1.0.0")
@ProviderType
public final class RankedServices<T> implements Iterable<T> {

private final ChangeListener changeListener;
private final SortedMap<Comparable<Object>, T> serviceMap = new TreeMap<>();
@SuppressWarnings("java:S3077") // accept volatile
private volatile Collection<T> sortedServices = Collections.emptyList();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static boolean getBoolean(@NotNull ServletRequest request, @NotNull Strin
@SuppressWarnings("unchecked")
public static <T extends Enum> @Nullable T getEnum(@NotNull ServletRequest request, @NotNull String param, @NotNull Class<T> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -151,7 +151,7 @@ public Object remove(Object key) {
* @deprecated Unsupported operation
*/
@Override
@Deprecated
@Deprecated(since = "1.0.0")
public void putAll(Map<? extends String, ? extends Object> m) {
throw new UnsupportedOperationException();
}
Expand All @@ -160,7 +160,7 @@ public void putAll(Map<? extends String, ? extends Object> m) {
* @deprecated Unsupported operation
*/
@Override
@Deprecated
@Deprecated(since = "1.0.0")
public void clear() {
throw new UnsupportedOperationException();
}
Expand All @@ -173,7 +173,7 @@ public void clear() {
* @return ImmutableValueMap
*/
public static @NotNull ImmutableValueMap of() {
return new ImmutableValueMap(ValueMap.EMPTY);
return new ImmutableValueMap(EMPTY);
}

/**
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Helper methods for resource path handling.
* @deprecated Use <code>io.wcm.wcm.commons.util.Path</code> instead.
*/
@Deprecated
@Deprecated(since = "1.2.0")
public final class ResourcePath {

private ResourcePath() {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/wcm/sling/commons/resource/ResourceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/";

/**
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -149,7 +149,7 @@ public static boolean equals(@NotNull String resourceType, @NotNull String anoth
* @return <code>true</code> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RequestParamTest {
private MockSlingHttpServletRequest request;

@BeforeEach
void setUp() throws Exception {
void setUp() {
request = context.request();
paramMap = getParamMap();
request.setParameterMap(paramMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RequestPathTest {
private RequestPathInfo requestPathInfo;

@BeforeEach
void setUp() throws Exception {
void setUp() {
when(request.getRequestPathInfo()).thenReturn(requestPathInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -97,7 +97,7 @@ public void doFilter(ServletRequest req2, ServletResponse resp2) {
}

@Test
void testWithExeption() throws Exception {
void testWithExeption() throws IOException {
assertNull(underTest.getThreadRequest());

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ void testMapPut() {

@Test
void testMapPutAll() {
Map<String, Object> input = Map.of(
"prop4", 25,
"prop5", 33);
assertThrows(UnsupportedOperationException.class, () -> {
underTest.putAll(Map.of(
"prop4", 25,
"prop5", 33));
underTest.putAll(input);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/wcm/sling/commons/util/EscapeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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''"));
Expand Down

0 comments on commit e0aa445

Please sign in to comment.