I've been tasked to make JUnit tests for an application that someone else made along time, I can't modify the original code, so when I encounter something like this:
public String clean(String url) throws Exception {
if (url.indexOf(invalidURL) {
throw new Exception("Severe XSSS detected");
}
}
I write my test with: throws Exception, and SonarQube complains about generic Exception and if I write a custom exception like: public class MyException extends Exception
, still SonarQube doesn't like it, any help will be much appreciated!
The existing answers provide useful information, but if the constraints you specify in your original post are correct, those answers don't really help.
If you can't actually modify the code under test, there is no way you can fix the SonarQube issue.