You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by Ross Gardler <rg...@apache.org> on 2005/08/01 19:59:26 UTC

Handling errors and logging in Java (was Re: [jira] Closed: (FOR-590) Enhance the Forrest Seed Project wizard with site configuration options)

Anil Ramnanan wrote:
> Ross Gardler wrote:
> 

..

>>
>> it doesn't work. I get the extra page but the wizard does 
>> not complete when I click finish.
>>

...

> Does the wizard create the project but just does not close when you 
> click on finish or does it not do anything at all ?

The wizard behaves as I would expect, with the new config page being 
presented. When I click on the Finish button the progress dialog 
appears, does its stuff then disappears. The wizard dialog remains on 
screen, I have to press the cancel button to get rid of it.

The project is created, but no configs are setup as per the wizard 
selections.

I've done some debugging and find that there is an error being caused by 
the following code, from NewProjectWizard.performFinsih():


try {
   getContainer().run(false, true, op);
} catch (InvocationTargetException e) {
   return false; // TODO: should open error dialog and log
} catch (InterruptedException e) {
   return false; // canceled
}

The line getContainer.run(false, true, op); causes an 
InvocationTargetException if there are no plugins selected in the plugin 
page.

This can of error trapping is *very* bad practice. What the above code 
does is trap an error and allow the application to proceed as if nothing 
happened. There is not even a log of the error being generated to allow 
us to find out what happened.

At the very least the above code (and all code like it) should be:

try {
   getContainer().run(false, true, op);
} catch (InvocationTargetException e) {
   logger.error("Failed to correctly setup the project", e);
   return false; // FIXME: report this error to the user
} catch (InterruptedException e) {
   logger.debug("Project setup appears to have been cancelled", e);
   return false; // canceled
}

(I've added this to SVN)

Even this is not really because of the FIXME. However, it is a big 
improvement in that the FIXME will attract attention to the issue and we 
will now have a log entry for the problem which will mean we don't have 
to use the debugger to work out what is going on (a very inneficient 
process). Except...

The log4j system is not being correctly initialised (see warnings in the 
Console when the plugin is run). Therefore there is nowhere for the log 
messages to go :-(

I've added the necessary config code for log4j, now we have logging 
output to:

- forrestEclipse.log (in the workspace root)
- and port 4445 (I recomend installing the Ganymede plugin to make use 
of this, I find it the best way to read logs)

The config file for log4j is in conf/log4j.xml

---

Now using this new logging output you can see that the problem is:

Caused by: java.lang.StringIndexOutOfBoundsException: String index out 
of range: -1
	at java.lang.String.substring(Unknown Source)
	at 
org.apache.forrest.eclipse.wizards.ActivatePluginsPage.getSelectedPlugins(ActivatePluginsPage.java:245)

I'll leave it to you to solve this problem - I'm going out for a meal.

Ross