From 194d4bfb01dcee15d6427d84372a75be35ceeee4 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 11 Feb 2020 23:06:54 +0100 Subject: [PATCH] Fix libraries comparator logic Previously it could lead to contract violations for example consider this: A = Library{ Name:"A", Types: ["Sensors"] } B = Library{ Name:"B", Types: null } C = Library{ Name:"C", Types: ["Arduino"] } it results in: A { @@ -47,9 +49,11 @@ public int compare(ContributedLibraryReleases o1, ContributedLibraryReleases o2) ContributedLibrary lib1 = o1.getLatest(); ContributedLibrary lib2 = o2.getLatest(); - if (lib1.getTypes() == null || lib2.getTypes() == null) { - return compareName(lib1, lib2); - } + List types1 = lib1.getTypes(); + List types2 = lib2.getTypes(); + if (types1 == null) types1 = Arrays.asList(); + if (types2 == null) types2 = Arrays.asList(); + if (lib1.getTypes().contains(firstType) && lib2.getTypes().contains(firstType)) { return compareName(lib1, lib2); }