acs-aem-commons icon indicating copy to clipboard operation
acs-aem-commons copied to clipboard

A Possible NullPointerException Bug in Version 5.3.0

Open zhaoyangyingmu opened this issue 2 years ago • 0 comments

Required Information

  • [ ] AEM Version, including Service Packs, Cumulative Fix Packs, etc: N/A
  • [ ] ACS AEM Commons Version: 5.3.0
  • [ ] Reproducible on Latest? yes

Actual Behavior

In version 5.3.0, in method:

com.adobe.acs.commons.rewriter.impl.VersionedClientlibsTransformerFactory.calculateMd5(@Nonnull final HtmlLibrary htmlLibrary, boolean isMinified)

line number: 343 code:

@Nonnull private String calculateMd5(@Nonnull final HtmlLibrary htmlLibrary, boolean isMinified) throws IOException {
    // ...
    try (InputStream input = htmlLibrary.getInputStream(isMinified)) {// htmlLibrary could be null
        // ...
    }
}

htmlLibrary could be null due to invocation BadMd5VersionedClientLibsFilter.doFilter, in which uriInfo.htmlLibrary is passed.

UriInfo uriInfo = getUriInfo(uri, slingRequest);
// ...
md5FromCache = calculateMd5(uriInfo.htmlLibrary, htmlLibraryManager.isMinifyEnabled());
@Nonnull
UriInfo getUriInfo(@Nullable final String uri, @Nonnull SlingHttpServletRequest request) {
    if (uri != null) {
        Matcher matcher;
        // ...
        if (matcher.matches()) {
            // ...
            return new UriInfo(libraryPath + "." + extension, md5, libraryType, htmlLibrary);
        }
    }

    return new UriInfo("", "", null, null);// warning: the fourth parameter is null for htmlLibrary.
}

When matcher.matches() returns false, uriInfo.htmlLibrary will be null, which will induce an npe in your project.

zhaoyangyingmu avatar Jun 04 '22 02:06 zhaoyangyingmu