So in Else if part , I am getting a Sonarqube bug "Change this condition so that it does not always evaluate to ‘true’ ; eome subsequent code is never executed. Can someone help or guide me on this?
You’ve provided three paths, but you’re basing the path choice on a boolean test. Boolean tests only have two outcomes: true and false. There is no third value. So you’re never going to get to the else. That means you can streamline your code to:
if(val)
{
// stuff
// return newurl
}
else if (!val)
{
// slightly different stuff
// return newurl
}
But that’s not all. Again, you’re doing a boolean test and boolean tests only have two outcomes. Your if tests for (val). If that condition is true, control flow moves into that block. If you don’t move into that block (and exit the method with your return statement) then you automatically know that !val is true. There’s no reason to re-test it.