mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-10 02:26:18 +00:00
Merge pull request #4687 from daniel-beck/fix-ExtensionComponent-compareTo
[JENKINS-62056] Fix ExtensionComponent#compareTo
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user