]> source.dussan.org Git - pf4j.git/commitdiff
sort files using last modified as long, preventing downcasting errors (#376)
authorThatGamerBlue <thatgamerblue@gmail.com>
Mon, 25 May 2020 16:32:40 +0000 (17:32 +0100)
committerGitHub <noreply@github.com>
Mon, 25 May 2020 16:32:40 +0000 (19:32 +0300)
pf4j/src/main/java/org/pf4j/BasePluginRepository.java
pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java

index 8c856f808d5d21a8ec0748c521eaf61b708e26c2..ea5ad3be4f28e489ea6476957db4cc8f1594434d 100644 (file)
@@ -48,7 +48,7 @@ public class BasePluginRepository implements PluginRepository {
         this.filter = filter;
 
         // last modified file is first
-        this.comparator = (o1, o2) -> (int) (o2.lastModified() - o1.lastModified());
+        this.comparator = Comparator.comparingLong(File::lastModified);
     }
 
     public void setFilter(FileFilter filter) {
index bcf153512e1727d3a60196c3a6a1f556ba02d1b0..e841189604482fe17f95cec0ea718f2d325999f1 100644 (file)
@@ -18,6 +18,7 @@ package org.pf4j;
 import com.google.common.collect.ImmutableList;
 import com.google.common.io.ByteStreams;
 import com.google.testing.compile.Compilation;
+import java.util.Comparator;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -238,7 +239,7 @@ public class AbstractExtensionFinderTest {
 
         public Map<String, Class<?>> loadClasses(List<JavaFileObject> classes) throws IOException {
             // Sort generated ".class" by lastModified field
-            classes.sort((c1, c2) -> (int) (c1.getLastModified() - c2.getLastModified()));
+            classes.sort(Comparator.comparingLong(JavaFileObject::getLastModified));
 
             // Load classes
             Map<String, Class<?>> loadedClasses = new HashMap<>(classes.size());