diff --git a/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/util/file/classloader/ClassLoaderUtils.java b/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/util/file/classloader/ClassLoaderUtils.java index 61ef0173e0..487c9d39b6 100644 --- a/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/util/file/classloader/ClassLoaderUtils.java +++ b/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/util/file/classloader/ClassLoaderUtils.java @@ -155,13 +155,17 @@ public class ClassLoaderUtils { } private static long getLastModified(String url) { - File file = null; + long lastModified = 0; try { - file = new File(new URI(url)); + final URI uri = new URI(url); + if (uri.getScheme().equals("file")) { + final File file = new File(uri); + lastModified = file.lastModified(); + } } catch (URISyntaxException e) { LOGGER.error("Error getting last modified date for " + url); } - return file != null ? file.lastModified() : 0; + return lastModified; } protected static ClassLoader createModuleClassLoader(URL[] modules, ClassLoader parentClassLoader) { diff --git a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/file/classloader/TestClassLoaderUtils.java b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/file/classloader/TestClassLoaderUtils.java index e2bec02eba..2ba4796bdc 100644 --- a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/file/classloader/TestClassLoaderUtils.java +++ b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/file/classloader/TestClassLoaderUtils.java @@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test; import java.io.FilenameFilter; import java.net.MalformedURLException; -import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Paths; import java.util.HashSet; @@ -114,7 +113,7 @@ public class TestClassLoaderUtils { } @Test - public void testGenerateAdditionalUrlsFingerprint() throws MalformedURLException, URISyntaxException { + public void testGenerateAdditionalUrlsFingerprintForFileUrl() throws MalformedURLException { final Set urls = new HashSet<>(); URL testUrl = Paths.get("src/test/resources/TestClassLoaderUtils/TestSuccess.jar").toUri().toURL(); urls.add(testUrl); @@ -122,6 +121,15 @@ public class TestClassLoaderUtils { assertNotNull(testFingerprint); } + @Test + public void testGenerateAdditionalUrlsFingerprintForHttpUrl() throws MalformedURLException { + final Set urls = new HashSet<>(); + URL testUrl = new URL("http://myhost/TestSuccess.jar"); + urls.add(testUrl); + String testFingerprint = ClassLoaderUtils.generateAdditionalUrlsFingerprint(urls, null); + assertNotNull(testFingerprint); + } + protected FilenameFilter getJarFilenameFilter(){ return (dir, name) -> name != null && name.endsWith(".jar"); }