未验证 提交 6b593081 编写于 作者: R Raihaan Shouhell 提交者: GitHub

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

[JENKINS-62056] Fix ExtensionComponent#compareTo
......@@ -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);
}
}
......@@ -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
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册