This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 34835

Summary: InplaceEditor.add*Listener could throw TooManyListeners exception
Product: platform Reporter: Jaroslav Tulach <jtulach>
Component: ExplorerAssignee: _ tboudreau <tboudreau>
Severity: blocker    
Priority: P2    
Version: 3.x   
Hardware: PC   
OS: Linux   
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on:    
Bug Blocks: 29447    

Description Jaroslav Tulach 2003-07-09 16:23:49 UTC
Is it possible that more than one listener will be
attached to a InplaceEditor? I guess it is not, as
it is guaranteed that only one InplaceEditor is
open at a time. If this is true, I suggest to
change the signature of addActionListener to throw
TooManyListeners exception. Then instead of
writing a complicated support for adding listeners
the implementors could choose to have just one field:

private ActionListener l;
public void addActionListener (l) {
  if (this.l != null) throw new TooManyListenersEx();
  this.l = l;

which is simpler and easier.
Comment 1 _ tboudreau 2003-07-14 08:39:29 UTC
No it can't, that's a checked exception.
Comment 2 Jaroslav Tulach 2003-07-14 09:18:43 UTC
Yes, it is checked exception, but I am not sure why that would clasify
this issue as invalid.

So once more. Please consider simplifying the life of InplaceEditor
writers by declaring

void InplaceEditor.addActionListener (ActionListener l) throws

which properly expresses your desire to attach just one listener to
each InplaceEditor and simplifies the life of writers in both cases:

1. if they inherit after JPanel (that does not have addActionListener
method), they can simply write the code as described above with one
field variable.

2. if they inherit from JTextField (has the addActionListener method
and does not throw the exception) they do not need to do anything and
it will still continue to work.

Comment 3 _ tboudreau 2003-07-15 17:08:28 UTC
Closing - not a terribly compelling argument, IMO.  Compound
components here are really the exception, not the rule, so 90%
of the time it's fine.

Also, there is no guarantee that a component, or worse (and more
likely) a look and feel will not try to add its own action listener
to the component, causing the exception to be thrown - people may
see the throws argument and think they need to police it.

There are equally effective ways to police listeners, such as
clearing the listener list when clear() is called on the 

Simpler and safer to leave it as is.
Comment 4 Marian Mirilovic 2003-07-28 17:00:11 UTC