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 201637 - The file cannot be safely opened with encoding UTF-8. Do you want to continue opening it?
Summary: The file cannot be safely opened with encoding UTF-8. Do you want to continue...
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Text (show other bugs)
Version: 7.0.1
Hardware: All All
: P3 normal with 2 votes (vote)
Assignee: dgaitan1
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-05 14:13 UTC by everflux
Modified: 2015-12-06 03:36 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Bugsito (1.94 KB, application/octet-stream)
2012-03-29 14:24 UTC, dgaitan1
Details
UTF-8 (28.97 KB, application/octet-stream)
2015-12-06 03:36 UTC, thangngocit
Details

Note You need to log in before you can comment on or make changes to this bug.
Description everflux 2011-09-05 14:13:17 UTC
Opened a PHP file with wrongly encoded umlauts. Alert box asks if I want to open it anyway, works as expected.
The red "exception occured" icon appears in the lower right corner, though. It can not be clicked, the exception can not be reported form within Netbeans.

This seems to be related to issues 196945.

Product Version = NetBeans IDE 7.0.1 (Build 201107282000)
Operating System = Linux version 2.6.38-11-generic running on amd64 (Ubuntu 11.04)
Java; VM; Vendor = 1.7.0
Runtime = Java HotSpot(TM) 64-Bit Server VM 21.0-b17

INFO [org.openide.text.CloneableEditorSupport]: Outer callstack
org.openide.text.DataEditorSupport$1: The file cannot be safely opened with encoding UTF-8. Do you want to continue opening it?
        at org.openide.text.DataEditorSupport.createAndThrowIncorrectCharsetUQE(DataEditorSupport.java:455)
        at org.openide.text.DataEditorSupport.loadFromStreamToKit(DataEditorSupport.java:446)
        at org.openide.text.CloneableEditorSupport.loadDocument(CloneableEditorSupport.java:2156)
        at org.openide.text.CloneableEditorSupport.access$2800(CloneableEditorSupport.java:133)
        at org.openide.text.CloneableEditorSupport$Listener.run(CloneableEditorSupport.java:2986)
Caused: org.openide.text.CloneableEditorSupport$DelegateIOExc: The file cannot be safely opened with encoding UTF-8. Do you want to continue opening it?
        at org.openide.text.CloneableEditorSupport$Listener.run(CloneableEditorSupport.java:2989)
        at org.openide.text.CloneableEditorSupport$3.doRun(CloneableEditorSupport.java:710)
        at org.openide.text.CloneableEditorSupport$3.run(CloneableEditorSupport.java:677)
        at org.netbeans.editor.GuardedDocument.runAtomic(GuardedDocument.java:314)
        at org.openide.text.NbDocument.runAtomic(NbDocument.java:422)
       at org.openide.text.CloneableEditorSupport$3.doRun(CloneableEditorSupport.java:687)
        at org.openide.text.CloneableEditorSupport$3.run(CloneableEditorSupport.java:677)
Caused: java.lang.Exception
[catch] at org.openide.text.CloneableEditorSupport.openDocumentImpl(CloneableEditorSupport.java:898)
        at org.openide.text.CloneableEditorSupport.openDocumentImpl(CloneableEditorSupport.java:880)
        at org.openide.text.CloneableEditorSupport.openDocumentCheckIOE(CloneableEditorSupport.java:860)
        at org.openide.text.CloneableEditorSupport.openDocument(CloneableEditorSupport.java:842)
        at org.openide.text.DataEditorSupport.openDocument(DataEditorSupport.java:538)
        at org.netbeans.modules.versioning.diff.DiffSidebar.getText(DiffSidebar.java:1013)
        at org.netbeans.modules.versioning.diff.DiffSidebar.getText(DiffSidebar.java:920)
        at org.netbeans.modules.versioning.diff.DiffSidebar.access$1200(DiffSidebar.java:103)
        at org.netbeans.modules.versioning.diff.DiffSidebar$RefreshDiffTask.fetchOriginalContent(DiffSidebar.java:878)
        at org.netbeans.modules.versioning.diff.DiffSidebar$RefreshDiffTask.computeDiff(DiffSidebar.java:849)
        at org.netbeans.modules.versioning.diff.DiffSidebar$RefreshDiffTask.run(DiffSidebar.java:834)
        at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1424)
        at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1968)
Comment 1 Miloslav Metelka 2011-09-22 11:48:09 UTC
I guess we need an additional handling for UserQuestionException mechanism.
Multiple UQEs can be thrown during opening of a single file e.g. first one for file being >1MB and another one for the case when file cannot be opened in UTF-8.
Some codes (such as DiffSideBar) call uqe.confirmed() automatically supposing it's the >1MB case but it might be the encoding case as well so such code is wrong. However currently I'm not aware of any way of how to determine type of UQE.
So we possibly need an enum (or a string id) to accompany each UQE giving type of the UQE.
Also we should revisit all the UQE client codes and possibly use loops (instead of just a single try-catch):

Document doc = null;
do {
    try {
        doc = edCookie.openDocument();
    } catch (UserQuestionException ex) {
        String type = ex.getType(); // new method
        if ("bigFile".equals(type)) {
            ex.confirmed();
        } else {
            NotifyDescriptor nd = new NotifyDescriptor.Confirmation(
                    e.getLocalizedMessage(), NotifyDescriptor.YES_NO_OPTION
                );
            nd.setOptions(new Object[] { NotifyDescriptor.YES_OPTION, NotifyDescriptor.NO_OPTION });
            Object res = DialogDisplayer.getDefault().notify(nd);
            if (NotifyDescriptor.OK_OPTION.equals(res)) {
                try {
                    e.confirmed();
                } catch (IOException ex1) {
                    Exceptions.printStackTrace(ex1);
                }
            }
        }
} while (doc == null);

Yardo, what do you think?
Comment 2 Miloslav Metelka 2011-09-22 11:53:56 UTC
Or the loop would be in a method like

StyledDocument NbDocument.openDocument(EditorCookie ec, boolean allowBigFiles, boolean ignoreBadEncoding) throws IOException

The method would not throw UQE. In case the method would return null the user refused opening in the messagebox.
Comment 3 psc1952 2011-12-04 03:25:21 UTC
I am getting this message on an existing Java file that contains the copyright symbol. Does not happen in Eclipse.
Comment 4 dgaitan1 2012-03-29 14:24:00 UTC
Created attachment 117477 [details]
Bugsito
Comment 5 Miloslav Metelka 2013-08-28 12:40:33 UTC
Tested the attached source file and the problem no longer happens in a recent dev build.
Comment 6 thangngocit 2015-12-06 03:36:07 UTC
Created attachment 157683 [details]
UTF-8