We are creating an application on the Netbeans platform, and one part of it is an editor for the specific language that we use.
We have the following class to highlight syntax errors:
class SyntaxErrorsHighlightingTask extends org.netbeans.modules.parsing.spi.ParserResultTask { public SyntaxErrorsHighlightingTask () { } @Override public void run (org.netbeans.modules.parsing.spi.Parser.Result result, org.netbeans.modules.parsing.spi.SchedulerEvent event) { try { final javax.swing.text.Document document = result.getSnapshot().getSource ().getDocument(false); final List<ErrorDescription> errors = new ArrayList<ErrorDescription> ();
}
The violation code that throws the exception is as follows:
org.netbeans.spi.editor.hints.HintsController.setErrors (document, "testsequence", errors);
Based on the search results has been changed to the following:
SwingUtilities.invokeLater(new Runnable() { @Override public void run() { System.err.println("is EDT? " + SwingUtilities.isEventDispatchThread()); HintsController.setErrors (document, "testsequence", errors); } });
The following is information about what happens when a syntax error is entered in the editor:
is EDT? true SEVERE [org.openide.util.RequestProcessor]: Error in RequestProcessor org.netbeans.spi.editor.hints.HintsController$1 java.lang.IllegalStateException: Must be run in EQ at org.netbeans.editor.Annotations.addAnnotation(Annotations.java:195) at org.netbeans.modules.editor.NbEditorDocument.addAnnotation(NbEditorDocument.java:251) at org.openide.text.NbDocument.addAnnotation(NbDocument.java:504) at org.netbeans.modules.editor.hints.AnnotationHolder$NbDocumentAttacher.attachAnnotation(AnnotationHolder.java:235) at org.netbeans.modules.editor.hints.AnnotationHolder.attachAnnotation(AnnotationHolder.java:208) at org.netbeans.modules.editor.hints.AnnotationHolder.updateAnnotationOnLine(AnnotationHolder.java:674) at org.netbeans.modules.editor.hints.AnnotationHolder.setErrorDescriptionsImpl(AnnotationHolder.java:899) at org.netbeans.modules.editor.hints.AnnotationHolder.access$1300(AnnotationHolder.java:113) at org.netbeans.modules.editor.hints.AnnotationHolder$4.run(AnnotationHolder.java:812) at org.netbeans.editor.BaseDocument.render(BaseDocument.java:1409) at org.netbeans.modules.editor.hints.AnnotationHolder.setErrorDescriptions(AnnotationHolder.java:809) at org.netbeans.modules.editor.hints.HintsControllerImpl.setErrorsImpl(HintsControllerImpl.java:111) at org.netbeans.modules.editor.hints.HintsControllerImpl.setErrors(HintsControllerImpl.java:93) at org.netbeans.spi.editor.hints.HintsController$1.run(HintsController.java:79) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1424) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1968) Caused: org.openide.util.RequestProcessor$SlowItem: task failed due to at org.openide.util.RequestProcessor.post(RequestProcessor.java:425) at org.netbeans.spi.editor.hints.HintsController.setErrors(HintsController.java:77) at com.
What happens is a call to the HintsController in the EDT (ThreadDispatch Thread). However, Annotations.addAnnotation () starts in another thread - sometimes in the System Clipboard Synchronizer thread, sometimes in the Inactive Processor Request thread. Since it checks if it is running on EDT, it always throws an IllegalStateException.
I am not an expert in using the Netbeans platform, and I am pretty new to this particular application in the company, so I might be missing out on something really obvious. Google did not help much. Anyone have any tips?