Jean-Francois Leveque

Nettoyage sur les conseils de SonarQube

Vulnerability : Define and throw a dedicated exception instead of using a generic one.

Using such generic exceptions as Error, RuntimeException, Throwable, and Exception prevents calling methods from handling true, system-generated exceptions differently than application-generated errors.

Noncompliant Code Example

public void foo(String bar) throws Throwable {  // Noncompliant
  throw new RuntimeException("My Message");     // Noncompliant
}

Compliant Solution

public void foo(String bar) {
  throw new MyOwnRuntimeException("My Message");
}
......@@ -27,12 +27,12 @@ public class BookServiceOldTest {
private BookServiceOld bookServiceOld;
@Before
public void setUp() throws Exception {
public void setUp() {
bookServiceOld = new BookServiceOld(entityManager);
}
@Test
public void testAddBook() throws Exception {
public void testAddBook() {
Book book = new Book();
bookServiceOld.addBook(book);
Mockito.verify(entityManager).persist(book);
......@@ -40,7 +40,7 @@ public class BookServiceOldTest {
@Test
public void testAllBooks() throws Exception {
public void testAllBooks() {
Book book = new Book();
book.setBookId(0);
......