报告对 Throwable.initCause() 的调用,其中异常构造函数还包含 Throwable cause 参数。

在本例中,可以移除 initCause() 调用,并将其参数添加到对异常构造函数的调用中。

示例:


  try {
      process();
  }
  catch (RuntimeException ex) {
    RuntimeException wrapper = new RuntimeException("Error while processing");
    wrapper.initCause(ex); // 不必要地调用 'Throwable.initCause()'
    throw wrapper;
  }

通过快速修复可将 cause 参数传递给构造函数。 在应用快速修复后:


  try {
      process();
  }
  catch (RuntimeException ex) {
    RuntimeException wrapper = new RuntimeException("Error while processing", ex);
    throw wrapper;
  }
  
2016.1 的新功能