play-authenticate icon indicating copy to clipboard operation
play-authenticate copied to clipboard

List of Exception Management Anti-Patterns and Code Smells

Open ashishsureka opened this issue 11 years ago • 0 comments
trafficstars

Code smells are defined as symptom s in the program source code which are usually not bugs or technically incorrect but indicates a possible deeper problem. Anti-patterns are counterparts of design patterns and are defined as mistakes during software development that produces negative consequences and is ineffective or counter-productive. During program execution, error events can occur that disrupts the normal flow of the program. Programming languages provide exception handling mechanism to developers for handling errors and exception events.

I mined the source-code for automatically detecting 10 exception handling anti-patterns (https://today.java.net/article/2006/04/04/exception-handling-antipatterns). In this issue report, I list the exception handling anti-patterns and code-smells that I found in the source code. My experimental results demonstrate presence of various exception handling anti-patterns and throw light on their intensity. I believe my tool for automatic detection of anti-patterns in source code and the attached results can be useful to programmers by helping them correct mistakes and write effective code.

1 Mining Source Code for Automatically Discovering Exception Management Anti-Patterns and Code Smell

2 FILE NAME : play-authenticate-master\code\app\com\feth\play\module\pa\providers\openid\OpenIdAuthProvider.java

3 CATCH CLAUSE : catch (final Throwable t) { if (t instanceof OpenIDError) { if (!hasOpenID) { throw new NoOpenIdAuthException("OpenID endpoint is required"); } else { if (((OpenIDError)t).message() != null) { throw new AuthException(((OpenIDError)t).message()); } else { throw new AuthException("Bad response from OpenID provider"); } } } else { throw new AuthException(t.getMessage()); } }

4 ANTI-PATTERN WEPG : Wrapping the exception and passing getMessage() destroys the stack trace of original exception


5 FILE NAME : play-authenticate-master\code\app\com\feth\play\module\pa\providers\openid\OpenIdAuthProvider.java

6 CATCH CLAUSE : catch (final Throwable t) { if (t instanceof java.net.ConnectException) { throw new OpenIdConnectException(t.getMessage()); } else { throw new AuthException(t.getMessage()); } }

7 ANTI-PATTERN WEPG : Wrapping the exception and passing getMessage() destroys the stack trace of original exception


8 FILE NAME : play-authenticate-master\code\app\com\feth\play\module\pa\user\AuthUser.java

9 CATCH CLAUSE : catch (final java.lang.IllegalArgumentException iae) { try { return LocaleUtils.toLocale(locale.replace('-','_')); } catch ( final java.lang.IllegalArgumentException iae2) { return null; } }

10 ANTI-PATTERN RNHR : just returns null instead of handling or re-throwing the exception, swallows the exception, losing the information forever


11 FILE NAME : play-authenticate-master\code\app\com\feth\play\module\pa\user\AuthUser.java

12 CATCH CLAUSE : catch (final java.lang.IllegalArgumentException iae2) { return null; }

13 ANTI-PATTERN RNHR : just returns null instead of handling or re-throwing the exception, swallows the exception, losing the information forever


14 EXPERIMENTAL RESULTS

15 NUMBER OF JAVA FILES IN THE APPLICATION : 104 16 NUMBER OF CATCH CLAUSES IN THE APPLICATION :19 17 NUMBER OF METHOD DECLARATIONS IN THE APPLICATION :671

18 NUMBER OF PSTE ANTIPATTERN : 0 19 NUMBER OF LGTE ANTIPATTERN : 0 20 NUMBER OF CTGE ANTIPATTERN : 0 21 NUMBER OF RNHR ANTIPATTERN : 0 22 NUMBER OF PSRN ANTIPATTERN : 0 23 NUMBER OF MLLM ANTIPATTERN : 0 24 NUMBER OF LGRN ANTIPATTERN : 2 25 NUMBER OF THGE ANTIPATTERN : 0 26 NUMBER OF WEPG ANTIPATTERN : 2 27 NUMBER OF RRGC ANTIPATTERN : 0

ashishsureka avatar Jun 30 '14 05:06 ashishsureka