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.
The attached source code attempts to obtain the javax.swing.text.Document from the SourceCookie.Editor returned from org.openide.src.MethodElement. The document is only successfully returned if the source file is open in the editor. If the editor does not contain the file, a null value is returned. The java.swing.text.Element interface does not provide for a null return value. The problematic behavior is that the code works if the code is open in the editor. The behavior should perform the appropriate initialization if the source is not currently open. To reproduce the problem, Execute the attached file as internal executor. You will notice that the return value is null if the attached file is not opened in the editor and non-null if the file is opened (as expected).
Created attachment 5835 [details] Source file to recreate the problem
There are actually two options: either autload the document blocking on the load finish, or return null instead of j.s.t.Element, when the document was not loaded yet.
The implementation tries to open the underlying document. Note that in a really exceptional case (someone has erased the Element's document between it was obtained and sourceToText was called), it may throw IllegalStateException. But that's IMHO better than returning null since SourceCookie.Editor's javadoc does not mention such possibility. Fixed in trunk: /cvs/java/src/org/netbeans/modules/java/JavaParserGlue.java,v <-- JavaParserGlue.java new revision: 1.36; previous revision: 1.35
VERIFIED
Resolved for 3.4.x or earlier, no new info since then -> closing.