Friday, June 17

Import or not important?

I am now positively convinced any Java source code example should explicitly reference imports at package level.

Consider the JSF code snippet below extracted from here.

package com.mycompany.expense.ui;

import javax.faces.event.ActionListener;

public class ReportHandler implements ActionListener {
  ...
  public void processAction(ActionEvent e) throws AbortProcessingException {
    ...
  }
}

Even a seasoned Java developer (ahem) could accidentally import java.awt.event.ActionEvent (by force of habit, maybe?) instead of javax.faces.event.ActionEvent. Having done that, it's 'good luck, sucker!' trying to find the silly mistake from the cryptic JSF exception stacktrace.

And why is there an explicit import of javax.faces.event.ActionListener but not one of javax.faces.event.ActionEvent?

[Update]:
Cryptic (or absent)
JSF errors revisited.

No comments: