Archive for March, 2008

Findbugs

Saturday, March 29th, 2008

CMMI level 3 is huge challenge for us. Some time ago I was using findbugs just for fun, now it’s time to use it on all projects I’m involved in.

Findbugs is a project started in TheUniversity of Maryland as a result of research on static code analysis. There are three bug categories:

  • Correctness bug : this is probably an error.
  • Bad Practice: this is violation of good practice.
  • Dodgy: this is simple dodgy code.

There are over two hundred bugs with description, which I suggest you to read. You can also write your own bug detector and there is for example a project called fb-contrib which has some bug detectors.

The usage of this tool is very simple. We can use it from eclipse, as eclipse plugin, standalone or as a maven plugin.

You can also simple install eclipse plugin by adding findbugs eclipse update site. After eclipse restart you should see in menu findbugs submenu. You can run findbug analyzis.

running findbug process

You can also add automatically checking for project, and of course choosing detector suitable for you by entering in project properties and next to findbugs options.

Findbugs setup

After that in code view you have additional pointers which shows you the line with problem. You can view description of the violation, which can help you to choose if this is a problem or false warning.

bugs details

There are also bugs tree view, which groups similar bugs and leafs are source code position. My suggestion is to use findbug with your build tool. In my situation it is maven. There are two possibilities to use findbug with maven. First is simple and you can run it without any setup. You can simply write mvn findbugs:findbugs and after few seconds you have report in target directory.

>mvn findbugs:findbugs
[INFO] Scanning for projects…
[INFO] Searching repository for plugin with prefix: ‘findbugs’.
[INFO] org.apache.maven.plugins: checking for updates from artifactory
[INFO] org.codehaus.mojo: checking for updates from artifactory
[INFO] artifact org.codehaus.mojo:findbugs-maven-plugin: checking for updates from artifactory
[INFO] ————————————————————————
[INFO] Building Synergy Portal Platform
[INFO] task-segment: [findbugs:findbugs]
[INFO] ————————————————————————
[INFO] Preparing findbugs:findbugs
….
[INFO] [findbugs:findbugs]
[INFO] No effort provided, using default effort.
[INFO] Using FindBugs Version: 1.2.0
[INFO] No threshold provided, using default threshold.
[INFO] Debugging is Off
[INFO] No bug include filter.

The best option is to use findbugs as report, which is added to site projection. To do this you should simple add findbugs report to maven reports.

<project>
  [...]
  <reporting>
    [...]
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>findbugs-maven-plugin</artifactId>
      <configuration>
      [...]
      </configuration>
    </plugin>
    [...]
  </reporting>
  [...]
</project>

After that always you run mvn site and your findbugs report will be attached to project site.

Good Luck with Findbugs

Pedro

BTW: See here to see some sample with all known projects status

Java Generics and Collections

Friday, March 28th, 2008

I read this book twice, and I suggest every java developer two read it twice or more. Some time ago I passed SCJP before this exam I thought that I know Generics but I didn’t. So when I saw this book in Roche Library I knew I should read it.

The book has two parts, one of them is about Generics (was read by me more than twice), second part is about java collections.

First at all we must know that generics are implemented by erasure. So once code is compiled there is no more information about Generics. Second important thing to remember is that List<Integer> has no relation with List<Number>. This one helps us to understand everything else. So once again List<Integer> is not subclass of List<Number> nor List<Number> is subclass of List<Integer>. This types are different, repeat with me D I F F E R E N T.

Once again:

  • Erasure
  • No parent-child relation

Ok so you ask what if I want a List with Integer and Float types. The answer is magical “? extends E” called wildcard, which means that it is legal to have type E and any type that is a subtype of E. For exampe Collection class have method

public boolean addAll(Collection<? extends E> collection);

which allows add all class and sublcass of type E. The second magic literal is “? super T” which simply means that it represents any type that is supertype of T.

This construction compared to arrays behavior makes three different subtyping.

Phrase Subtype type condition
T[] covariant if T is subtype of S
List<T> invariant if T is identical as S
List<? extends T> covariant if T is subtype of S
List<? super T> contravariant if T is supertype of S

We can’t use wildcards in :

  • instance creation : List<? extends Integer> list = new List<? extends Integer>();
  • supertype declaration: MyClass extends List<? extends Integer>
  • generic method call: Collections.<? extends Integer>emptyList();

Important note is that List<? extends Integer> is a wildcard but List<List<? extends Integer>> is NOT.

One thing to mention is that parametrized type is reificated, so in runtime List<Number> and List<String> is simple raw List. Hence we can’t use instanceof with parametrized type. The only one generic type is <?> wildcard.

There are more advanced topics related to generics including tips how to migrate from no generic code to generic one.

Second part of the book is about java collections. There are full characterization of class hierarchy and the most important thing is that all implementation has comparison of performance. So everyone can choose suitable implementation for task.

Principles to remember:

Cast-iron guarantee: the implicit casts added by the compilation of generics never fail.

The Get and Put Principle: use an extends wildcard when you only get values out of a structure, use a super wildcard when you only put values into structure, and don’t use a wildcard when you do both get and put.

The Principle of Truth in Advertising: the reified type of an array must be a subtype of the erasure of its static type.

Summary
In my opinion all java programmers should have this book on his shelf and I assure you I will get my own.

Read more on Java Generics, there is a generic tutorial.

California – Part One

Wednesday, March 19th, 2008

Our trip began in Warsaw airport with great news that our flight was canceled. We must go to BA and they rebooked us to LOT flight. Next great news was in london, the security guard said us that it impossible to get to our flight to San Francisco. Our last chance was that our luggage should automatically send to SF, so security guard gets our documents and come back with our tickets, he told to us “run quickly to gate 10”. The last thing was that our luggage didn’t run so quickly as we did ;) . BA gave us 50$ for primary prerequisite. That was enough for us, so we rent a car and go to Golden Gate vista point.

Misfortunately we didn’t have camera because main was in luggage and the new one was uncharged. So we simple go for a Nappa valley, the country of wine on oil. Unfortunately we was exhaust so we stay in motel. Next day we eat in Tarantino like bar.
Next we arrived into Jack London cottage. He invented many interesting things, I simply could say that he was American Edison. He was writer, farmer , etc. The park near his cottage is nice to see, but you must look out poison oak and Rattlesnake

After that we went to Benziger winery which is famous for Biodynamic wine-growing. We taste great Pinot Noir, than Merlot, Cabernet Sauvignon and finally Syrath. Decision was not easy at all, so we asked for help. We bought six bottles, and the greatest of mine I keep in secret and will drink it with my wife on our marriage date. We ask about others winery and we get for free a map, and a suggestion about the road. Yeah Trinity Road was pleasure for our eyes but I as driver hadn’t good time, lots of curves with nice views after few glasses of wine.

Ok because I see it’s no easy to write all the story at once, this is the end of part one episode one ;) .

See you

Full map of part one, we are in 20-30% of the road ;) , If you like to go deeply into details, let me know

Time for sponsor – Roche Winery ;) and few photos

Our car and first moteltarantino.pngRoche WinerySnakes we love itJack London ParkBenziger wineryTrinity Road

SD West – last day

Friday, March 14th, 2008

The last day was little bit dull. I think because it was last day and mans was going to flights , and it was sad. First speech was “Aspect-Oriented Design and Programing in Ruby” by Dean Wampler. He creates and manages AOP ruby project called Aquarium. He shown a lot of code, and by examples of rails he shown how aspect oriented design may help even when language has enough power (meta programing). It was really interesting very advanced topic and I’m going to investigate it.

Next talk was hard to choose, in last minute as continuous working group member I decided to see “Automating Builds: Brining Quality and Testing Forward” by Zach Nies. He is co-author of very nice blog about agile methodology “theagileblog”. It was a quite good presentation.

And Ladies and Gentlemans the best of the best speech was a lunch keynote “Dances with Robots” by James McLurkin. What can I say, it was stunning presentation. Everyone after that presentation goes to Lego store to buy some Mind-Storms. James personality is so cute and pleasant. I can not describe this session even in 1 percent, so I suggest you go to James homepage and read it and if you had opportunity to see him life go there, you will be applaud. BTW the first question was “how can I start to do something like this?”.

I’m java developer so next two session was java path. First of them was “Memory Leaks in Java Applications: Different Tools for Different Types of Leaks” by Greg Sporar. With help of sample application Greg shown us different types of leaks and how to hunt them easy and quickly, good technical presentation.

The last one “Programing in Hadoop” by Owen O’Malley. He described as map-reduce algorithm, which is implemented in hadoop. He shown us some bad example when not properly used map-reduce can kill network or machines. The numbers Owen was talking about was impressive over 1000 nodes compute over 100TB data.

After that we went to see Golden Gate and by the way we go to Google campus, Roche in Paulo Alto. The roche division is next to XEROX and some others well known for IT guys companies. And of course we can’t finished in other way as going to Apple Computer Inc headquarter One Infinite Loop street in Cupertino.

See You
Pedro

SD WEST – day two

Wednesday, March 12th, 2008

First session was the workshop with Amr Elssamadisy. He is an author of great book “Patterns of Agile Practice Adoption”, which can be also downloaded FOR FREE from infoq site. Great workshop, great book, and he give me a copy of it with personal autograph.

Next I want to know something more about java nio, so I went to Ron Hitchens presentation “How to Build a Scalable, Multiplexed Java Server With NIO”. Ron is author of the “Java NIO” book. I thought that NIO is something I can learn easy, but Ron showed me how wrong I was. After this presentation, NIO is recognized as hard and scheduled to unknown time ;) . If you want to try this topic Ron put his presentation and code here.

Than was so called lunch and keynote from the Intel guy about parallelism. James Reinders told us about how important is to write programs to work in parallel. He described construction of new processors and about future intel plans.

After keynote I went to Allen Holub, He is a great speaker, talks softly and very funny. He showed us some tricks hackers can use to expose our system. He talks about XSS and XSRF. Nice talk with very real life example.

And the last talk this day was Neal Ford “Meta-Programming Ruby”. This talk was really advanced. Neal has many examples, and show deeply Ruby meta features. If you interested in Neal presentation see his home page.

I’m slowly back to normal life, a friend of mine choose Melatonin, I’m old fashioned so I’ve chosen Tyskie ;) .

about me

My name is Sebastian Pietrowski. I've finished Warsaw University as Master degree. I started my journey with Java 1.1 with Thread and JDBC programing in 1998 as I worked for merlin.pl. In 1999 I've passed Java Programer Certificate for Java 1.2, and was solution architect of merlin.pl infrastructure when we was moving from pl/sql to J2EE. It was great performance optimization with 10 times more req/sec than in requirements and 85 times faster as original solution.

Currently I work as Expert Software Development Java at F.Hoffmann-La Roche. The company was founded in 1896 and today, Roche employs over 80.000 people. After work I'm involved in activities related to Scala/Lift, Ruby/Rails/Merb, Python/Django. This is because I try to be pragmatic also I'm focused on application performance and tuning with success in my daily work.

My Yoda's motto: Do, or do not. There is no try.