Skip to content

Commit

Permalink
Elminate PMD warnings / Prevent finalize attacks (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert authored Jan 15, 2024
1 parent 56a792b commit 7575b83
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/main/java/io/wcm/handler/media/spi/MediaFormatProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Set;

import org.osgi.annotation.versioning.ConsumerType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.wcm.handler.media.format.MediaFormat;
import io.wcm.sling.commons.caservice.ContextAwareService;
Expand All @@ -39,6 +41,8 @@ public abstract class MediaFormatProvider implements ContextAwareService {

private final Set<MediaFormat> mediaFormats;

private static final Logger log = LoggerFactory.getLogger(MediaFormatProvider.class);

/**
* @param mediaFormats Set of media formats for parameter provider
*/
Expand Down Expand Up @@ -76,9 +80,19 @@ private static Set<MediaFormat> getMediaFormatsFromPublicFields(Class<?> type) {
}
}
catch (IllegalArgumentException | IllegalAccessException ex) {
throw new RuntimeException("Unable to access fields of " + type.getName(), ex);
log.warn("Unable to access fields of {}", type.getName(), ex);
}
return Collections.unmodifiableSet(params);
}

/**
* @deprecated Prevent finalize attack (PMD CT_CONSTRUCTOR_THROW / SEI CERT Rule OBJ-11)
*/
@Override
@SuppressWarnings({ "PMD.EmptyFinalizer", "checkstyle:SuperFinalize", "checkstyle:NoFinalizerCheck", "java:S1113" })
@Deprecated(since = "2.0.0")
protected final void finalize() {
// do nothing
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
/**
* Generates URI templates for asset renditions - with or without Dynamic Media.
*/
class DamUriTemplate implements UriTemplate {
final class DamUriTemplate implements UriTemplate {

private final UriTemplateType type;
private final String uriTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,14 @@ else if (type == InputStream.class) {
return super.adaptTo(type);
}

/**
* @deprecated Prevent finalize attack (PMD CT_CONSTRUCTOR_THROW / SEI CERT Rule OBJ-11)
*/
@Override
@SuppressWarnings({ "PMD.EmptyFinalizer", "checkstyle:SuperFinalize", "checkstyle:NoFinalizerCheck", "java:S1113" })
@Deprecated(since = "2.0.0")
protected final void finalize() {
// do nothing
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
/**
* {@link Rendition} implementation for inline media objects stored in a node in a content page.
*/
class InlineRendition extends SlingAdaptable implements Rendition {
final class InlineRendition extends SlingAdaptable implements Rendition {

private final Adaptable adaptable;
private final Resource resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import io.wcm.handler.url.UrlHandler;
import io.wcm.sling.commons.adapter.AdaptTo;

class InlineUriTemplate implements UriTemplate {
final class InlineUriTemplate implements UriTemplate {

private final String uriTemplate;
private final UriTemplateType type;
Expand Down

0 comments on commit 7575b83

Please sign in to comment.