Thank you, Java annotation!

This was an interesting bug hellip; I was working on a Web application, where Adobe Flex client was sending an instance of an ActionScript WrapperObject to the Java server, which was supposed to invoke some JBDC code to run an SQL Insert statement saving the data from the Java version of WrapperObject in the database. I wrote all the pieces of Flex, Java, and SQL and started Tomcat in Eclipse IDE.

The Web browser displayed my window, I filled out the form populating the ActionScript WrapperObject and pressed the button Save. Nothing happened. No errors and no data inserted in the database.

Well, need to start debugging hellip;Let “s see what could have gotten wrong:

1. I didn “t properly populate the ActionScript WrapperObject

2. I didn “t properly configure the Java class/method so the front end didn “t even call it.

3. I didn “t code the database portion properly.

But why there is no errors? Starting the Flex part in the debug mode quickly revealed that the WrapperObject was properly populated and the asynchronous request to the Java server has been sent.

Great. The next question is, “Have I called the proper endpoint (the destination) on the Java side and if the correct method has been really invoked? rdquo; Started an HTTP/AMF sniffer, which confirmed that I was calling a method on the endpoint mapped to the class Customer shown below. On the Java side, the class hierarchy looked as follows:

class _Customer {


public boolean saveData( WrapperObject wrapper){

// an empty method



class Customer extends _Customer{

public boolean saveData (WrapperObject wrapper) {

// the code saving data in DBMS was here



Without leaving Eclipse IDE, restarted Tomcat in the debug mode and put a breakpoint in the caller of Java “s saveData. Interesting hellip; The debugger brought me inside the empty method of _Customer.saveData. Do you see any spelling errors in the method signatures? Me neither. This was about time to use a Java annotation @Override, which I was always underestimating. Changed the class Customer to look like this:

class Customer extends _Customer{


public boolean saveData (WrapperObject wrapper) {

// the code saving data in DBMS was here



Sure enough, the Java compiler immediately told me that the method saveData has to override the one from the superclass. But I did override it, didn “t I?

The problem was that my project has two different versions of the class WrapperObject located in different packages! The superclass was using the WrapperObject from one package, but the subclass from another! This little annotation caught what my eyes didn ‘t see. Fixed the import statement in the subclass to properly override the method saveData, re-ran the program and got hellip; an SQL error stating that I have an extra comma somewhere in my Insert statement. But this one is a piece of cake! I was so happy.

Thank you Java @Override ndash; you made my day!From now on I ‘ll be using this example in all my Java classes.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s