Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 344654

Summary: [EditorMgmt] Editors should be able to treat large files specially (e.g. deny opening huge files)
Product: [Eclipse Project] Platform Reporter: Prakash Rangaraj <prakash>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: bokowski, daniel_megert, eclipse, elias, emoffatt, jamesblackburn+eclipse, markus.kell.r, mober.at+eclipse, ob1.eclipse, prakash, pwebster, remy.suen, sptaszkiewicz
Version: 3.7Flags: prakash: review?
bokowski: review+
remy.suen: review+
Target Milestone: 3.7 RC2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 117746, 344031, 344652, 344653    
Bug Blocks:    
Attachments:
Description Flags
Patch v01
none
The "forward-ported" patch from 3.4.2
none
The "forward-ported" patch from 3.4.2 updated none

Description Prakash Rangaraj CLA 2011-05-04 00:34:19 EDT
+++ This bug was initially created as a clone of Bug #344653 +++

+++ This bug was initially created as a clone of Bug #344652 +++

+++ This bug was initially created as a clone of Bug #344031 +++

+++ This bug was initially created as a clone of Bug #117746 +++

Loading large files in an editor needs a lot of memory (up to 5 times the file size, see Bugzilla 75086), so the Workbench can run into an OutOfMemory error or freeze for some time while an editor is busy loading a file.

Since users do not see in the Resource navigator how large a file is, it can easily happen that one tries to open a very large file by accident. We have auto-generated log files which range from 1 to 400 MB in size. The smaller ones we want to open in Eclipse Workbench, the larger ones we open in an external editor. Trying to opening a 400MB file in the Workbench by accident leads to an OutOfMemoryError and destabilizes the workbench or even makes it unusable for some time.

It should be possible to define a maximum file size (in the Preferences, in plugin.xml or by computing available heap size) up to which an editor editor can open a file directly. If the user tries to open a file that exceeds the given size, the user should be shown a dialog which allows to
  * Open the file in spite of the warning
  * Open the file in an alternative (external) editor instead
  * Cancel the edit request

Perhaps the best solution would be to extend the Editor API such that an editor is given the file path to be opened BEFORE it is actually opened. Thereby, each editor implementor could have policies for allowing or denying the open request.
Policies for denying could be based on file size, virtual vs. real file system [See Bugzilla 106176], file content...) In case an edit request is denied, the Platform could show a dialog like

  "Editor FooBar has denied opening 'yourFile.xxx' with the following message:
   (Custom Message e.g. File is 50MB large)
   Do you want to
     * Open the file in (Dropdown of registered editors for xxx files) instead
     * Open the file in spite of the warning
     * Cancel
  "
Comment 1 Prakash Rangaraj CLA 2011-05-04 04:52:02 EDT
Created attachment 194679 [details]
Patch v01

Patch v01 for HEAD
Comment 2 Oleg Besedin CLA 2011-05-18 11:42:35 EDT
At this point changes in 3.7 should be minimal, I suggest we go with the same patch as was done in 3.4.2+ (bug 344031 ). Note also reversal of the changes from Label to Text (bug 344031 comment 18 ) which seems to be missing from the proposed patch.
Comment 3 Oleg Besedin CLA 2011-05-18 13:54:55 EDT
Created attachment 196027 [details]
The "forward-ported" patch from 3.4.2
Comment 4 Remy Suen CLA 2011-05-18 14:44:11 EDT
(In reply to comment #3)
> Created attachment 196027 [details]
> The "forward-ported" patch from 3.4.2

The patch looks okay to me and does the job with the least amount of code required.

One thing I noticed was that it doesn't "work" if you change the value at runtime but I suppose we're just expecting people to use plugin_customization.ini to alter the values on startup and not for them to be randomly changing the value while the application is up. If one were to change this value, they would need to spawn new workbench windows (so that a new EditorManager would get instantiated) for the new value to kick in.

I think it would be worth adding a @noreference tag to the "upgraded" STORE_ID_INTERNAL_EXTERNAL static field. While the text notes that it probably won't be referenced (as clients are not supposed to extend the class), it doesn't hurt to add the tag in my opinion though I admit to being unfamiliar with our API tagging policies.

Lastly, I'm wondering if these changes will come up as API errors during the build? I know that SWT has to update the API exclusion list for bug 279461 but that is a case of making a public class @noextend while we are lifting the 'final' requirement and replacing it with a @noextend. Are similar rules going to kick in for our API tooling tags here?
Comment 5 Oleg Besedin CLA 2011-05-18 15:00:24 EDT
Created attachment 196035 [details]
The "forward-ported" patch from 3.4.2 updated

(In reply to comment #4)
> One thing I noticed was that it doesn't "work" if you change the value at
> runtime but I suppose we're just expecting people to use
> plugin_customization.ini to alter the values on startup and not for them to be
> randomly changing the value while the application is up. 

That's correct. At present we do not expect the file size limit to change at runtime.

> I think it would be worth adding a @noreference tag to the "upgraded"
> STORE_ID_INTERNAL_EXTERNAL static field. 

Good point, I updated the patch.

> Lastly, I'm wondering if these changes will come up as API errors during the
> build? 

I checked with Olivier and he thinks that it should be fine for API tools. Of course there is always a chance that it won't :-).
Comment 6 Remy Suen CLA 2011-05-18 15:03:12 EDT
Comment on attachment 196035 [details]
The "forward-ported" patch from 3.4.2 updated

Marking the attachment as a patch.
Comment 7 Boris Bokowski CLA 2011-05-18 15:07:06 EDT
+1 for 3.7.RC2
Comment 8 Oleg Besedin CLA 2011-05-18 15:35:55 EDT
Updated patch applied to CVS Head. Thank you!
Comment 9 Oleg Besedin CLA 2011-05-19 11:16:45 EDT
Verified in I20110519-0800.
Comment 10 Dani Megert CLA 2011-10-06 06:00:34 EDT
Oleg, it looks like this didn't make it into 4.x.
Comment 11 Oleg Besedin CLA 2011-10-06 16:03:46 EDT
There is no EditorManager class in 4.2...
Comment 12 Dani Megert CLA 2013-05-31 10:11:21 EDT

*** This bug has been marked as a duplicate of bug 117746 ***
Comment 13 Dani Megert CLA 2013-05-31 10:15:08 EDT
Let's keep this as bug for the fix being in 3.7.x and 3.8.x.