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 198676 - javax.swing.text.BadLocationException: BaseDocument.write()
Summary: javax.swing.text.BadLocationException: BaseDocument.write()
Status: VERIFIED FIXED
Alias: None
Product: xml
Classification: Unclassified
Component: XML Multiview (show other bugs)
Version: 7.0
Hardware: All All
: P2 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords: RANDOM
Depends on: 134726
Blocks:
  Show dependency tree
 
Reported: 2011-05-17 13:56 UTC by Maksim Khramov
Modified: 2011-11-24 13:59 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 158059


Attachments
stacktrace (1.21 KB, text/plain)
2011-05-17 13:56 UTC, Maksim Khramov
Details
stacktrace (1.21 KB, text/plain)
2011-06-03 14:17 UTC, Maksim Khramov
Details
stacktrace (4.57 KB, text/plain)
2011-10-06 09:23 UTC, Jiri Skrivanek
Details
stacktrace (9.03 KB, text/plain)
2011-10-24 11:30 UTC, Jiri Skrivanek
Details
stacktrace (7.69 KB, text/plain)
2011-11-07 12:42 UTC, Maksim Khramov
Details
Possible patch (827 bytes, patch)
2011-11-11 10:35 UTC, Svata Dedic
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maksim Khramov 2011-05-17 13:56:04 UTC
Build: NetBeans IDE 7.0 (Build 201104080000)
VM: Java HotSpot(TM) 64-Bit Server VM, 20.1-b02, Java(TM) Platform, Standard Edition for Business, 1.6.0_26-ea-b02
OS: Windows 7

User Comments:
GUEST: Generating hibernate.cfg.xml.




Stacktrace: 
javax.swing.text.BadLocationException: BaseDocument.write()
   at org.netbeans.editor.BaseDocument.write(BaseDocument.java:1548)
   at org.netbeans.editor.BaseKit.write(BaseKit.java:722)
   at org.netbeans.modules.xml.multiview.XmlMultiViewEditorSupport.saveFromKitToStream(XmlMultiViewEditorSupport.java:239)
   at org.openide.text.CloneableEditorSupport.getInputStream(CloneableEditorSupport.java:1625)
   at org.netbeans.modules.xml.multiview.XmlMultiViewEditorSupport.getInputStream(XmlMultiViewEditorSupport.java:195)
   at org.netbeans.modules.hibernate.loaders.cfg.HibernateCfgDataObject.parseDocument(HibernateCfgDataObject.java:135)
Comment 1 Maksim Khramov 2011-05-17 13:56:10 UTC
Created attachment 108355 [details]
stacktrace
Comment 2 Maksim Khramov 2011-06-03 14:17:53 UTC
Created attachment 108702 [details]
stacktrace
Comment 3 Milutin Kristofic 2011-09-19 14:13:11 UTC
It looks like a problem is from XmlMultiViewEditorSupport. Please evaluate.
Comment 4 Jiri Skrivanek 2011-10-06 09:23:47 UTC
Created attachment 111585 [details]
stacktrace

To reproduce:

- create web application with GlassFish serve and Hibernate framework
- open new file wizard
- choose "Hibernate|Hibernate Configuration Wizard"
- continue in wizard and when you click the Finish button it throws this exception
Comment 5 Jiri Skrivanek 2011-10-24 11:30:22 UTC
Created attachment 112366 [details]
stacktrace

To reproduce:

- create web project with Hibernate framework and GlassFish server
- open new file wizard
- choose "Hibernate|Hibernate Configuration Wizard" and click Next
- finish the wizard with default values
- create the same file again and exception is thrown
Comment 6 Maksim Khramov 2011-11-07 12:42:41 UTC
Created attachment 112919 [details]
stacktrace
Comment 7 Exceptions Reporter 2011-11-07 12:42:53 UTC
This bug already has 20 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=158059
Comment 8 Petr Jiricka 2011-11-07 13:44:32 UTC
Could this be a problem in the Hibernate support? Cc'ing Sergey.
Comment 9 Sergey Petrov 2011-11-07 14:51:52 UTC
yes, may be hibernate support issue with attempt to override already created configuration, wizard should block this case.
Comment 10 Sergey Petrov 2011-11-07 16:39:51 UTC
looks like it;s not the reason as I can't create new config with the same name. something else need to be broken.
Comment 11 Sergey Petrov 2011-11-07 17:36:58 UTC
can't reproduce it yet
Comment 12 Petr Jiricka 2011-11-08 09:16:58 UTC
Whoever can reproduce, can you please attach steps to reproduce? Changing to incomplete for now - please reopen after attaching the steps. Thanks.
Comment 13 Sergey Petrov 2011-11-08 09:57:57 UTC
I'm not sure it's really hibernate issue but have no proof, there is another issue with report from jpa side first (issue 134726) but also have comments on getting this problem in another case (RCP on netbeans). So either all cases prepare environment in wrong way or it's an issue in XML multiview support.
Comment 14 Jiri Skrivanek 2011-11-10 08:42:21 UTC
I am still able to reproduce it:

- create web project with Hibernate framework and GlassFish server
- open new file wizard
- choose "Hibernate|Hibernate Configuration Wizard" and click Next
- finish the wizard with default values
- repeat creation of file and exception appears (on 3-rd attempt in this case)

http://statistics.netbeans.org/exceptions/exception.do?id=541075
Comment 15 Sergey Petrov 2011-11-10 17:55:12 UTC
I was able to reproduce, in my case it was 5th attempt, 4th and 5th cfg files seems ok regardless exception.
Comment 16 Sergey Petrov 2011-11-10 20:46:48 UTC
XMLKit::write(new OutputStreamWriter(stream, dObj.getEncodingHelper().getEncoding()), doc, 0, doc.getLength()); is called but as it's not atomic action doc.length is changed during processing and is smaller when BaseDocument::write is invoked inside the method.
Comment 17 Sergey Petrov 2011-11-11 09:00:41 UTC
as it's XmlMultiViewEditorSupport use to get doc.getLength() in saveFromKitToStream and use it in call to XMLKit(BaseKit) it's likely should be the place to lock this document or handle possible changes somehow else,  please evaluate.
Comment 18 Sergey Petrov 2011-11-11 09:46:01 UTC
just decide it may be good to catch this exception on hibernate/persistence support side anyway, but will keep 134726 to track as something missed in xml multiview, as 134726 have a report from RCP application.
Comment 19 Sergey Petrov 2011-11-11 10:17:00 UTC
http://hg.netbeans.org/web-main/rev/65bf55e7cbe5 fix
Comment 20 Svata Dedic 2011-11-11 10:35:50 UTC
Created attachment 113113 [details]
Possible patch

I am not able to reproduce the defect that reliably. However when it happened to me, I have discovered that the event is fired during *first* load of the document - it does not make much sense. The attached patch should eliminate the 1st event, and it seems that the wsdl hierarchy refreshes properly after that.
Comment 21 Sergey Petrov 2011-11-11 14:46:37 UTC
Seems good and even better as fix root cause, may be have sense to reopen the issue and patch for hibernate/persistence area can be reverted and this one applied or anyway this one may be valuable even without reverting.
Comment 22 Quality Engineering 2011-11-12 16:30:26 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/65bf55e7cbe5
User: Sergey B. Petrov <sj-nb@netbeans.org>
Log: #198676, #134726 add "catch" to possible parsing issue
Comment 23 Jiri Skrivanek 2011-11-14 14:16:07 UTC
I can confirm that with the patch by sdedic I am not able to reproduce it (before applying the patch I reverted #65bf55e7cbe5).