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 128850 - CloaneableEditorSupport.openDocument must not throw UserQuestionException
Summary: CloaneableEditorSupport.openDocument must not throw UserQuestionException
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Text (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Denis Anisimov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-29 16:24 UTC by Vladimir Voskresensky
Modified: 2008-12-22 11:58 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Voskresensky 2008-02-29 16:24:42 UTC
openDocument is programmatic way for opening document without creating editor window => there must not be UI dialog with
question/notification about big size of underlying document in case of standard:
       EditorCookie  cookie = (EditorCookie)dataObject.getCookie(EditorCookie.class);
       StyledDocument doc = cookie.openDocument(); 

When tried to get document using above approach with big size I've got exception.
org.openide.text.DataEditorSupport$Env$1ME: The file sql_yacc.cc seems to be too large (1 Mb) to safely open.
Opening the file could cause OutOfMemoryError, which would make the IDE unusable. Do you really want to open it?
       at org.openide.text.DataEditorSupport$Env.inputStream(DataEditorSupport.java:717)
       at org.openide.text.CloneableEditorSupport.loadDocument(CloneableEditorSupport.java:1869)
       at org.openide.text.CloneableEditorSupport.access$2200(CloneableEditorSupport.java:120)
       at org.openide.text.CloneableEditorSupport$Listener.run(CloneableEditorSupport.java:2624)
       at org.openide.text.CloneableEditorSupport$1.doRun(CloneableEditorSupport.java:594)
       at org.openide.text.CloneableEditorSupport$1.run(CloneableEditorSupport.java:565)
       at org.netbeans.editor.GuardedDocument.runAtomic(GuardedDocument.java:251)
       at org.openide.text.NbDocument.runAtomic(NbDocument.java:384)
       at org.openide.text.CloneableEditorSupport$1.doRun(CloneableEditorSupport.java:575)
       at org.openide.text.CloneableEditorSupport$1.run(CloneableEditorSupport.java:565)
       at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:561)
       at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:986)
Comment 1 Denis Anisimov 2008-03-20 10:32:33 UTC
The exception that you get is not waning about opening big file in Editor.
It is about just reading file in memory. "Open" file here means reading in memory.

Such mechanism prevents allocation a huge amount of memory. And it doesn't
concern to any UI.
So this exception is normal way to warn client ( user or developer that uses this API )
about such situation.

You can catch this exception ( I believe this is exactly what you need to do )
for avoiding dialog . In "try/catch" block you can use method "confirmed" 
http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/UserQuestionException.html#confirmed()
and then call openDocument() once again.
In this case you will not get this exception one more time.

If you don't catch this exception then it will be shown in dialog.
Comment 2 Vladimir Voskresensky 2008-03-20 11:13:54 UTC
I did exactly with try/catch/confirm
If it is expected behavior, let's close bug after updating the correspondent JavaDoc for methods which could throw this
exception (to help other people).

Thanks,
Vladimir.
Comment 3 Denis Anisimov 2008-03-20 11:59:43 UTC
Agreed.
Comment 4 Denis Anisimov 2008-03-20 12:19:48 UTC
Javadoc comments are added to EditorCookie.openDocument and ClonableEditorSupport.openDocument() methods.
changeset:   74244:f26672d69b54
Comment 5 Karthikeyan Rajeswaran 2008-07-15 18:49:25 UTC
See also: issue 138281