strange exception warning

IDEA has been hinting me about an exception usage since 896 or so. I'm doing a catch (Exception e) so I can get any errors and rethrow them as specific exceptions. There's an screenshot attached showing my code and the warning from IDEA.

There's really anything wrong with my code or this is a bug and I should post a request?



Attachment(s):
idea-warning.png
0
11 comments

SQLException is Exception extending. EJBException is RuntimeException
extending.
Maybe IDEA is see that you can get only SQLException in try catch cause and
then it mean that IDEA see "e" can be only SQLException.

The RuntimeException you can do not cache, as you know. Maybe it logic have
similar warning?

And more clearly rewrite cache block as:
try {
...
} catch (RuntimeException e) {
// This block hooks all RuntimeEseptions
} catch (Exception e) {
// This block for all other
}

Thanks!
--
Alexey Efimov, Software Engineer
Sputnik Labs,
http://www.spklabs.com
"Marcus Brito" <pazu@animegaiden.com.br> wrote in message
news:23107068.1062420086579.JavaMail.itn@is.intellij.net...

IDEA has been hinting me about an exception usage since 896 or so. I'm

doing a catch (Exception e) so I can get any errors and rethrow them as
specific exceptions. There's an screenshot attached showing my code and the
warning from IDEA.
>

There's really anything wrong with my code or this is a bug and I should

post a request?



0

BTW, nice coloring :)
Could you please send it to TWiki? ;)

http://www.intellij.org/twiki/bin/view/Main/LookAndFeel
--
Alexey Efimov, Software Engineer
Sputnik Labs,
http://www.spklabs.com
"Marcus Brito" <pazu@animegaiden.com.br> wrote in message
news:23107068.1062420086579.JavaMail.itn@is.intellij.net...

IDEA has been hinting me about an exception usage since 896 or so. I'm

doing a catch (Exception e) so I can get any errors and rethrow them as
specific exceptions. There's an screenshot attached showing my code and the
warning from IDEA.
>

There's really anything wrong with my code or this is a bug and I should

post a request?


0

Can you show us your try? Since EJBException and SQLException are not in the same hierarchy try replacing with

try{

}
catch(SQLException sqle){

}
catch(EJBException( ejbe){

}
catch(Exception e){

}

Also note that sqleceptions are chained so you will need something like

while(sqle != null){
process(sqle);
sqle = sqle.getNextException();

}

0

Now, I know there are better ways to do that try{...} catch{...}, including the one suggested by you. However, my question was just about wether IDEA is right about this warning or not.

The code inside the try {..} block calls a variety of business methods that throws many different exceptions (NamingException, RemoteException, SQLException, EJBException and some project-specific exceptions). So, I don't think IDEA is right saying that my "instance of" operation is redundant.

Rewriting the code as you suggested makes IDEA happy. And oh, I'll post the coloring on the wiki. It's based on the "Active" jEdit color scheme.

0

I've investigated the thing and found out that it's just message wrong and
should be read like
condition e instanceof SqlException is always false
condition e instanceof EjbException is always false

meaning code in try block does not throw these declared exceptions. I'll
correct the message.

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Marcus Brito" <pazu@animegaiden.com.br> wrote in message
news:23107068.1062420086579.JavaMail.itn@is.intellij.net...

IDEA has been hinting me about an exception usage since 896 or so. I'm

doing a catch (Exception e) so I can get any errors and rethrow them as
specific exceptions. There's an screenshot attached showing my code and the
warning from IDEA.
>

There's really anything wrong with my code or this is a bug and I should

post a request?


0


"Maxim Shafirov (JetBrains)" <max@intellij.net> wrote in message
news:bivue7$o03$1@is.intellij.net...

I've investigated the thing and found out that it's just message wrong and
should be read like
condition e instanceof SqlException is always false
condition e instanceof EjbException is always false


Ok, the message is wrong, but it's false that the condition always false :)

SQLException is a checked exception and (unless there's an unseen catch
SQLException) it can be true in the example.


0

If theoretical is it posible to get some exception differents that SQLException then you are right - the logic of this inspection is wrong and also message is wrong.
But if inspection of your code will get result then only SQLException can be realy throw then, i guess, the logic of code inspection is good and message is right. But, sure, the "null" is never catched :) then message must be simple "instance of operation is redundant the e is always SQLException".

The simple test, that allow to have check this logic:


This code can throw both exceptions but IDEA still have warnigns "Conditions e instanceof .. is redundant and canreplaced with != null". The warnings for both:

And for


But if we change code to:

Or

Or even


We alway still have warnings about "Conditions e instanceof .. is redundant and canreplaced with != null" and always for both "if" statements.

I think, you are fully right, it wrong inspection logic and as result wrong message.

Thanks!

PS. Just for information, to see this warnings you must enable inspections in "IDE Settings->Errors->Local Code Analyst" switch to "As warnings".

0

Have you seen the try block for this sample? Otherwise why are you sure
inspection is wrong?

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Carlos Costa e Silva" <carlos@keysoft.pt> wrote in message
news:bivuva$sb2$1@is.intellij.net...
>

"Maxim Shafirov (JetBrains)" <max@intellij.net> wrote in message
news:bivue7$o03$1@is.intellij.net...

I've investigated the thing and found out that it's just message wrong

and

should be read like
condition e instanceof SqlException is always false
condition e instanceof EjbException is always false

>

Ok, the message is wrong, but it's false that the condition always false

:)
>

SQLException is a checked exception and (unless there's an unseen catch
SQLException) it can be true in the example.

>
>


0

I've stated it on a previous comment, Maxim. The try{} block is quite long and full of business method, so it makes no sense in post it here. However, I assure you that the try{} block throws, at least:

java.rmi.RemoteException
java.sql.SQLException
javax.ejb.CreateException
javax.naming.NamingException
com.telebahiacelular.movistore.exceptions.MoviSegurancaException

And that was easily discovered just commenting out the catch block and waiting for IDEA to show all the errors about uncatch exceptions.

That being said, I can send the code to you if you think it would be useful for your testing/analysis.

0

Have you seen the try block for this sample?
Otherwise why are you sure
inspection is wrong?


More complete test. In here I get the warning "Condition ex ... is redundant ...".

0

No need for that unless the things reappear in higher build. Fixed for now.
Thanks!

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Marcus Brito" <pazu@animegaiden.com.br> wrote in message
news:24846731.1062441313826.JavaMail.itn@is.intellij.net...

I've stated it on a previous comment, Maxim. The try{} block is quite long

and full of business method, so it makes no sense in post it here. However,
I assure you that the try{} block throws, at least:
>

java.rmi.RemoteException
java.sql.SQLException
javax.ejb.CreateException
javax.naming.NamingException
com.telebahiacelular.movistore.exceptions.MoviSegurancaException

>

And that was easily discovered just commenting out the catch block and

waiting for IDEA to show all the errors about uncatch exceptions.
>

That being said, I can send the code to you if you think it would be

useful for your testing/analysis.


0

Please sign in to leave a comment.