此規則標記使用 JspException.getRootCause() 方法。
該 JspException.getRootCause() 方法在 JSP 2.1 中被廢棄,並已在 JSP 4.0 中移除。 從 JSP 4.0 開始,開發人員應該使用標準的 Throwable.getCause() 方法來取代,以更一致的方式在 Java API 中提供相同的功能。
以下範例顯示會被標記的無效用法:
import jakarta.servlet.jsp.JspException;
public class RemoveJspGetRootCauseMethod {
public void testGetRootCauseUsage(JspException e) {
Throwable rootCause = e.getRootCause(); // This will be flagged
}
}
以下範例顯示有效的用法:
import jakarta.servlet.jsp.JspException;
public class ValidGetCauseMethod {
public void test(JspException e) {
Throwable cause = e.getCause(); // This will not flag
}
}
如需相關資訊,請參閱下列資源: