diff --git a/core/src/main/java/hudson/ExtensionComponent.java b/core/src/main/java/hudson/ExtensionComponent.java index d274e11204de3847f381d56c7672b1344bfd8199..e4e35ebe1d450d8309e0eb4312d22d2dca4f0009 100644 --- a/core/src/main/java/hudson/ExtensionComponent.java +++ b/core/src/main/java/hudson/ExtensionComponent.java @@ -91,14 +91,40 @@ public class ExtensionComponent implements Comparable> if (Double.compare(a, b) > 0) return -1; if (Double.compare(a, b) < 0) return 1; - // make the order bit more deterministic among extensions of the same ordinal - if (this.instance instanceof Descriptor && that.instance instanceof Descriptor) { + boolean thisIsDescriptor = false; + String thisLabel = this.instance.getClass().getName(); + if (this.instance instanceof Descriptor) { try { - return Util.fixNull(((Descriptor)this.instance).getDisplayName()).compareTo(Util.fixNull(((Descriptor)that.instance).getDisplayName())); + thisLabel = Util.fixNull(((Descriptor) this.instance).getDisplayName()); + thisIsDescriptor = true; } catch (RuntimeException | LinkageError x) { - LOG.log(Level.WARNING, null, x); + LOG.log(Level.WARNING, "Failure during Descriptor#getDisplayName for " + this.instance.getClass().getName(), x); } } - return this.instance.getClass().getName().compareTo(that.instance.getClass().getName()); + + boolean thatIsDescriptor = false; + String thatLabel = that.instance.getClass().getName(); + if (that.instance instanceof Descriptor) { + try { + thatLabel = Util.fixNull(((Descriptor) that.instance).getDisplayName()); + thatIsDescriptor = true; + } catch (RuntimeException | LinkageError x) { + LOG.log(Level.WARNING, "Failure during Descriptor#getDisplayName for " + that.instance.getClass().getName(), x); + } + } + + if (thisIsDescriptor) { + if (thatIsDescriptor) { + return thisLabel.compareTo(thatLabel); + } else { + return 1; + } + } else { + if (thatIsDescriptor) { + return -1; + } + } + + return thisLabel.compareTo(thatLabel); } } diff --git a/test/src/test/java/hudson/ExtensionListTest.java b/test/src/test/java/hudson/ExtensionListTest.java index 3c3a6dddb5c2cfd20c5dd60b8f207749591353a2..de2ee11d53ffda71b96450b11fb86f7f5549ab2f 100644 --- a/test/src/test/java/hudson/ExtensionListTest.java +++ b/test/src/test/java/hudson/ExtensionListTest.java @@ -217,4 +217,9 @@ public class ExtensionListTest { assertEquals(0, list.size()); } + @Issue("JENKINS-62056") + @Test + public void checkSort() { + ExtensionList.lookup(Object.class).get(0); // exceptions are a problem + } }