Code Review Principles Process and Tools
Code Review Principles Process and Tools
Review
Principles,
Processes
and Tools
Aditya Pratap Bhuyan
April 25
2014
Code
Review
Details for
Java
Table of Contents
1.
2.
d.
e.
f.
g.
h.
i.
e.
f.
g.
g.
h.
i.
j.
k.
l.
10 | P a g e | A D I T Y A P R A T A P B H U Y A N
Example:
catch (NoSuchMethodException e) {
return null;
}
This one is insidious. Not only does it return null instead of handling or rethrowing the exception, it totally swallows the exception, losing the
information forever.
8. Throw from Within Finally
Example:
try {
blah();
} finally {
cleanUp();
}This is fine, as long as cleanUp() can never throw an exception. In the
above example, if blah() throws an exception, and then in the finally
block, cleanUp() throws an exception, that second exception will be
thrown and the first exception will be lost forever. If the code that you call
in a finally block can possibly throw an exception, make sure that you
either handle it, or log it. Never let it bubble out of the finally block.
9. Unsupported Operation Returning Null
Example:
10.
Ignoring InterruptedException
Example:
while (true) {
try {
Thread.sleep(100000);
} catch (InterruptedException e) {}
doSomethingCool();
}
11 | P a g e | A D I T Y A P R A T A P B H U Y A N
while (true) {
try {
Thread.sleep(100000);
} catch (InterruptedException e) {
break;
}
doSomethingCool();
}
11.
Relying on
getCause()
catch (MyException e) {
if (e.getCause() instanceof FooException) {}
The problem with relying on the result of getCause is that it
makes your code fragile. It may work fine today, but what happens
when the code that you're calling into, or the code that it relies on,
changes its underlying implementation, and ends up wrapping the
ultimate cause inside of another exception? Now calling getCause
may return you a wrapping exception, and what you really want is
the result of getCause().getCause(). Instead, you should
unwrap the causes until you find the ultimate cause of the
problem. Apache's commons-lang project provides
ExceptionUtils.getRootCause() to do this easily.
14.
12 | P a g e | A D I T Y A P R A T A P B H U Y A N
15.
16.
17.
18.
19.
20.
21.
13 | P a g e | A D I T Y A P R A T A P B H U Y A N
14 | P a g e | A D I T Y A P R A T A P B H U Y A N
15 | P a g e | A D I T Y A P R A T A P B H U Y A N
3.
4.
5.
16 | P a g e | A D I T Y A P R A T A P B H U Y A N
17 | P a g e | A D I T Y A P R A T A P B H U Y A N
18 | P a g e | A D I T Y A P R A T A P B H U Y A N
c)
ActionScript
a)
C
a)
b)
c)
d)
e)
f)
g)
C++
a)
Java
a)
b)
c)
d)
e)
19 | P a g e | A D I T Y A P R A T A P B H U Y A N
f)
JavaScript
a)
Objective-C
a)
d)
e)
f)
g)
h)
i)
20 | P a g e | A D I T Y A P R A T A P B H U Y A N
j)
k)
l)
m)
n)
o)
p)
q)
r)
s)
t)
u)
v)
w)
21 | P a g e | A D I T Y A P R A T A P B H U Y A N
b)
c)
d)
e)
f)
Ada
Ada-ASSURED A tool that offers coding style checks,
standards enforcement and pretty printing features.
b) AdaCore CodePeer Automated code review and bug finder
for Ada programs that uses control-flow, data-flow, and other
advanced static analysis techniques.
c) LDRA Testbed A software analysis and testing tool suite for
Ada83/95.
a)
22 | P a g e | A D I T Y A P R A T A P B H U Y A N
d)
C / C++
a)
b)
c)
d)
e)
f)
g)
h)
i)
j)
Java
b)
c)
a)
Java.
analysis.
d)
23 | P a g e | A D I T Y A P R A T A P B H U Y A N
6. References
The following references were taken while preparing the
document.
1. http://www.en.wikipedia.org
2.
https://developer.mozilla.org/en/Code_Review_FAQ
https://developer.mozilla.org/en/Code_Review_FAQ
24 | P a g e | A D I T Y A P R A T A P B H U Y A N