Solved

Attempt to mutate in notification exception

Posted on 2010-11-10
7
1,163 Views
Last Modified: 2012-05-10
I'm getting an Attempt to mutate in notification exception. I have a class DataStore which holds data with a listener that takes action when data in it has changed. When it sets the data from the DataStore to a GUI component, the exception occurs. The data does make it to the component. This is a Swing thread issue of some sort, I guess.

How should I address this?

JTextField myTextField;
...
public void propertyChange(PropertyChangeEvent event) {
		
	InvisibleChangedComponent invisibleChangedComponent = InvisibleChangedComponent.getInstance();
	final Actions action = invisibleChangedComponent.getAction();

	if (action == Actions.CHANGED) {

	        final DataStore dataStore = DataStore.getInstance();
		String newString = dataStore.getMyString();
		try {
			myTextField.setText(newString);
		}
		catch (Exception e) {
			// Attempt to mutate in notification
		}
}

Open in new window

0
Comment
Question by:allelopath
  • 4
  • 3
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 34106883
looks like the event is getting triggered by a change in the text field
This would be better handled with a DocumentListener
0
 
LVL 1

Author Comment

by:allelopath
ID: 34107035
I see the problem, not apparent from the code I posted.
As stated, I have it listening to DataStore so that when DataStore changes, it is reflected in the test field. Also, however, I have a DocumentListener that listens for changes to the text field:

final Document myDocument = myTesxField.getDocument();
myDocument.addDocumentListener(documentListener);
myDocument.putProperty(NAME_KEY,MY_TEXTFIELD);

When changes are made to the textfield (by the user typing), these get pushed to the DataStore.
So it is cyclical and on the 2nd time around, it throws the exception.

So the question, how is it best to handle this situation, where I have a DataStore and a text field, and when either is updated, I want the data to go to the other?

0
 
LVL 92

Expert Comment

by:objects
ID: 34107064
might be a job for a custom Document (that listens to the data store)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:allelopath
ID: 34107168
ok, this textfield is one component of 5 on a JPanel (2 comboboxes and 2 more textfields), and they all behave the same way with respect to DataStore <-> component. Would I have 1 custom Document for each (ie 5 custom documents) or 1 custom Document for all? The component data can be changed individually.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 34107297
a custom document for each text filed
0
 
LVL 1

Author Comment

by:allelopath
ID: 34113070
So conceptually, I will have:
A Document and DocumentListener. When the data changes, either in the text field,or in the datasource, the change occurs to data held in the document. Then the text field and the data store are listening to the Document, and when it changes, the change it pushed to both.
Correct?
0
 
LVL 92

Expert Comment

by:objects
ID: 34116958
sounds about right
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now