Solved

Attempt to mutate in notification exception

Posted on 2010-11-10
7
1,179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

734 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