提交 e8ed394a 编写于 作者: O Oleg Nenashev

FindBugs: Wrap BC_IMPOSSIBLE_DOWNCAST in ToolDescriptor for empty array creation fallback

上级 1b99938f
......@@ -24,6 +24,7 @@
package hudson.tools;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.Descriptor;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
......@@ -71,10 +72,19 @@ public abstract class ToolDescriptor<T extends ToolInstallation> extends Descrip
Class t = Types.erasure(pt.getActualTypeArguments()[0]);
return (T[])Array.newInstance(t,0);
} else {
// can't infer the type. fallacbk
return (T[])new Object[0];
// can't infer the type. Fallback
return emptyArray_unsafeCast();
}
}
//TODO: Get rid of it?
//It's unsafe according to http://stackoverflow.com/questions/2927391/whats-the-reason-i-cant-create-generic-array-types-in-java
@SuppressWarnings("unchecked")
@SuppressFBWarnings(value = "BC_IMPOSSIBLE_DOWNCAST",
justification = "Such casting is generally unsafe, but we use it as a last resort.")
private T[] emptyArray_unsafeCast() {
return (T[])new Object[0];
}
/**
* Overwrites {@link ToolInstallation}s.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册