Merge pull request #4687 from daniel-beck/fix-ExtensionComponent-compareTo

[JENKINS-62056] Fix ExtensionComponent#compareTo
This commit is contained in:
Raihaan Shouhell authored and GitHub committed 2020-04-29 19:00:04 +08:00
commit 6b5930817b
2 files changed
+36 -5

No files matched your search

@@ -91,14 +91,40 @@ public class ExtensionComponent<T> implements Comparable<ExtensionComponent<T>>
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);
}
}