Refactoring with Jackpot in Glassfish



Jackpot is a Java source code reengineering tool from NetBeans.  Intrigued by all the buzz around it in JavaOne, I decided to try Jackpot beta on Glassfish.  By following the short instruction and was able to get it up and running in my NetBeans 5.0 in a few minutes.  It comes with 14 built-in rules, grouped into 2 rule sets: default and Effective Java:

Jackpot default rules in NetBeans

I first tried to let Jackpot query several modules in Glassfish at once, including appserv-commons, appserv-core, appserv-webtier, appserv-http-engines, etc, which turned out to be too ambitious in my machine.  I had several OutOfMemoryError.  Then I tried only appserv-core module with only one query -- unnecessary cast.  The query completed in less than 1 minute, and found 65 matching nodes.  I randomly checked a few and these casts are really unnecessary casts.  Double-click on one item will open up two side-by-side diff windows, showing the suggested fix.  If I click Do Refactoring button, all these 65 unnecessary casts will be fixed automatically.  IMO, they are pretty low-risk fixes and will not only clean up code, but also boost the server performance.

If I'm assigned the task of fixing them, I wouldn't do as well as Jackpot does.  I will need much more time than one-click, and I'm sure I will mess something up along the way.  Jackpot strikes me as a dangerous tool, cause it can put us out of job.

Fixing some types of anti-patterns needs human intervention, for instance, bad-finally-blocks anti-pattern.  There are no suggested fix for these types of query results.  Jackpot found 15 such issues in appserv-core module, some of them are actually false alarm, for instance, it interprets the return statement inside anonymous inner-class as a bad return statement that will be executed inside the finally block:

} finally {
    java.security.AccessController.doPrivileged(
        new java.security.PrivilegedAction() {
             public java.lang.Object run() {
                // do something
                return null;
            }
        });
    }


There are still some rough edges, given that it's still at beta.  I'd like to see a better query result console, adding buttons like sort, filter, select all, deselect all on all matching items.  Since there may be hundreds of matching nodes for one query, as I've seen in Glassfish, I hate to select/deselect them one by one, or customize rules.

PS: I entered a bug for the above issue in NetBeans | Jackpot [Issue 77082] New - return statement in anonymous innerclass reported as bad finally block
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Cheng Fang

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today